VMware Cloud Community
vmk2014
Expert
Expert
Jump to solution

Validate the Data store - No Running VM's

Hi All,

Can we validate before decommissioning or unmounting all VMFS 5.0  data store? We want to validate that no running or powered off VM's existing on the data store VMFS 5.0

We are migrating from VMFS 5.0 to VMFS 6.0 and there are tons of data store, hence want to avoid the manual check.

Thanks

vmk

Tags (1)
Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Just realised I had a typo, it should be FileSystemVersion instead of FileVersion.

The updated code

Get-Datastore -Name (Get-Content -Path C:\temp\datastore.txt) |

Where-Object {([version]$_.FileSystemVersion).Major -eq 5} |

ForEach-Object -Process {

  $vm = Get-VM -Datastore $_

  if($vm.Count -eq 0){

   Write-Host "No VMs on datastore $($_.Name) - Version $($_.FileVersion)"

  }

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

Reply
0 Kudos
19 Replies
LucD
Leadership
Leadership
Jump to solution

You could do something like this

$dsName = 'MyDS'

$vm = Get-VM -Datastore $dsName

if($vm.Count -eq 0){

   Write-Host "No VMs on datastore $dsName"

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
vmk2014
Expert
Expert
Jump to solution

LucD,

Can we pull at the cluster level instead of entering manually single data store at each time manually? we have around 1000 + DS.

thanks

vmk

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try like this

$clusterName = 'MyCluster'

Get-Cluster -Name $clusterName | Get-VMHost | Get-Datastore |

ForEach-Object -Process {

  $vm = Get-VM -Datastore $_

  if($vm.Count -eq 0){

   Write-Host "No VMs on datastore $dsName"

  }

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
vmk2014
Expert
Expert
Jump to solution

Will it include local Datastore also? I want local DS also

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Since we don't filter them out, yes, local datastores will be included.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
vmk2014
Expert
Expert
Jump to solution

LucD,

Can we include the data store name along with the output because in the cluster VMFS 6.0 data store also exists and want to make sure we are deleting or unmount right the data store?

If you see out don't show data store name. Example - No VMs on VPLEX_P2CX_UD1090

PS C:\Script> .\Datastore_validation.ps1

No VMs on datastore

No VMs on datastore

No VMs on datastore

No VMs on datastore

No VMs on datastore

No VMs on datastore

No VMs on datastore

No VMs on datastore

No VMs on datastore

No VMs on datastore

No VMs on datastore

No VMs on datastore

No VMs on datastore

No VMs on datastore

No VMs on datastore

No VMs on datastore

No VMs on datastore

No VMs on datastore

No VMs on datastore

No VMs on datastore

No VMs on datastore

VPLEX_P2CX_UD1090
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try like this

$clusterName = 'MyCluster'

Get-Cluster -Name $clusterName | Get-VMHost | Get-Datastore |

ForEach-Object -Process {

  $vm = Get-VM -Datastore $_

  if($vm.Count -gt 0){

   Write-Host "VMs on datastore $($_.Name)"

  }

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

And the reverse

$clusterName = 'MyCluster'

Get-Cluster -Name $clusterName | Get-VMHost | Get-Datastore |

ForEach-Object -Process {

  $vm = Get-VM -Datastore $_

  if($vm.Count -eq 0){

   Write-Host "No VMs on datastore $($_.Name)"

  }

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
vmk2014
Expert
Expert
Jump to solution

Oops it giving VM's on the Datastore VMFS6.0 but i'm looking No NM's on VMFS 5.0 then we can easily go ahead and delete or unmount it.

Reply
0 Kudos
vmk2014
Expert
Expert
Jump to solution

LucD,

reverse one is creating confusion. Want straight forward which we can go ahead and delete it post validation

Example - No VMs on the VPLEX_P1CX_UD1090  for   VMFS5.0

Reply
0 Kudos
vmk2014
Expert
Expert
Jump to solution

can we try this by giving data store name  C:\temp\datastore.txt ? and get the confirmation whether any VM's running or not?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Ok, try like this.

It only looks at datastores with version 5.*

Get-Datastore -Name (Get-Content -Path C:\temp\datastore.txt) |

Where-Object {([version]$_.FileVersion).Major -eq 5} |

ForEach-Object -Process {

  $vm = Get-VM -Datastore $_

  if($vm.Count -eq 0){

   Write-Host "No VMs on datastore $($_.Name) - Version $($_.FileVersion)"

  }

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
vmk2014
Expert
Expert
Jump to solution

Tried but no output

pastedImage_0.png

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Can you check if this returns anything?

Get-Datastore -Name (Get-Content -Path C:\temp\datastore.txt)

And then run

Get-Datastore -Name (Get-Content -Path C:\temp\datastore.txt) |

Select Name,FileVersion,@{N='V5';E={([version]$_.FileVersion).Major}}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
vmk2014
Expert
Expert
Jump to solution

Get-Datastore -Name (Get-Content -Path C:\temp\datastore.txt)  - Yes it returns datastore name and capacity and then the below output as shown in screenshot

pastedImage_0.png

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Just realised I had a typo, it should be FileSystemVersion instead of FileVersion.

The updated code

Get-Datastore -Name (Get-Content -Path C:\temp\datastore.txt) |

Where-Object {([version]$_.FileSystemVersion).Major -eq 5} |

ForEach-Object -Process {

  $vm = Get-VM -Datastore $_

  if($vm.Count -eq 0){

   Write-Host "No VMs on datastore $($_.Name) - Version $($_.FileVersion)"

  }

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
vmk2014
Expert
Expert
Jump to solution

LucD,

It works this time. Just want to confirm, will it possible to confirm any leftover vmdk file or templates in the data store. I saw there are no VM's running on the data store in VM tab in VC web client

but if you browse file then you might find some leftover vmdk or zombie file or templates ( templates want to migrate to another DS before  deleting DS

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

The Get-VM with the Datastore parameter will only return registered VMs (independent if they are powered on or not).

Unregistered VMs and orphaned VMDK files are not counted as VM.

You can run the same script for templates, just replace Get-VM with Get-Template.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
vmk2014
Expert
Expert
Jump to solution

Thank you LucD.

Reply
0 Kudos