VMware Cloud Community
MariusRoma
Expert
Expert

Return code from new-snapshot

My PowerCLI script includes the following statement:

get-vm $myvm | new-snapshot -name $mysnapshotname -Description $mydescription

It works fine, but I need to insert a test to see if the snapshot creation was successfull.

  • How can I get and test a returncode from new-snapshot?
  • How can I simulate an error in creating a snapshot in my lab environment in order to test my script?

Regards

marius

0 Kudos
1 Reply
LucD
Leadership
Leadership

As I already mentioned in the other thread, you can check the content of $error[0].

One way to test the New-Snapshot cmdlet is taking away the Privilege (via a customised Role) to create snapshots (from the account that you are using, preferably a test account)

Adding the -ErrorAction Stop will also help to test a Try-Catch construct.


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

0 Kudos