previously I tried to make a powershell script to compared asset tags from a text files with computer names in AD, that was successful. However, when an asset isn't found in AD it just skips through that line and moves on to the next. The asset that cannot be found is not exported into the CSV file.
Is there a way to get it to print in the CSV file the missing Asset, along with a message like "Asset not found" next to the asset tag? I tried using this line but all that does is add spaces in between the lines.
if ($_.samaccountname -notlike "*$line*") {"Asset does not exist in AD"}
Code:
Import-Module ActiveDirectory
[Array]$Collection = foreach($line in Get-Content H:\AssetNames.txt) {
Get-ADComputer -Filter * -Property Description | Where {$_.samaccountname -Like "*$line*"} | Select Name, Description
#if ($_.samaccountname -notlike "*$line*") {"Asset does not exist in AD"}
}
$Collection | Export-Csv C:\test.csv -NoTypeInformation