Forum Discussion
Removing Manager for all disabled users
Hi Community,
Currently working on a request for Teams org chart to display updated information.
#Purpose of this script is to cleanup the organization teams chart. I need to remove manager from all disabled users in azure for it reproduce in Teams.
The command below works but I am having trouble pushing it to all filtered disabled accounts
$User = Get-AzureADUser -Top 1
Remove-AzureADUserManager -ObjectId $User.ObjectId
This is how I currently have the Syntax formatted
Get-AzureADUser -Filter "AccountEnabled eq false" -Remove-AzureADUserManager -ObjectId $user.ObjectId
Please provide any guidance, a true rookie.
Thanks
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
}
3 Replies
- Ty__AdventurousAdminCopper ContributorERROR once ran
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- raindropsdevIron Contributor
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__AdventurousAdminCopper 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
}