VSphere CLI: how do I take a new Snapshot and add description?
-
19-06-2021 - |
Question
I'm working on a VSphere CLI script that will take 6 snapshots and allow me to make the description of each snapshot be the date it was created. At the moment here's the code that I'm trying:
$server = "<ServerName>"
connect-VIserver $server
$snapshot = Get-vm | New-Snapshot -Name $"<serverName>" | Set-Snapshot -$snapshot -Description get-date
Solution
You can do this in one call
Get-VM | New-Snapshot -Name "$serverName" -Description (Get-Date)
I'm not sure why you want to do this as, the snapshot object has a property called "Created" You can get it by doing something like this:
$snapshots = Get-VM | New-Snapshot -Name "$serverName"
$snapshots | foreach { Set-Snapshot -Description $_.Created }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow