Automation

 View Only
  • 1.  Content of a .vmdk desriptor file

    Posted Nov 09, 2011 09:46 AM

    Hi,

    is it possible to get the content of a .VMDK descriptor  file with PowerCLI?

    Thanks!



  • 2.  RE: Content of a .vmdk desriptor file
    Best Answer

    Posted Nov 09, 2011 06:35 PM

    If you allow the VMDK to be stored in your local %TEMP% folder, you can do something like this

    $vmName = "MyVM"
    $hdName = "Hard disk 1"
    $hd
    = Get-VM -Name $vmName | Get-HardDisk | where {$_.Name -eq $hdName} $ds = Get-Datastore -Name $hd.Filename.Split(']')[0].TrimStart('[') $vmdkPath = $hd.Filename.Split(']')[1].TrimStart(' ') New-PSDrive -Location $ds -Name ds -PSProvider VimDatastore -Root '\'

    $temp
    = (Get-ChildItem Env:TEMP).Value $source = ("ds:\" + $vmdkPath).Replace('/','\') $destination = $temp + '\' + $vmdkPath.Split('/')[-1] Copy-DatastoreItem -Item $source -Destination $destination Remove-PSDrive -Name ds -Confirm:$false
    Get-Content -Path $destination

    This sample script will just display the content on the console, but depending on why you need the VMDK file, you could read the file line by line and interprete the content.



  • 3.  RE: Content of a .vmdk desriptor file

    Posted Nov 09, 2011 08:33 PM

    Thanks Lucd!  It works well!

    Zoli