PowerCLI

 View Only
  • 1.  get-vm | get-snapshot question...

    Posted Apr 18, 2012 06:54 PM

    I have the following line in a script

    $VMSnapshotReport = Get-VM | Get-Snapshot | Select-Object VM, Name, Description, Created, SizeMB | Out-String

    The output looks like ths:

    VM          : ThinAppWindows7

    Name        : After Prescan

    Description : After Prescan

    Created     : 3/6/2012 12:12:22 PM

    SizeMB      : 1881.3

    My question is simple: is there any way to add a "Select-Object" that will display the Datastore of the virtual machine?  Because after this line is another line that displays the datastore statistics (Get-VM | Get-Datastore).  The goal being, that large snapshots we can review the output file and make sure the datastore is suited to support keeping the snapshot around, etc.

    Thx



  • 2.  RE: get-vm | get-snapshot question...
    Best Answer

    Posted Apr 18, 2012 09:00 PM

    Try it like this

    $VMSnapshotReport = Get-VM | Get-Snapshot | 
    Select-Object VM, Name, Description, Created, SizeMB, 
    @{N="Datastore";E={[string]::Join(',',(Get-View $_.VM.DatastoreIdList | %{$_.Name})}} | Out-String 


  • 3.  RE: get-vm | get-snapshot question...

    Posted Apr 18, 2012 10:31 PM

    That worked flawlessly, thanks.

    Not sure I could have done it as good on my own.... :smileyhappy: