2011-04-03 210 views
1

如何從文本文件中將多個計算機帳戶添加到Active Directory中的安全組中?我將這段代碼放在一起,但它只適用於用戶帳戶。Powershell - 將計算機添加到Active Directory中的安全組

Import-Module ActiveDirectory 

Get-Content C:\Servers.txt | Foreach-Object {Add-ADGroupMember "WSUS Auto Download and Notify for Install" $_} 
+0

你得到一個錯誤信息? – dugas 2011-04-04 02:13:08

+1

計算機的帳戶名稱已粘貼到它的末尾。是你做的嗎? (名爲「server1」的服務器的帳戶名稱爲「server1 $」。) – OldFart 2011-04-04 15:05:38

回答

0

您正在查找的命令是Add-ADPrincipalGroupMembership。

Get-Content c:\servers.txt | Add-ADPrincipalGroupMember -memberof 'WSUS Auto Download and Notify for Install' 

如果您需要添加「$」的計算機名的末尾,你的命令可以使用腳本塊參數(一個anoymous功能,可以修改管道輸入)。

Get-Content c:\servers.txt | Add-ADPrincipalGroupMember -memberof 'WSUS Auto Download and Notify for Install' -identity {"$_$"} 
0

我使用-Identity $ _。的objectGUID

$ _ $沒有爲我工作。

編輯:啊,對不起,這是因爲我使用Get-ADComputer管道它,而不是一個文本文件。

0

我有類似的任務發現info on this link工作對我來說,

運行它在PowerShell中的管理

Import-Module ActiveDirectory 
$List=Get-Content c:\computers.txt 
$List | foreach {Add-ADGroupMember -id ADGroupName -MEMBERS (Get-ADComputer $_) 
相關問題