Guys,
I have an interesting powershell question.
Forgive me, I'm not a powershell expert...but I want to delete all users in the cloud that are a) not licensed and b) not administrators... Short and sweet, we have a lab that we're using to test O365 features, etc. and one of the tests was to do a
directory sync with specific OU's, however, we accidentally sync'd the entire AD domain. I don't want to remove admins, and we have some sharepoint licensed users I want to keep, however, blow away everything else in the lab. I've already stopped
Directory Synchronization, just need to get a powershell to delete the objects in the cloud.
I've figured out how to query for the non-licensed users....
Get-MSOLUser -all | where {$_.islicensed -eq "False"}
And how to get all of the global admins:
$role = Get-MSOLRole -RoleName "Company Administrator"
Get-MSOLRoleMember -RoleObjectID &role.objectid
But I'm having a heck of a time figuring out a powershell that will Get all False licensed users AND All Non-Administrators and then pipe that to a remove-msoluser command.
I figure something like:
Get-MSOLUser -all | where {$_.islicensed -eq "False"} | ????? for all non-admins | remove-msoluser
Either like above, or if the Get-MSOLUser would have an attribute marking if it's an admin or not (not seeing one) would make it easier.
Any help anyone can think of is :bowdown:
Thanks in advance!!!