How can I get all this to not only output on the screen, but to save to a text file in CSV format?
$OUs = Get-ADObject -LDAPFilter "(objectCategory=organizationalUnit)" ` -SearchBase "OU=GA,OU=EAST,DC=corp,DC=chm,DC=com" | Select distinguishedName ForEach ($OU In $OUs) { $OU.distinguishedName Get-ADComputer -SearchBase $OU.distinguishedName -SearchScope OneLevel ` -Filter * | Select Name } I have tried
$OUs = Get-ADObject -LDAPFilter "(objectCategory=organizationalUnit)" ` -SearchBase "OU=GA,OU=EAST,DC=corp,DC=chartercom,DC=com" | Select distinguishedName ForEach ($OU In $OUs) { $OU.distinguishedName Get-ADComputer -SearchBase $OU.distinguishedName -SearchScope OneLevel ` -Filter * | Select Name } | | export-CSV c:\temp\outfile.csv –noType And many other formats, but I always get the error:
An empty pipe element is not allowed.