Exclude results in a list (returned from Get-QADComputer)
-
03-06-2021 - |
Question
List all active machineaccounts in the current domain
$ComputerScan = @(Get-QADComputer -sizelimit $sizelimit -IncludedProperties LastLogonTimeStamp -WarningAction SilentlyContinue -Inactive:$false -OSName $computerFilter | where {$_.AccountIsDisabled -eq $false} )
# Create list of computers
ForEach ($Computer in $ComputerScan){
$compObj = New-Object PsObject -Property @{
Computer = $computer
Credentials = $credentials
Domain = $domain
}
$computers += $compObj
}
I am doing a foreach
on $computers
after this but I would like to have a exclusionlist..
Preferably formatted like this
computer1
server4
computet4
But, how?
Greetings from Norway!
Solution
A few improvements to the computer query:
- LastLogonTimeStamp is returned by default, no need to include it
- -Inactive is $false by default, no need to specify it.
Instaed of using where-object, use ldap filters to get enabled computers
$computerScan = Get-QADComputer
-LdapFilter '(!(userAccountControl:1.2.840.113556.1.4.803:=2))'
-Sizelimit $sizelimit -WarningAction SilentlyContinue -OSName $computerFilter | Select-Object -ExpandProperty Name
OTHER TIPS
$ComputerScan = @('blah', 'bluh', 'blih', 'bloh')
$ExclusionList = @('blih', 'blah')
$ComputerScan | where { $ExclusionList -notcontains $_ } | Write-Host
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow