Finding all F3 users from list with PowerShell

Brass Contributor

Hello I am trying to get a PS script to go through a list of users and filter it out so only the F3 SKU users are listed as TRUE in the isLicensed column in the .csv output. The issue I am having is that when I run the script it is showing ALL users from the users.txt file as TRUE (meaning they should be F3) but when double checking random users they are show up as E3. The script I am using is below. I was told that using the -notmatch should work but no dice. Any ideas how I can get this to work? Many thanks!

 

Get-content c:\temp\users.txt | foreach {Get-MsolUser -UserPrincipalName $_ | Where-Object {($_.licenses).AccountSkuId -notmatch "SPE_E3"}} | Select-Object UserPrincipalname,islicensed | Export-csv c:\temp\Users_Without_E3.csv

 

 

4 Replies
Have you checked a user manually and verified that the E3 SKU ID is SPE_E3

Hello@Thijs Lecomte and thanks for the reply. Yes I have verified the SKU id for the a known E3 user and a known F3 user in the list to verify the correct SKU id is being used in the script.

 

Thanks.

I just did some tests.
I think your issues might come from a few things:

- Are you 100% sure about the AccountSkuID, because for me an E1 has 'STANDARDPACK' as it's accountskuid
- Is it possible users have multiple licenses? F3/E3
- Is the isLicensed field in your CSV?

Hello@charlie4872 !
I've tried the same script and other variations of my own and I got it to work correct. 

 

Is it possible for you to share the Source file ( users.txt ) so I can see what fields you have and if something there might be wrong? 

 

Also, maybe convert the txt to csv format and see if that works better? 
Try and work with variables instead of using so many pipes as well. 

I managed to do this with a few users with the following script ( I used another SKU tho ) 

 

Connect-Msolservices
$Users = Import-csv -Path "C:\Path\Users.csv
$SKU = "O365_BUSINESS_ESSENTIALS"

Foreach ($User in $Users) {

Get-Msoluser -UserPrincipalName $User.UserPrincipalName | Where-Object {($_.Licenses).accountSkuId -notcontains $SKU} | Export-csv "C:\Path\Export.csv"

 

Let me know how it goes 

 

Kind Regards
Oliwer Sjöberg