简体   繁体   English

计算机的动态AD组成员身份

[英]Dynamic AD group membership for computers

I am trying to write a script i can run to dynamically manage computers in a security group in AD. 我正在尝试编写一个脚本,我可以运行该脚本来动态管理AD安全组中的计算机。 I've successfully done the first bit but would like it make some additions. 我已经成功地完成了第一部分,但希望它能做一些补充。 So far I have: $computers = Get-ADComputer -Filter * -Searchbase "OU=Clients,OU=Devices,DC=domain,DC=local" | select-object -expandproperty DistinguishedName | out-file C:\\computers.txt Get-Content c:\\computers.txt | Add-ADPrincipalGroupMembership -MemberOf 'Group_C' 到目前为止,我有: $computers = Get-ADComputer -Filter * -Searchbase "OU=Clients,OU=Devices,DC=domain,DC=local" | select-object -expandproperty DistinguishedName | out-file C:\\computers.txt Get-Content c:\\computers.txt | Add-ADPrincipalGroupMembership -MemberOf 'Group_C' $computers = Get-ADComputer -Filter * -Searchbase "OU=Clients,OU=Devices,DC=domain,DC=local" | select-object -expandproperty DistinguishedName | out-file C:\\computers.txt Get-Content c:\\computers.txt | Add-ADPrincipalGroupMembership -MemberOf 'Group_C'

I would like to exclude machines that already bellong to Group_A and Group_B and remove machines from Group C if they no longer appear in computers.txt 我想排除已经与Group_A和Group_B竞争的机器,如果它们不再出现在computers.txt中,则将它们从组C中删除。

The following will exclude computers from Group_A and Group_B: 以下内容将从Group_A和Group_B中排除计算机:

$GroupA_DN = "<GroupA DistinguishedName>"
$GroupB_DN = "<GroupB DistinguishedName>"

Get-ADComputer -filter {memberof -ne $GroupA_DN -and memberof -ne $GroupB_DN}

The $GroupA_DN variable will need to have a string of the distinguished name of group A. For example, $GroupA_DN = "CN=Group_A,OU=SomeOU,OU=Clients,OU=Devices,DC=domain,DC=local" . $GroupA_DN变量将需要具有字符串A组的专有名称。例如, $GroupA_DN = "CN=Group_A,OU=SomeOU,OU=Clients,OU=Devices,DC=domain,DC=local" The same will need to be repeated for group B in its respective variable. 对于组B,需要在其相应变量中重复相同的操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM