locked
Multiple line variable output shown on one line RRS feed

  • Question

  • I am writing a script that pulls various information from VM's in Hyper-V Clusters.

    One thing I am doing is the following:

    $VMHDD = Get-VMHardDiskDrive -VMName $Using:VM.Name

    Which I then write-host using:

    "HDD Path: " + $VMHDD.Path

    Problem is it shows multiple paths on a single line, instead of multiple lines.
    I can't figure out why, and hope someone can explain if it can be done, and if so, how.

    I have the same thing for VMs with multiple network adapters and VLAN IDs.

    Thursday, March 15, 2018 4:09 PM

All replies

  • What would expect? You are concatenating a string with an array and Powershell does the magic for you. If you like to have it multiple strings you'll  need a loop.

    Like this:

    Foreach($path in $VMHDD.path){
        "HDD Path: " + $path
    }


    Best regards,

    (79,108,97,102|%{[char]$_})-join''



    • Edited by BOfH-666 Thursday, March 15, 2018 4:23 PM
    • Proposed as answer by I.T Delinquent Thursday, March 15, 2018 4:33 PM
    Thursday, March 15, 2018 4:20 PM
  • We figured it out that the following works. Thanks for the tip.

    foreach ($hddpath in $VMHDD.Path) {
                        Write-Host "HDD Path: " $hddpath
                        }

    Thursday, March 15, 2018 4:28 PM
  • Great. We're proud of you.  ;-)

    Best regards,

    (79,108,97,102|%{[char]$_})-join''

    Thursday, March 15, 2018 4:33 PM