Someone tell me that I'm simply doing something wrong. My objective is to get a CSV with all M365 users that are unlicensed (cause any of our clients licensed users are still synced from AD), DO still have the ImmutableID field filled in (even though they're cloud only), and they are not external users. So far I've connected to MSOL PowerShell and used the following:
Get-MsolUser -All | Where-Object {($_.ImmutableID -ne $null) -and ($_.IsLicensed -eq $False)} | Select UserPrincipalName, ImmutableID, isLicensed
This returns me a list of unlicensed users with the ImmutableID field and UPN, so I see cloud only users even though some of them still have an ImmutableID linking them to an on-prem user object (I.E some of them return ******@clientdomain.com, some return a random string of characters linking them to an on-prem user). I tried to append:
-and ($_.ImmutableID -NotLike "clientdomain.com")
-and ($_.ImmutableID -NotContains "clientdomain.com")
So that I could filter out external users and cloud only internal users with a cloud only style ImmutableID, but I still get users with a cloud only style ImmutableID and external users. Am I missing something?
New thought as I'm writing... yes I appended:
| Export-Csv C:\Temp\filename.csv at the end.