我有一些服务器,我需要授予1个特定用户的pipe理访问权限,即将他添加到本地pipe理员。 我想这可以用PowerShell脚本或别的什么..可以有人build议我如何做到这一点?
如果这台计算机在Active Directory域中,我将通过组策略控制这个。 (您可以通过GPO使用受限制的群组,这会将成员添加到本地pipe理员组,同时删除不应该在其中的成员。)
如果这台电脑不是域的一部分,只需运行
C:\>net localgroup Administrators billybob /add
你当然也可以在batch file中运行上面的行。
也许不是最漂亮的Powershell,绝对不是最短的,但这里是我使用的一个修改版本。
# Get the servers from a file named listOfServers.txt, skip lines # either commented with a # or blank. $serverList = Get-Content -Path C:\temp\listOfServers.txt | where {($_ -notlike "*#*") -and ($_ -notmatch "^\s*$")} # Cycle throught the servers adding the user to the Administrators group. foreach ($server in $serverList) { $computer = [ADSI]("WinNT://" + $server + ",computer") $group = $computer.psbase.children.find("Administrators") $group.Add("WinNT://yourDomainName/" + $user) }
Ryan Ries基本上说了什么。 我曾经使用受限制的组来添加pipe理员(也踢出了不应该在那里的人,奖金!)。
对于非域名计算机,像PsExec这样的计算机列表可以工作。 像这样的东西:
@ECHO ON set controlfile=serverlist.txt FOR /F %%L IN (%controlfile%%) DO ( SET "line=%%L" psexec \\%%L net localgroup Administrators YourDomain\YourUser /add )