2012-04-26 46 views
0

列出所有活動machineaccounts當前域

$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 
} 

我這個後上做$computers一個foreach,但我想有一個exclusionlist .. 最好格式化如下排除的結果列表(從返回GET-QADComputer)

computer1 
server4 
computet4 

但是,怎麼樣?

來自挪威的問候!

回答

1

到電腦查詢一些改進:

  1. 的lastLogonTimestamp默認情況下返回,沒有必要將其列入
  2. -inactive缺省爲$ false時,無需指定。
  3. Instaed使用Where對象,使用LDAP篩選器以獲得功能的電腦

    $ computerScan = GET-QADComputer -LdapFilter '(!(userAccountControl:1.2.840.113556.1.4.803:=2))' -Sizelimit $的sizeLimit -WarningAction SilentlyContinue -OSName $ computerFilter的| Select-Object -ExpandProperty Name

+0

謝謝謝! – Sune 2012-05-09 10:46:48

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

$ComputerScan | where { $ExclusionList -notcontains $_ } | Write-Host 
+0

這不起作用,因爲get-qadcomputer返回對象。謝謝你嘗試! – Sune 2012-04-26 12:25:13

+0

你不能篩選其中一個屬性嗎? $ _。電腦什麼的? – 2012-04-26 12:31:13