Link to home
Start Free TrialLog in
Avatar of janhoedt
janhoedt

asked on

PS: how do I get one hashtable of two results/queries?

Hi,

This works ...
$CasMailbox = Get-CASMailbox $username | select abc
$Mailbox =  Get-mailbox $username | select xyz
$Result = $CasMailbox,$Mailbox

but it creates two object
$Result | gm
TypeName: Selected.Microsoft.Exchange.Data.Directory.Management.CASMailbox
TypeName: Selected.Microsoft.Exchange.Data.Directory.Management.Mailbox

Need to execute this to few hundred mailaccounts, how do I get them in one object, preferably without using foreach?

J.
Avatar of Qlemo
Qlemo
Flag of Germany image

Just add them. But make sure the properties are the same, otherwise you'll get incomplete dumps with export-csv and format-* aso.
$Result = $CasMailbox + $Mailbox

Open in new window

I believe that autor is asking for hashtable like this
$result=@{
"CasMailbox" = Get-CASMailbox $username | select abc
"Mailbox" =  Get-mailbox $username | select xyz
}

Open in new window


or probably more something like this:

$result=@{
"a"=(Get-CASMailbox $username).a
"b"=(Get-CASMailbox $username).b
"c"=(Get-CASMailbox $username).c
"x"=(Get-mailbox $username).x
"y"=(Get-mailbox $username).y
"z"=(Get-mailbox $username).z
}

Open in new window


or the same, but a bit more effective for processing time

       
$CasMailbox = Get-CASMailbox $username | select abc
$Mailbox =  Get-mailbox $username | select xyz     
$result=@{
"a"=$CASMailbox.a
"b"=$CASMailbox.b
"c"=$CASMailbox.c
"x"=$mailbox.x
"y"=$mailbox.y
"z"=$mailbox.z
}

Open in new window

Avatar of janhoedt
janhoedt

ASKER

Thanks.
Howto extend if multiple results?

$CasMailbox = Get-CASMailbox -resultsize 10
$Mailbox =  Get-mailbox -ResultSize 10

Then export to csv?

J.
Note: the+ does not work.
Bot are of different type:
Microsoft.Exchange.Data.Directory.Management.Mailbox
Microsoft.Exchange.Data.Directory.Management.CASMailbox
If they have a different type and different structure, you need to "normalize" them, i.e. create new objects with common properties. You cannot export mixed object types into CSV (that well), as I already stated. And it really doesn't make sense to do a full export of such objects, with their nested object information and real load of data.

So: What do you really want to achieve? What are the generated data to use for?
What I want to achieve:
*get certain properties of a list of users via Get-CASMailbox $username | select abc
*get other properties of the same list of users via Get-mailbox $username | select xyz

Combine them in an $Result and have this exported to a csv so the csv has the specific properties of all those users.
Let me give you an example:

$CasMailbox = Get-CASMailbox | select PrimarySMTPAddress, SamAccountname
$Mailbox =  Get-mailbox | select UserPrincipalName, prohibitsendquota

$ResultPSCustomObject = [PSCustomObject]@{
      SMTP = $CasMailbox.PrimarySmtpAddress
      SamAccountName = $CasMailbox.Identity
      UPN = $Mailbox.UserPrincipalName
      ProhibitSendQuota = $Mailbox.ProhibitSendQuota
     }
$ResultPSCustomObject | Out-File C:\Result.csv

Everything works BUT the Result.csv does not contain the data which is in $ResultPSCustomObject
Just using Out-File is a bad way to get file output. But it should work, if applied to a single object with simple types. And it doesn't generate a CSV format file.

Did you want to provide the same username for both cmdlets, and then mix/combine some of the properties for a single user, as shown in your question?
If you run the commands as shown later, you do not have any relation between CASMailbox and Mailbox properties - they can be from different users.
ASKER CERTIFIED SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial