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-mailboxfolderstatistics 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
}

Open in new window

techdriveAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Will SzymkowskiSenior Solution ArchitectCommented:
The key here is if the cmdlets and the parameters "Accepts Pipeline input" from other cmdlets.

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.
footechCommented:
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.
techdriveAuthor Commented:
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,totalitemsize,itemcount
$obj.Name = $_.Name
$obj.Database = $_.Database
$obj.totalitemsize = (Get-mailboxstatistics $_.Name).totalitemsize
$obj.itemcount = (Get-mailboxstatistics $_.Name).itemcount
Write-Output $obj
}
techdriveAuthor Commented:
I also meant to say thanks footech for pointing this out.
footechCommented:
Glad you worked it out.  Please remember to close the question as you see fit.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Exchange

From novice to tech pro — start learning today.