Automation

 View Only
  • 1.  powercli set hard disk mode

    Posted Jul 21, 2010 02:06 AM

    Hi

    Does anyone know how to change the mode of a specific virtual disk?

    The desktop I'm workign on has two virtual disks and I only want to change the first disk...

    If I use..

    Get-Harddisk -vm STU-NP-P1-2 | Set-harddisk -Persistence "IndependentNonPersistent"

    the command works but changes all the disks to "IndependentNonPersistent"

    How do I do this for a specific disk?

    Thanks



  • 2.  RE: powercli set hard disk mode
    Best Answer

    Posted Jul 21, 2010 05:28 AM

    Try something like this

    Get-HardDisk -VM STU-NP-P1-2 | where {$_.Name -eq "Hard disk 1"} | Set-harddisk -Persistence "IndependentNonPersistent"
    

    ____________

    Blog: LucD notes

    Twitter: lucd22



  • 3.  RE: powercli set hard disk mode

    Posted Jul 21, 2010 09:03 PM

    Thanks for your answer, it works great, would you mind explaining what the "$_.Name" part does? I dont quite understand how it works....

    Thanks



  • 4.  RE: powercli set hard disk mode

    Posted Jul 22, 2010 05:22 AM

    Sure, the Get-HardDisk cmdlet returns one or more objects and places these objects in the pipeline (the '|' operator).

    The next cmdlet, the Where-Object cmdlet, receives the objects one-by-one.

    The object is available to the Where-Object cmdlet as the $_ variable.

    Objects have properties, in other words values, associated with them.

    To retrieve a value for a specific property one uses the dot-notation.

    In this case $_.Name means the Name property of the object that arrived through the pipe.

    ____________

    Blog: LucD notes

    Twitter: lucd22