How do you pipe information into a Get-ADcomputer
command in PowerShell?
I'd like to import a list of computers and descriptions from a CSV file and use the CSV data to gather additional information for the computers listed in the CSV file. However, when I attempt to use information from the CSV file, the Get-Command
runs using the string ($_.description
) instead of the description info from CSV file (value of $_.description
).
My code:
$csv = Import-Csv C:\Temp\computers.csv -Header @("name","info","description")
foreach ($line in $csv) {
Get-AdComputer -LDAPFilter "(description = $_.description)" -Properties * -SearchScope Subtree -SearchBase "OU=computers,DC=example"
}