Department list of users do not have a license for Office365

Hi folks,

My organization has a subscription to Office 365. Cloud sync with the local AD

I am establish the remote session with the cloud. I want to find all users in who do not have a license for Office 365.
For first, I wrote the following pipe:

Get-MsolUser -MaxResults 500 | Where-Object { $_.isLicensed -eq "false"  }  | Select-Object UserPrincipalName, DisplayName, Department | sort department | Export-Csv c:\powershell\LicensedUsers.csv  
and receive valid csv table.
then I want to get a list of users for a particular department, and for this to run the following command

Get-MsolUser -MaxResults 500 | Where-Object { $_.isLicensed -eq "false" -and $_.department -eq "marketing"  }  | Select-Object UserPrincipalName, DisplayName,  Department | Export-Csv c:\powershell\LicensedUsers.csv

Pipe  is running without an error messages, but the csv table is empty

What I did wrong?

Please, help
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Vasil Michev (MVP)Commented:
Try this:

Get-MsolUser -MaxResults 500 | Where-Object { $_.isLicensed -eq $false -and $_.department -eq "marketing"  }  | Select-Object UserPrincipalName, DisplayName,  Department | Export-Csv c:\powershell\LicensedUsers.csv

Open in new window

nesher13Author Commented:
Vasil !

how does this differ from my pipe?
Vasil Michev (MVP)Commented:
You are using string for "false", you should use the variable $false instead.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud as a Security Delivery Platform for MSSPs

Every Managed Security Service Provider (MSSP) needs a platform to deliver effective and efficient security-as-a-service to their customers. Scale, elasticity and profitability are a few of the many features that a Cloud platform offers. View our on-demand webinar to learn more!

nesher13Author Commented:

Do I have to do it in SharePoint Online Management Shell ?

 Getting all Licensed Office 365 users with PowerShell

  there is link:  
Vasil Michev (MVP)Commented:
No, that's the WAAD PowerShell module (, not SharePoint.
nesher13Author Commented:
The answer was not full
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.