Hi,
is it possible to get the content of a .VMDK descriptor file with PowerCLI?
Thanks!
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.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks Lucd! It works well!
Zoli