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
nesher13Asked:
Who is Participating?
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

0
nesher13Author Commented:
Vasil !

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

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
Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

nesher13Author Commented:
Vasil!

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

 Getting all Licensed Office 365 users with PowerShell

  there is link:        

  https://support.microsoft.com/en-us/kb/2777380
0
Vasil Michev (MVP)Commented:
No, that's the WAAD PowerShell module (https://msdn.microsoft.com/en-us/library/azure/jj151815.aspx#bkmk_installmodule), not SharePoint.
0
nesher13Author Commented:
The answer was not full
0
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
Powershell

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.