PowerShell:  Where-Object not working as a filter

K B
K B used Ask the Experts™
on
I can't seem to limit this $userLicenses (without actually explicitly setting it)

What am I missing?

 $userLicenses = $userLicense | ? {$usersku -eq 'contoso:ENTERPRISEPACK'}

Open in new window


$UserLicenses yields all the user's licence SKUs, instead of the one.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2014
Commented:
Have you tried
 $userLicenses = $userLicense | ? {$_ -eq 'contoso:ENTERPRISEPACK'}

Open in new window

?

Remember, you've got to filter based on the current object.

Commented:
What is the value of the $userLicense and $usersku variables?

Here's an example if you were working with objects returned from the Get-MsolAccountSku cmdlet:

Get-MsolAccountSku | Where-Object {$_.accountskuid -eq 'contoso:ENTERPRISEPACK'}

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial