我们的应用程序将在本地用户组中添加用户列表。
用户将与组相关联,如果更改了用户名,我们可能需要按组进行更新。
我试图在Powershell中使用[ADSI]首先获取列表,然后对其进行修改。
$MyprojGroups=@("Myproj Engineers",
"Myproj Managers",
"MyprojDBUser",
"MyprojUser")
Foreach( $MyprojGroup in $MyprojGroups) {
Write-host "MyprojGroup : $MyprojGroup "
$usergroup=[ADSI]($MyprojGroup).psbase.Path
$usergroup
UpdateUserName -groupName $usergroup -OlduserName "Administrator" -NewuserName "Admin"
}
Function UpdateUserName {
Param (
[string]$OlduserName,
[string]$groupName,
[string]$NewuserName
)
# To check whether the user name is associated with the group
$MEm=$groupName.psbase.Invoke("Members") | foreach {$_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null)}
If ($mem -eq "OlduserName") {
# Has to update the New User Name
}
}
但是,ADSI不接受直接传递组名。如果用户名与分配的组相关联,如何更新?
最佳答案
您是否要在要检查的每台计算机上运行powershell脚本?
是否要将本地用户添加到本地组?
你能尝试类似的东西吗(当然是在管理员 shell 内):
$grp = [ADSI]"WinNT://$computerName/$groupName,group"
$grp.add("WinNT://$computerName/$NewUserName")
$grp.remove("WinNT://$computerName/$OldUserName")
关于powershell - 如何更新本地用户组的用户名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11687152/