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.Exchang e.Data.Dir ectory.Man agement.CA SMailbox
TypeName: Selected.Microsoft.Exchang e.Data.Dir ectory.Man agement.Ma ilbox
Need to execute this to few hundred mailaccounts, how do I get them in one object, preferably without using foreach?
J.
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.Exchang
TypeName: Selected.Microsoft.Exchang
Need to execute this to few hundred mailaccounts, how do I get them in one object, preferably without using foreach?
J.
I believe that autor is asking for hashtable like this
or probably more something like this:
or the same, but a bit more effective for processing time
$result=@{
"CasMailbox" = Get-CASMailbox $username | select abc
"Mailbox" = Get-mailbox $username | select xyz
}
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
}
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
}
ASKER
Thanks.
Howto extend if multiple results?
$CasMailbox = Get-CASMailbox -resultsize 10
$Mailbox = Get-mailbox -ResultSize 10
Then export to csv?
J.
Howto extend if multiple results?
$CasMailbox = Get-CASMailbox -resultsize 10
$Mailbox = Get-mailbox -ResultSize 10
Then export to csv?
J.
ASKER
Note: the+ does not work.
Bot are of different type:
Microsoft.Exchange.Data.Di rectory.Ma nagement.M ailbox
Microsoft.Exchange.Data.Di rectory.Ma nagement.C ASMailbox
Bot are of different type:
Microsoft.Exchange.Data.Di
Microsoft.Exchange.Data.Di
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?
So: What do you really want to achieve? What are the generated data to use for?
ASKER
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.
*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.
ASKER
Let me give you an example:
$CasMailbox = Get-CASMailbox | select PrimarySMTPAddress, SamAccountname
$Mailbox = Get-mailbox | select UserPrincipalName, prohibitsendquota
$ResultPSCustomObject = [PSCustomObject]@{
SMTP = $CasMailbox.PrimarySmtpAdd ress
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
$CasMailbox = Get-CASMailbox | select PrimarySMTPAddress, SamAccountname
$Mailbox = Get-mailbox | select UserPrincipalName, prohibitsendquota
$ResultPSCustomObject = [PSCustomObject]@{
SMTP = $CasMailbox.PrimarySmtpAdd
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window