K B
asked on
PowerShell: Use of subproperties in a Select statement
I get this error when I attempt to run this script... any ideas? How does one expand then use the subproperty?
Select-Object : Cannot convert System.Object[] to one of the following types {System.String, System.Management.Automati on.ScriptB lock}.
At C:\scripts\subtotal2.ps1:4 char:5
+ Select-Object -Unique -Property $target, @{
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Select-Object], NotSupportedException
+ FullyQualifiedErrorId : DictionaryKeyUnknownType,M icrosoft.P owerShell. Commands.S electObjec tCommand
Thank you.
Select-Object : Cannot convert System.Object[] to one of the following types {System.String, System.Management.Automati
At C:\scripts\subtotal2.ps1:4
+ Select-Object -Unique -Property $target, @{
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Select-Object], NotSupportedException
+ FullyQualifiedErrorId : DictionaryKeyUnknownType,M
$report = Get-MoveRequest -ResultSize 5 | Get-MoveRequestStatistics | Select {$_.targetdatabase.name},totalmailboxsize
$target = $report.{$_.targetdatabase.name}
$report | Group-Object -Property $target |
Select-Object -Unique -Property $target, @{
Label = "Sum";
Expression = {
# Sum all the counts for each domain
($PSItem.group | Measure-Object -Property totalmailboxsize -sum).Sum
}
} |
Sort-Object -Property Sum -Descending |
Out-GridView -Title "Size Per Database"
Thank you.
Hi KB
Just so I understand the purpose of the code you posted. It looks like you're attempting to query mailbox move request and gather the overall mailbox size being moved to specific targetmailboxdatabase(s).
Just so I understand the purpose of the code you posted. It looks like you're attempting to query mailbox move request and gather the overall mailbox size being moved to specific targetmailboxdatabase(s).
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That is absolutely perfect! thank you!
Is there any way to make the Totalmailboxsize output as GBs?
And my main question is, where does $_.Name come from? I see it used as the expression in the select-object command and cannot figure it out.
For example, when I execute these commands:
... there is no Name property.
I really appreciate your help.. this is great thank you again.
Is there any way to make the Totalmailboxsize output as GBs?
And my main question is, where does $_.Name come from? I see it used as the expression in the select-object command and cannot figure it out.
For example, when I execute these commands:
$report = Get-MoveRequest -ResultSize 5 | Get-MoveRequestStatistics | Select @{n="DatebaseName";e={$_.targetdatabase.name}},totalmailboxsize
$report | GM
... there is no Name property.
I really appreciate your help.. this is great thank you again.
ASKER
I am guessing for the GB conversion?...
ohhh..
$report = Get-MoveRequest -ResultSize 5 | Get-MoveRequestStatistics | Select @{n = "DatabaseName"; e = {$_.targetdatabase.name}}, @{n='total';e={($_.totalmailboxsize/1GB)}}
$report | Group-Object -Property DatabaseName |
Select-Object -Property @{n = "DatabaseName"; e = {$_.Name}}, @{
Label = "Sum";
Expression = {
($PSItem.group | Measure-Object -Property total -sum).Sum
}
} |
Sort-Object -Property Sum -Descending |
Out-GridView -Title "Size Per Database"
ohhh..
$report | Group-Object -Property databasename | GM
ASKER
Thank you again footech!
Yep, you've got it. The Name property comes from Group-Object.
Is there any way to make the Totalmailboxsize output as GBs?I could only answer that if I knew what the Totalmailboxsize property is currently. If it's just a number of bytes, then you can create a new calculated property and give the value as Totalmailboxsize divided by 1GB. So yes, your example/guess above would be my guess as well.
$target.gettype().name