Forum Discussion
Removing Manager for all disabled users
- Oct 04, 2022
raindropsdev Thanks for the update and the syntax help.
Forgot to post an update on what also got me through.
$Users = Get-AzureADUser -Filter "AccountEnabled eq false"#Remove-AzureADUserManager -ObjectId $Users[0].ObjectId
foreach ($User in $Users) {
Remove-AzureADUserManager -ObjectId $User.ObjectId
}
Get-AzureADUser : Cannot convert 'System.Object[]' to the type 'System.String' required by parameter 'ObjectId'. Specified method is not supported.
At line:2 char:88
+ ... Enabled eq false" -Remove-AzureADUserManager -ObjectId $user.ObjectId
+ ~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Get-AzureADUser], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgument,Microsoft.Open.AzureAD16.PowerShell.GetUser
Two things: Be careful using Azure AD Powershell if you're planning for this script to be run regularly, because it will be decommissioned at the end of this year.
Second, you can do just pipe the results of the first command through like this:
Get-AzureADUser -Filter "AccountEnabled eq false" | Remove-AzureADUserManager
- Ty__AdventurousAdminOct 04, 2022Copper Contributor
raindropsdev Thanks for the update and the syntax help.
Forgot to post an update on what also got me through.
$Users = Get-AzureADUser -Filter "AccountEnabled eq false"#Remove-AzureADUserManager -ObjectId $Users[0].ObjectId
foreach ($User in $Users) {
Remove-AzureADUserManager -ObjectId $User.ObjectId
}