none
Powershell help with formatting a string RRS feed

  • Question

  • Hi,

    I've had a total blank and can't figure out how to get this to work, any help appreciated...

    I've got a PS script which adds storage into SCVMM. 

    One of the commands needs to present the base disks in a specific format...example command like this.

    Set-SCVMHost -VMHost $clusterNode -BaseDiskPaths "\\LAB01-SOFS\CLU-LAB01-SOFS_LUN5_CSV3|\\lab01-sofs\CLU-LAB01-SOFS_LUN3_CSV2" -RunAsynchronously

    The way the script is run is to automate most the processes, so i am first running 

    Get-SCVMHost -VMHostCluster $hostcluster | foreach {
                $vmHostName = $_.Name
                $hostID = $_.ID
                $currentbaseDisks = $_.BaseDiskPaths

    The above gets all the disks and variables i need to pass to the Set-SCVMHost command as above. 

    What i am struggling with is the formating of the BaseDiskPath to be a straight line seperated by | between each disk. 

    So everytime the script runs, the BaseDiskPaths uses the existing disk and then adds the next disk to it.

    Hope i've made sense.

    Thanks

    Denis


    Regards,

    Denis Cooper

    MCITP EA - MCT

    Help keep the forums tidy, if this has helped please mark it as an answer

    Blog: http://www.windows-support.co.uk  Twitter:   LinkedIn:

    Thursday, May 26, 2016 12:07 PM

Answers

  • Hi Denis,

    I'm not exactly clear on what you're trying to accomplish, but if you need to join members of an array together you can use -join like so:

    $disks = 'Disk 1','Disk 2','Disk 3'
    
    $baseDiskPaths = $disks -join '|'
    
    $baseDiskPaths


    • Marked as answer by Denis Cooper Friday, May 27, 2016 7:22 AM
    Thursday, May 26, 2016 12:20 PM

All replies

  • Hi Denis,

    I'm not exactly clear on what you're trying to accomplish, but if you need to join members of an array together you can use -join like so:

    $disks = 'Disk 1','Disk 2','Disk 3'
    
    $baseDiskPaths = $disks -join '|'
    
    $baseDiskPaths


    • Marked as answer by Denis Cooper Friday, May 27, 2016 7:22 AM
    Thursday, May 26, 2016 12:20 PM
  • actually that should work....

    will give it a go

    thanks


    Regards,

    Denis Cooper

    MCITP EA - MCT

    Help keep the forums tidy, if this has helped please mark it as an answer

    Blog: http://www.windows-support.co.uk  Twitter:   LinkedIn:

    Thursday, May 26, 2016 12:57 PM
  • Cheers, you're welcome.

    Thursday, May 26, 2016 1:01 PM