We have Exchange Info Stores that begin with UsersA-B, UsersC-D, etc., and then some that are outside that naming convention.
$allIS = Get-MailboxDatabase |
Where { $_.name -notlike "*Users*" } |
Select Identity
I'll lookup a current user's info store, and then try to do a comparison on the $allIS array. If it matches, do some action.
When I output the value of $allIS[0] for instance, it returns @{Identity=MSCCR\CEO\CEO}
.
I'd like to throw those converted strings into a different array, and then do the comparison. This would be to have a dynamic list of information stores to compare against. But maybe this isn't the best, most efficient way. What would be the best way to try to do this comparison, as right now I'm comparing apples to oranges here?
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}
$isNames = @()
$allIS = Get-MailboxDatabase |
Where { $_.name -notlike "*Users*" } |
Select Identity |
%{ $isNames += $_.name }
It pipes the output to a foreach
loop using %
instead.
$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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With