开发者

Editing user groups using Powershell

开发者 https://www.devze.com 2023-03-11 20:43 出处:网络
I wanted to add multiple members to local admin group, below is the code function Add-Admin { [CmdletBinding()]

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)
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号