Hey guys, would really appreciate some help here.
I’m building a powershell script to retrieve and delete adcomputers which haven’t logged in for a certain amount of time. However, there are some computer which I use once or twice a year which I do not want to remove. I have therefore created a white list.
My script is as follows:
get list of computers
$computerList = Get-ADComputer -Filter {LastLogonDate -lt $time} -Properties Name,LastLogonDate | select -Property Name,LastLogonDate
import white list
$importedWhiteList = Import-Clixml -Path “$filePath\whitelist.xml”
#check which computer are not in the white list and add them to another list
$filteredList = foreach($c in $computerList) {if($importedWhiteList -notcontains $c) {$c}
I then delete the old computers from the filtered list…
The issue is that even if $c is a computer which I know exists in the white list, it still comes out as false, as if the computer is not there.
If I pipe a computer from the $importedWhiteList | gm it is the same type object as if I pipe from get-adcomputer | gm and the same object as $c | gm
The white list was created by piping get-adcomputer -filter… | export-clixml , it was not created manually so I don’t think the list is the issue.
Help would be really appreciated. I’m new to powershell, so if you have a better practice way of solving my issue I would really appreciate that too.
Thanks.