【问题标题】:Find computers that are not members of a specific GG group查找不属于特定 GG 组成员的计算机
【发布时间】:2019-10-20 22:20:51
【问题描述】:

我使用脚本导出不在活动目录中特定 GG 组中的用户,但我想对计算机执行相同操作。

这是适用于用户的示例:

$groups = 'GG_LCS_UsersType4', 'GG_LCS_UsersType3', 'GG_LCS_UsersType2', 'GG_LCS_SpecialUsers'
$whereFilter = $groups | Foreach-Object { 
    $g = (Get-ADGroup -server $domain $_).DistinguishedName
    "{0} '{1}'" -f '$_.memberOf -notcontains',$g 
}
$whereFilter = [scriptblock]::Create($whereFilter -join " -and ")
$users = (Get-ADUser -server $Domain -filter {objectclass -eq "user"} -properties memberof).where($whereFilter)
$users | Select-Object SamAccountName,Enabled |
    Export-Csv "${Domain}_Users_withoutGG.csv" -NoTypeInformation -Encoding UTF8 -Append

我尝试这样做是为了对计算机做同样的事情,但这不起作用:

$groups = 'GG_LCS_ComputersType2', 'GG_LCS_ComputersType3', 'GG_LCS_ComputersType4'
$whereFilter = $groups | Foreach-Object { 
    $g = (Get-ADGroup -server $domain $_).DistinguishedName
    "{0} '{1}'" -f '$_.memberOf -notcontains',$g 
}
$whereFilter = [scriptblock]::Create($whereFilter -join " -and ")
$users = (Get-ADComputer -server $Domain -filter {objectclass -eq "computer"} -properties memberof).where($whereFilter)
$users | Select-Object SamAccountName,Enabled |
    Export-Csv "${Domain}_Computers_withoutGG.csv" -NoTypeInformation -Encoding UTF8 -Append

你能帮帮我吗?谢谢!

【问题讨论】:

  • 视情况而定。什么不符合您的预期(即您预期的结果是什么,您实际得到了什么结果)?
  • 我在我的电脑上试过这个,根据我的解释它可以正常工作。我唯一要改变的是最后选择 SamAccountName。计算机对象的 SamAccountName 将包含 $。对于计算机,我会切换到Select-Object Name,Enabled

标签: powershell active-directory active-directory-group


【解决方案1】:

尝试添加 -SearchBase

$AD = Get-ADComputer  -Filter *  -Properties $properties -SearchBase "DC=subdomain,DC=domain,DC=com" -Server $server
$AD | Select-Object * | Export-Csv -NoTypeInformation $filePath -Encoding UTF8

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-04
    相关资源
    最近更新 更多