添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

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.

Consolidating free space:

$free = (Get-Datastore -VM $vm | Select @{N="FreeSpace";E={[math]::Round(($_.FreeSpaceMB)*100/($_.CapacityMB),0)}})

Now checking if free space is available in each DS where VM connected:

foreach ($ds in $free.FreeSpace)
    if (($ds -gt 25)
get-vm $vm | new-snapshot -name "$cmr.$date" -Description $description
        

If I understand the question properly, regarding dealing with multiple datastores... I would take a look at introducing a Sort-Object after the initial Get-Datastore which is based on the FreeSpaceMB property, then only selecting the first datastore (which should have the least amount of free space available) and performing your calculation based on that.

Untested example: $free = (Get-Datastore -VM $vm | Sort-Object -Property FreeSpaceMB | Select-Object -Property @{N="FreeSpace";E={[math]::Round(($_.FreeSpaceMB)*100/($_.CapacityMB),0)}} -First 1)

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.

site design / logo © 2020 Stack Exchange Inc; user contributions licensed under cc by-sa 4.0 with attribution required. rev 2020.2.5.35980