Powershell - Get-ADComputer -properties memberof

*爱你&永不变心* 提交于 2019-12-02 11:28:10

Let's work with this:

$groups = @("Terminal Server License Servers","Exchange Trusted Subsystem","Cert Publishers")
$regex = '^({0})' -f ($groups -join '|')
get-adcomputer -Filter {OperatingSystem -like "Windows Server 200*"} -properties * | 
    Where-Object{($_.MemberOf | Get-ADGroup).Name -notmatch $regex} |
    Select-Object Name,OperatingSystem,MemberOf

Take the groups and turn them into an array. Join the array members into a regex string which will match the full names of groups. Move the If statement into a -Filter to return only what you want which would make it more efficient. The MemberOf is a list of DistinguishedNames. Get the just the group name from Get-AdGroup. You could easily use string manipulation to extract the name from the dn. I just find this easier. Havent done anything, beyond a Select-Object, with the results but you could pipe into a ForEach-Object and process accordingly.

[System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest().Sites | if($server.OperatingSystem -match "Windows Server 200[38]"| % { $_.Server }

| select Domain,Name,Roles,OSVersion,IPAddress

$servers = get-adcomputer -Filter 'ObjectClass -eq "Computer"' -properties * |
if($server.OperatingSystem -match "Windows Server 200[38]" | 
% { $_.Server } | select Domain,Name,Roles,OSVersion,IPAddress

Provides only 2003 and 2008 matches filtering

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!