title: ESXi VM snapshot creation | PowerCLI
body: <p>I'm trying to automate snapshot checking DS free space. Its getting tricky for VMs with multiple DS attached. Script takes multiple snapshots for such VMs if condition satisfies. Please help me to understand where its going wrong.</p>
  
  <p>Consolidating free space:</p>
  
  <pre><code>$free = (Get-Datastore -VM $vm | Select @{N="FreeSpace";E={[math]::Round(($_.FreeSpaceMB)*100/($_.CapacityMB),0)}})
  </code></pre>
  
  <p>Now checking if free space is available in each DS where VM connected:</p>
  
  <pre><code>foreach ($ds in $free.FreeSpace)
  
  {
      if (($ds -gt 25)
  {
  get-vm $vm | new-snapshot -name "$cmr.$date" -Description $description
  }
  }
  </code></pre>