PowerCLI

 View Only
  • 1.  Check if disks are 'Indipendent'

    Posted Nov 05, 2018 10:20 AM

    Hello, I would like to extract (csv file) some parameter about disks from a list of vm (txt),

    From this base:

    Get-VM |Select Name,VMHost | Where-Object {$_.name -like "*vm1*" } | Export-Csv -Path C:\Users\gemela\Desktop\vm_info.csv -NoTypeInformation -UseCulture

    I would like to get: Disk and info about Virtual Device Node, If there are setting to be Independent , Persistent or NonPersistent

    Thanks



  • 2.  RE: Check if disks are 'Indipendent'

    Posted Nov 05, 2018 05:08 PM

    Get-vm 'vm1' | get-harddisk

    that will give you the persistence property

    If you want to put more data together you will need to run a loop to gather the data you want and place it in your excel file.

    $vms = @('vm1','vm2')

    foreach($vm in $vms) {

         $hdproperty = (get-VM $vm | get-harddisk).persistence

         #add the excel code here

    }



  • 3.  RE: Check if disks are 'Indipendent'

    Posted Nov 06, 2018 09:52 AM

    You could do something like this

    Get-VM -Name (Import-Csv -Path C:\Users\gemela\Desktop\vm_info.csv -UseCulture).Name |

    Get-HardDisk |

    Select @{N='VM';E={$_.Parent.Name}},Name,Persistence,

       @{N='DeviceNode';E={

       $hd = $_

       $ctrl = $hd.Parent.Extensiondata.Config.Hardware.Device |

       where{$_.Key -eq $hd.ExtensionData.ControllerKey}

       "$($ctrl.BusNumber):$($_.ExtensionData.UnitNumber)"}}