Webtron
Webtron

Reputation: 473

How to Parse the Results of CMDlet into Array

I am sure there is an easy answer to this question, but I cannot find it anywhere. I would like to know how to parse the results of Get-Mailbox | select Alias into an array so each time I use the array it does not show the items as "@{Alias=username}".

I have tired this, but it seems to make the values not text:

$arrayname = Get-Mailbox | select Alias

I am sure this question has been asked before, but I cannot find it.

Essentially I would like to get the Alias' from the Get-Mailbox command into an array so that I can use the foreach cmdlet to get specific folder information from a user like so:

>> $aliases = Get-Mailbox | select Alias
>> Foreach ($username in $aliases) {Get-MailboxFolderStatistics -identity $username | select FolderPath | where {$_.FolderPath -like '*Deleted*'} | Export-CSV "C:\users\username\desktop\allusers-deletedfolder-postarchive.csv" -NoTypeInformation}

Upvotes: 0

Views: 2175

Answers (1)

Ansgar Wiechers
Ansgar Wiechers

Reputation: 200193

The cmdlet already produces an array, only that its elements are mailbox objects, not strings. Selecting the Alias property restricts the object properties, but still leaves you with an array of objects (hence the output you observed). You need to expand the property:

$arrayname = Get-Mailbox | select -Expand Alias

or echo it in a loop:

$arrayname = Get-Mailbox | % { $_.Alias }

Upvotes: 1

Related Questions