Help with piping a command output to a variable

by gte at 2013-01-11 13:19:13


I’m new to powershell but am well versed in C sharp so I’m not new to programming. I can’t figure out how to pipe the output of this command into a variable instead of a text file, so that I can then join it with another variable and write a single output line to a text file.

Get-MailboxDatabase -Identity $dbpath | Get-Mailbox | get-random | Get-NamedProperty | FT PropertyID >> "c:\Temp\mbdboutput1.txt"

Something along the lines of what’s below. Thanks for reading.

$server = [value from foreach loop]
$propId = Get-MailboxDatabase -Identity $dbpath | Get-Mailbox | get-random | Get-NamedProperty | FT PropertyID

$server + " " + $propId >> "c:\Temp\mbdboutput1.txt"

by ArtB0514 at 2013-01-14 06:25:02
Whenever something in PowerShell doesn’t do what you expect, one of the first things to do is to run Get-Help -Full (or -Online) on the command that’s causing trouble. In your case, the problem command is Format-Table. If you check the OUTPUTS description for Format-Table, you will see that it produces [quote]OUTPUTS
Format-Table returns format objects that represent the table.[/quote]
This means that your $propID object doesn’t contain the properties that you are looking for, but instead has PowerShell internal format objects. What you really want to do is this]$propId = Get-MailboxDatabase -Identity $dbpath | Get-Mailbox | get-random | Get-NamedProperty
Format-Table $propID[/powershell]
by gte at 2013-01-14 07:19:17

Thanks for the reply. The code you provided is still giving me an error. I have Powershell 1 if that makes a difference.

I did do the get-help command as you suggested after Get-NamedProperty and I see the following

$propId = Get-MailboxDatabase -Identity $dbpath | Get-Mailbox | get-random | Get-NamedProperty <<<< get-help
+ CategoryInfo : InvalidArgument: (Lipscomb, Connie:PSObject) [Get-NamedProperty], ParameterBinding
+ FullyQualifiedErrorId : InputObjectNotBound,Microsoft.Exchange.Management.Powershell.Support.GetNamedPrope
by ArtB0514 at 2013-01-15 06:22:43
I assume that you are running the Exchange Management Shell. You might want to read the primer: You might also want to check out

Get-Help is not a property that you can feed into the -Identity parameter for Get-NamedProperty. Try it this way:

Get-Help Get-NamedProperty -Full
by gte at 2013-01-15 10:08:30
Ok, thank you