我想将多个成员添加到本地管理员组,下面是代码
function Add-Admin {
[CmdletBinding()]
Param
([Parameter(Mandatory=$true,ValueFromPipeline=$true,HelpMessage="UserName to be added to local Admin Group")]
[string[]]
$username
,[Parameter(Mandatory=$true,ValueFromPipeline=$true,HelpMessage="Domain in which the UserName exists")]
[string[]]
$domain
)
$strComputer="localHost"
$computer = [ADSI]("WinNT://" + $strComputer + ",computer")
$computer.name
$Group = $computer.psbase.children.find("administrators")
$Group.Add("WinNT://" + $domain + "/" + $username)
$Group.name
$Group.psbase.invoke("Members") | %{$_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null)}
}
当我运行该函数时,我能够将其作为
运行Add-Admin -username vinith -domain corp.a.org
我想要的是,提供多个要添加的用户名
Add-Admin -username vinith,ith,itops -domain corp.a.org
任何人都可以帮助我解决如何去做&添加 vinith,ith,itops (一次超过一个用户)
答案 0 :(得分:1)
将$ username变量视为数组(原样)
替换:
$Group.Add("WinNT://" + $domain + "/" + $username)
通过
foreach ($user in $username)
{
$Group.Add("WinNT://" + $domain + "/" + $user)
}