Result of Get-Mailbox when 0 or 1 mailbox is retrieved... NOT AN ARRAY :(

Dear experts,
When I run this command and at least 2 mailboxes are found  the result is an array...

$ArrSMList = get-mailbox | Get-MailboxPermission -user $strUser | ?  {($_.AccessRights -match "FullAccess") -and -not ($_.User -like "NT AUTHORITY\SELF")} | Get-user | Select DisplayName,SamaccountName,Identity

I may ask for $arrSMList.Count or even ($I = 0 to .count)
Write-Host "$ArrSMList[$I]" + $ArrSMList[$I].DisplayName

BUT when only ONE is found NO WAY, I can't access the .Count cause this is not an array...

I would like to have EVEN IF only 1 is found  as return an array.
How can I transform this to an array if ONLY ONE is found ?

tks.
François VDCIcT service DeskAsked:
Who is Participating?
 
oBdAConnect With a Mentor Commented:
Just wrap the expression inside an @():
$ArrSMList = @(Get-Mailbox | Get-MailboxPermission -user $strUser |
	Where-Object {($_.AccessRights -match "FullAccess") -and -not ($_.User -like "NT AUTHORITY\SELF")} |
	Get-User |
	Select-Object DisplayName, SamaccountName, Identity)

Open in new window

0
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.

All Courses

From novice to tech pro — start learning today.