I wanted to add multiple members to local admin group, below is the code
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
)
$strCo开发者_JAVA技巧mputer="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)}
}
when I run the function im able to run it as
Add-Admin -username vinith -domain corp.a.org
what i want is, to supply multiple user names to be added
Add-Admin -username vinith,ith,itops -domain corp.a.org
can anyone help me out on how to go about & add vinith,ith,itops (more than one user at a time)
Just consider your $username variable as an array (as it is)
replace :
$Group.Add("WinNT://" + $domain + "/" + $username)
by
foreach ($user in $username)
{
$Group.Add("WinNT://" + $domain + "/" + $user)
}
精彩评论