Mike
asked on
Need to combine two scripts
Greeting Experts,
I need some help combining two different scripts into one, The first script is used to query DNS by using the IP address to get a hostname of the device. the 2nd is used to get different attributes from Active Directory based on the host name. I would like to combine the first script with the 2nd script together. I would like to scan DNS to get hostnames from the supplied IP address. Then get attributes request from Active Directory. Can somebody help me with this issue? I have added the two scripts below
Script 1
2nd Script
I need some help combining two different scripts into one, The first script is used to query DNS by using the IP address to get a hostname of the device. the 2nd is used to get different attributes from Active Directory based on the host name. I would like to combine the first script with the 2nd script together. I would like to scan DNS to get hostnames from the supplied IP address. Then get attributes request from Active Directory. Can somebody help me with this issue? I have added the two scripts below
Script 1
Get-Content C:\IP_Address.txt | % {
$ip = $_
Try {
$HostName = ([Net.Dns]::GetHostByAddress($ip)).HostName
"" | Select @{N="IP";E={$ip}},@{N="HostName";E={$HostName}}
}
Catch{
"" | Select @{N="IP";E={$ip}},@{N="HostName";E={"No HostNameFound"}}
}
} | Export-Csv C:\hostnames.csv -NoType
2nd Script
$Name = gc "C:\workstations.txt"
Get-ADComputer -Filter '*' -Properties Name,Description,DNShostname,Objectsid |
? { $Name -contains $_.Name } |
select Name,Description,Dnshostname,Objectsid |
Export-Csv 'C:\workstations.csv' -NoType
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER