0

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!

Sune
  • 3,080
  • 16
  • 53
  • 64

2 Answers2

1
$ComputerScan = @('blah', 'bluh', 'blih', 'bloh')
$ExclusionList = @('blih', 'blah')

$ComputerScan | where { $ExclusionList -notcontains $_ } | Write-Host
David Brabant
  • 41,623
  • 16
  • 83
  • 111
1

A few improvements to the computer query:

  1. LastLogonTimeStamp is returned by default, no need to include it
  2. -Inactive is $false by default, no need to specify it.
  3. 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

Shay Levy
  • 121,444
  • 32
  • 184
  • 206