VMware Cloud Community
zsoltesz
Enthusiast
Enthusiast
Jump to solution

Content of a .vmdk desriptor file

Hi,

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

Thanks!

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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

View solution in original post

0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

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

0 Kudos
zsoltesz
Enthusiast
Enthusiast
Jump to solution

Thanks Lucd!  It works well!

Zoli

0 Kudos