Forum question wanted to take a list of computer names in a csv
Using the Quest cmdlets it becomes
Import-Csv computers2.csv | foreach { $comp = Get-QADComputer -Name $($_.Name) if ($comp) {$location = $comp.DN} else {$location = "Does NOT exist in AD"} New-Object -TypeName Psobject -Property @{ Name = $_.Name Location = $location } } | Export-Csv complocs.csv -NoTypeInformation
Read the CSV and for each computer see if we can find it in AD. I’m searching whole AD and assuming less than 1000 machines. Alter the search properties if these don’t match your needs. Put the name and distinguished name (DN) in an object and write to CSV
Its just as easy with the Microsoft cmdlets
Import-Csv computers2.csv | foreach { $comp = Get-ADComputer -LDAPFilter "(name=$($_.Name))" if ($comp) {$location = $comp.DistinguishedName} else {$location = "Does NOT exist in AD"} New-Object -TypeName Psobject -Property @{ Name = $_.Name Location = $location } } | Export-Csv complocs2.csv -NoTypeInformation
Main difference is that we have to use an LDAP filter in Get-ADComputer. Also we pick up the DistinguishedName not DN property