PowerShell: Convert an object to a string

The PowerShelly way

$isNames = @()
$allIS = Get-MailboxDatabase | 
    Where { $_.name -notlike "*Users*" } | 
    Select Identity | 
    %{ $isNames += $_.name }

It pipes the output to a foreach loop using % instead.

A more procedural way

$isNames = @()

foreach ($is in $allIS)
{
    $isNames += $is.identity
}

That gives you a simple array of only the names of the information stores, as strings instead of objects.


It is hard to tell if that could be optimized without seeing the second part...

But it's pretty easy to get a flat array of identities. Either use -ExpandProperty on select, or use foreach { $_.Identity } instead of select:

$allIS = Get-MailboxDatabase | ? { $_.name -notlike "*Users*" } | select -expand Identity
$allIS = Get-MailboxDatabase | ? { $_.Name -notlike '*Users*' | foreach { $_.Identity}

Tags:

Powershell