7 Replies Latest reply on Nov 26, 2019 1:25 AM by MarkusLandertinger2

    Script to check if VMs run on correct Datastore(Cluster) / Checking VM Datastore Cluster Relationship

    MarkusLandertinger2 Lurker
    VMware Employees

      Dear All,

      I am looking for a Script that checks if VM's are running on the correct Datastore.Architecture:


      • 1 VCSA
      • 2 Hosts, each on 1 Site
      • 2 Storage Arrays, each on 1 Site




      So the Requirement is, that 'VM' has to reside on the Datastorecluster of it's 'Home Site'.

      No automation needed so far, just a Script that:


      - Lists all VM's with the Datastore Cluster on which it's VMDK's are residing in (Datastorename would be sufficient too I guess)

      - Writes the List out to a CSV File

      - In an ideal World: Adds a * (Star) or some mark to identify the Lines where the placing doesn't match for easy identifying.


      What I got so far:



      $vcenter = “VCENTER FQDN”
      $clustername = “TARGET CLUSTER NAME”
      if ($global:DefaultVIServer){
            Write-Host “1. Terminating existing vCenter Connections...” -ForeGroundColor Red
            Disconnect-ViServer -Server * -Confirm:$False -Force}
            Write-Host “2. Connecting to vCenter: [$vcenter]” -ForegroundColor Yellow
            $connection = Connect-VIServer $vcenter
            if($connection.isconnected -eq “true”){
            Write-Host “Connection to [$vcenter] successfully established” -ForegroundColor Green
                Sleep 2}
            {Write-Host “Error while connecting to vCenter Server! Please check your credentials and target IP/FQDN” -ForegroundColor Red
            Sleep 5
      Write-Host “3. Writing out the Data...” -ForegroundColor Green
      Export-Csv C:\vm-datastore-report.csv -NoTypeInformation -UseCulture


      So what I'm struggling with:


      - Listing all VM's of Host1 and the DS Cluster of it's VMDK's.

      - Listing all VM's of Host2 and the DS Cluster of it's VMDK's

      - Marking any Line which voids that 1:1 relation with some Charakter


      BTW: Do you have suggestions for a good GUI Powershell Editor? I know there are some Editors where you can put together such Commands like I need, but I don't know which ones are recommended, since I just get deeper into the Scripting Story.


      Thanks in advance for your help,

      Kind regards,