Link to home
Start Free TrialLog in
Avatar of Mike
MikeFlag for United States of America

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

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

Open in new window



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

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mike

ASKER

The Script works perfect thanks for the help......  :)