PowerCLI-Example-Scripts
PowerCLI-Example-Scripts copied to clipboard
run remove-UserFromSsoGroup error
Describe the bug
@bwuch
I have tested and followed run script second time failed #530. but it seems got another error see update in #530 and made this error. I got error when I run command Get-SsoPersonUser -Name $oldusername -Domain $corpdomain | Remove-UserFromSsoGroup -TargetGroup $vcgroup
PS C:\Users\luy13> Get-SsoPersonUser -Name $oldusername -Domain $corpdomain | Remove-UserFromSsoGroup -TargetGroup $vcgroup Remove-UserFromSsoGroup : One or more errors occurred. At line:1 char:60
- ... e -Domain $corpdomain | Remove-UserFromSsoGroup -TargetGroup $vcgroup
-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
- FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Remove-UserFromSsoGroup
Reproduction steps
1. Close PS ISE
2. reopen PS ISE
3. run vCenter-remove-corpuser.ps1
4. got error
here is vCenter-remove-corpuser.ps1
. "C:\PS_scripts\vCenter\Group.ps1"
$path="C:\Temp\Reports\vCenters\" # output report file location
$server="server.com" # VCD server
$sysgrouplist = "Users",
"Systcorponfiguration.BashShellAdministrators",
"Systcorponfiguration.SupportUsers",
"Systcorponfiguration.ReadOnly",
"WorkloadStorage",
"CAAdmins",
"SolutionUsers",
"ComponentManager.Administrators",
"ServiceProviderUsers",
"ActAsUsers",
""
$username = "[email protected]"
$passwd = password
$localdomain="vsphere.local"
$corpdomain="corp.com"
Write-host "`nRemove users in vCenter $server"
$vcenterfile=$path+"vcenterlist.txt"
$vcenterlist = get-content $vcenterfile
#
Foreach ($server in $vcenterlist) {
$hostname=$server.Split(".")[0]
$imptfile=$path+$hostname+"-grpmbr.txt"
$rptfile=$path+"usrimpt-"+$hostname+".txt"
$grouplist = get-content $imptfile
# Write-host "`nImport users in groups in vCenter $server"
Read-Host -Prompt "`nPress any key to continue remove users to groups in $server"
Connect-SsoAdminServer -Server $server -User $username -Password $passwd -SkipCertificateCheck
For ($i = 0; $i -le ($grouplist.length - 1); $i += 1) {
$groupname=$grouplist[$i].Split(",")[1].Trim()
$oldusername=$grouplist[$i].Split(",")[2].Trim()
$useremail=$grouplist[$i].Split(",")[3].Trim()
$newaccount=$useremail.Split('@')[0]
If (($groupname -notin $sysgrouplist) -and ($useremail -ne "")) {
if ($groupname -eq "ELS"){
$vcgroup = Get-SsoGroup -Name $groupname -Domain $localdomain
Get-SsoPersonUser -Name $oldusername -Domain $corpdomain | Remove-UserFromSsoGroup -TargetGroup $vcgroup
write-host "deleting $oldusername in $groupname Group is done, $useremail, $newaccount"
"$i, $groupname , $oldusername, $useremail, $newaccount" | Out-File -FilePath $rptfile -Append
}
}
}
Disconnect-SsoAdminServer -Server $server
}
Expected behavior
the scirpt should remove user from group. and it worked yesterday.
Additional context
No response