Automation

 View Only
  • 1.  Find VMs which are missing .vmdk descriptor file

    Posted Sep 21, 2016 02:46 PM

    Hello

    In a environment where there are multiple VM's which are missing descriptor file and its very hard to find which hard disk vmdk file is missing.

    1. VM's are in powered on State.

    2. Need to find VM's whose harddisk doesn't consists of .vmdk file.

    My idea is to list all VM's and there harddisk with corresponding .vmdk file(descriptor file) . There we find the VM's with no vmdk file will show blank in csv file.

    I tried to execute below code but its trimming the harddisk file name and showing vmdk path.

    Can some one direct me on correct path please?

    foreach ($VM in (Get-VM 'log1' | Sort-Object -Property Name)) {

    foreach ($HardDisk in ($VM | Get-HardDisk | Sort-Object -Property Name)){

    $ds = Get-Datastore -Name $HardDisk.Filename.Split(']')[0].TrimStart('[')

    $vmdkPath = $HardDisk.Filename.Split(']')[1].TrimStart(' ')

    ""| select @{N="VM";E={$VM.Name}},

    @{N="Hard Disk";E={$HardDisk.Name}},

    @{N="Datastore";E={$ds.Name}},

    @{N="VMDKpath";E={$vmdkPath}},

    @{N="VMDK Size";E={($VM.extensiondata.layoutex.file|?{$_.name -contains $HardDisk.filename.replace(".","-flat.")}).size/1GB}},

    @{N="Drive Size";E={$HardDisk.CapacityGB}}

    }

    }



  • 2.  RE: Find VMs which are missing .vmdk descriptor file

    Posted Sep 21, 2016 04:05 PM

    Did you already try to list the files via the VimDatastore PSDrive?



  • 3.  RE: Find VMs which are missing .vmdk descriptor file

    Posted Sep 21, 2016 04:22 PM

    ‌no LucD. Can you please direct me to list the files using vimDatastore PSDrive.



  • 4.  RE: Find VMs which are missing .vmdk descriptor file

    Posted Sep 21, 2016 07:37 PM

    Sure, there is a sample script in 1.  Re: DataStore Folder & Size Details

    Hope that helps.



  • 5.  RE: Find VMs which are missing .vmdk descriptor file
    Best Answer

    Posted Sep 22, 2016 12:28 PM

    Thanks for your 'VMX Raiders Revisited' Script. With the help of that script I tried this variation and tested on single VM. It worked.

    Any modifications will be helpful for faster and accurate output.

    foreach ($VM in (Get-VM 'log1' | Sort-Object -Property Name)) {

    foreach ($HardDisk in ($VM | Get-HardDisk | Sort-Object -Property Name)){

    $ds = Get-Datastore -Name $HardDisk.Filename.Split(']')[0].TrimStart('[')

    $vmdkPath = $HardDisk.Filename.Split(']')[1].TrimStart(' ')

    $vmdkPathtrim =$vmdkPath.split('/')[1].trimstart('/')

    # Set up Search for .VMDK Files in Datastore

    New-PSDrive -Name TgtDS -Location $ds -PSProvider VimDatastore -Root '\' | Out-Null

    $vmdksearch = @(Get-ChildItem -Path TgtDS: -Recurse | `

    where {$_.FolderPath -notmatch ".snapshot" -and $_.Name -like "$vmdkPathtrim"})

    Remove-PSDrive -Name TgtDS

    ""| select @{N="VM";E={$VM.Name}},

    @{N="Hard Disk";E={$HardDisk.Name}},

    @{N="Datastore";E={$ds.Name}},

    @{N="VMDKpath";E={$vmdkPath}},

    @{N="VMDK Size";E={($VM.extensiondata.layoutex.file|?{$_.name -contains $HardDisk.filename.replace(".","-flat.")}).size/1GB}},

    @{N="Drive Size";E={$HardDisk.CapacityGB}},

    @{N="VMDK Exist In Datastore";E={$vmdksearch}}

    }

    }



  • 6.  RE: Find VMs which are missing .vmdk descriptor file

    Posted Sep 22, 2016 04:58 PM

    Using the VimDatastore provider is not the fastest process I'm afraid.
    Had a look at your script, but can't see major improvements.



  • 7.  RE: Find VMs which are missing .vmdk descriptor file

    Posted Sep 24, 2016 10:19 AM

    Thanks for your kind support Guru:smileyhappy:

    As of now I will use this code to fetch missing .vmdk details.