【发布时间】:2021-01-08 10:16:17
【问题描述】:
我有以下 Powershell 脚本:
$domainObj = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()
$PDC = ($domainObj.PdcRoleOwner).Name
$SearchString = "LDAP://"
$SearchString += $PDC + "/"
$DistinguishedName = "DC=$($domainObj.Name.Replace('.', ',DC='))"
$SearchString += $DistinguishedName
$Searcher = New-Object System.DirectoryServices.DirectorySearcher([ADSI]$SearchString)
$objDomain = New-Object System.DirectoryServices.DirectoryEntry
$Searcher.SearchRoot = $objDomain
$Searcher.filter="samAccountType=805306368"
$Result = $Searcher.FindAll()
Foreach($obj in $Result)
{
Foreach($prop in $obj.Properties)
{
$prop
}
Write-Host "------------------------"
}
我需要对此进行修改以执行以下操作,但我不确定如何应用正确的过滤器,我认为需要进入$Searcher.filter:
- 将脚本更改为仅返回 Domain Admins 组的成员。
- 更改脚本以返回域中的所有计算机。
- 添加过滤器以仅返回运行 Windows 10 的计算机。
【问题讨论】:
-
你有什么理由不使用
Get-ADComputer和Get-ADUser/Get-ADGroup? -
Get-ADUser 等 cmdlet 默认仅在 DC 上。脚本的重点是能够在没有这些的情况下进行查询。
-
您可以安装 rsat 工具以使用这些功能
-
脚本的重点是能够在没有这些的情况下进行查询。
-
看看脚本github.com/lazywinadmin/PowerShell/blob/master/… 它确实查询计算机,然后您可以过滤输出,如
Get-Domaincomputer -DomainDN 'DOMAINNAME' -ComputerName * | where {operatingsystem -like 'Windows 10*'}
标签: powershell active-directory