我正在使用以下功能将用户添加到本地用户组。我需要将一组用户添加到我机器上的本地组。
function AddUsersToGroup([string]$MachineName,[string]$GroupName,[String[]]$Userarr)
{
write-host 'write: $Userarr'
Foreach($s in $Userarr)
{
write-host $s
}
$objOU = [ADSI]"WinNT://$MachineName/$GroupName,group"
Foreach($User in $Userarr)
{
$objOU.add("WinNT://$MachineName/$User,user")
}
}
$UserArray=@("Administrator", "NETWORK SERVICE", "LOCAL SERVICE","SYSTEM")
AddUsersToGroup -MachineName:"localhost" -GroupName:"Comserver Consumer",-Userarr:@("Administrator", "NETWORK SERVICE", "LOCAL SERVICE","SYSTEM")
AddUsersToGroup -MachineName:"localhost" -GroupName:"Comserver Consumer",-Userarr:@("Administrator", "NETWORK SERVICE", "LOCAL SERVICE","SYSTEM")
我收到以下错误:
检索成员“add”时发生以下异常:
找不到组名。
我是PowerShell的新手。请帮忙 :)