techdrive
asked on
Creating a new object
Sorry about the question if it seems trivial but how does one know what commands work together when creating a new object. For example get-mailbox and get-user works together but if I use get-mailboxstatistics or get-mailboxfolderstatistic s I have to do something different. How are you able to tell before you run the command. Another example case and point. If I add get-mailboxstatistics below like I have done it will not run and say something about null value.
$mailboxes = get-mailbox -organizationalunit "OU name"
$mailboxes | %{
$obj = New-Object PSObject
$obj | Add-Member NoteProperty Name $_.Name
$obj | Add-Member NoteProperty Database $_.Database
$obj | Add-Member NoteProperty Title (Get-mailboxstatistics $_.totalitemsize).Title
$obj | Add-Member NoteProperty Dept (Get-User $_.itemcount).Department
Write-Output $obj
}
I don't believe this is really a question about which cmdlets work together.
But it's not really clear to me what you're asking. In your example I don't know which part of the code you're talking about.
Creating a new object is not dependent on other cmdlets in any way. It seems more likely that you are encountering some error (or unexpected results) with the commands
(Get-mailboxstatistics $_.totalitemsize).Title
(Get-User $_.itemcount).Department
which is causing a problem with the Add-Member command.
But it's not really clear to me what you're asking. In your example I don't know which part of the code you're talking about.
Creating a new object is not dependent on other cmdlets in any way. It seems more likely that you are encountering some error (or unexpected results) with the commands
(Get-mailboxstatistics $_.totalitemsize).Title
(Get-User $_.itemcount).Department
which is causing a problem with the Add-Member command.
ASKER
I was clearly wrong..I took a look at my code and corrected this issue
$mailboxes = get-mailbox -organizationalunit ""
$mailboxes | %{
$obj = "" | Select-Object Name,Database,totalitemsiz e,itemcoun t
$obj.Name = $_.Name
$obj.Database = $_.Database
$obj.totalitemsize = (Get-mailboxstatistics $_.Name).totalitemsize
$obj.itemcount = (Get-mailboxstatistics $_.Name).itemcount
Write-Output $obj
}
$mailboxes = get-mailbox -organizationalunit ""
$mailboxes | %{
$obj = "" | Select-Object Name,Database,totalitemsiz
$obj.Name = $_.Name
$obj.Database = $_.Database
$obj.totalitemsize = (Get-mailboxstatistics $_.Name).totalitemsize
$obj.itemcount = (Get-mailboxstatistics $_.Name).itemcount
Write-Output $obj
}
ASKER
I also meant to say thanks footech for pointing this out.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If you run get-help get-mailbox -full
You will see under each parameter Accepts pipeline input? True or False
Depending on the cmdlet and also the parameter you use determines this.
Get-mailbox -Identity (does accept pipeline input) however get-mailbox -Anr or -Filter (does not accept pipeline input).
Will.