The code below almost does what I need. I have a list of PC names and I need to get the PC name and the AD description. The catch is in the AD description I need to exclude any machine that has BHS in the description.
I've played around with the -notlike, -notcontains etc... and I've yet to get the right snytax.
$pc=Get-Content"c:\temp\List.txt"
$GoodDesc=''
$results= @()
$results=foreach ($machinein$pc) {
$computerName= (Get-ADComputer$machine-Properties name).name
$desc= (Get-ADComputer$machine-Properties Description).description
if ($desc-notlike'*BHS*') {$Gooddesc=$Desc}
[PSCustomObject]@{
PCName=$computerName
'Description'=$GoodDesc
}
}
$results | Export-Csv"c:\temp\listoutput.csv"-Appe