Our application will add list of user in local user groups.
Users will be associated with the groups , if the user name is changed we may need to update them in groups.
I was trying to use [ADSI] in powershell to get the list first then modify it .
$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
}
}
But passing the groupname directly is not being accepted for ADSI. How to update the user name if it associated with the assigned groups?