Posted by on January 27, 2016

Of course, this only works with a single column in the hashtable…

Say you have a list of mailboxes in a hashtable, like this:

$Mailboxes = Get-Mailboxes -OrganizationalUnit administration

But for some reason (It doesn’t really matter why, does it? You just do.) you want a list of their User Principal Names in an array instead of the hashtable. You can do this like so:

$Array = @()
$Mailboxes | Foreach {$Array += $_.UserPrincipalName}

Now if you check your @Array, you’ll find something like this:

(You might be thinking that email address seems a much more obvious target for this example. Try the PrimarySmtpAddress or WindowsEmailAddress attributes. You’ll see why I didn’t use them. You can still do it, but it’s trickier. Let’s save that one for another day.)

Posted in: PowerShell


Be the first to comment.

Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>