Simple question, but cant seem to figure it working with the -join function. Im looking to join results from a powershell command using a single command (not outputting to a variable and then calling both variables), separated by a hyphen with no extra spaces. For example,
Get-BitLockerVolume | select MountPoint,VolumeStatus,EncryptionMethod | ft -HideTableHeaders
to get the output into the format you would like we just make a new string by calling these named properties from the output of the command i saved as the
Format-Table (ft) is almost always going to break things when exporting because you are changing it from an object to a a formatted string. In short, Format-Table breaks the pipeline.
You are taking stored in a table (PSObject) and trying to join the items into a string. The individual elements need to referenced in some manner. You would do the same thing in Excel for CONCAT referencing cells to join into a string.
[quote quote=133533]Ah, makes perfect sense. What if if i use “Out-String” – something like the command below. Would that still be considered an object?
Yes it would because everything is an object in powershell, and a String is simply a type of object.
While piping the commands to a Format-Table (ft) and converting the result to a string works for you now, you cant be sure it will always give you the output you want. Rob is absolutley correct about Format-Table, the only time i ever use it is when im trying to make sure an array contains the data i want.
Keeping the result as an object and then buiding a string around referencing that object is a lot easier to troubleshoot and gives you a lot of flexibility if you want to do something more that just output that data into a text file.
Just out of curiosity is this part of a larger script?
Or are you just building out a text report of machines in your environment?