VMware Cloud Community
ppeters
Contributor
Contributor
Jump to solution

Rookie Question: Checking return status from an operation

I'm doing my first powershell scripting for vmware and I'm wondering how to check the return status from an operation. Most of the examples just assume that everything works as planned Smiley Wink

In particular, I'm using the new-snapshot and remove-snapshot operations.

If someone can give me a pointer to the right place in some documentation, I'll be happy to take it from there.

Thanks!

Pat

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

First of all you can examine the $? and the $error variable.

See Tobias's chapter on handling PS errors here.

In fact the complete series is ideal for new and intermediate PS users. Smiley Wink

In PS you can also use trap to capture errors and display/return error messages and return codes.

Yasen gave a very good explanation on the use of trap and the VITK in .


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

View solution in original post

0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

First of all you can examine the $? and the $error variable.

See Tobias's chapter on handling PS errors here.

In fact the complete series is ideal for new and intermediate PS users. Smiley Wink

In PS you can also use trap to capture errors and display/return error messages and return codes.

Yasen gave a very good explanation on the use of trap and the VITK in .


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

0 Kudos
ppeters
Contributor
Contributor
Jump to solution

Thanks for the pointer. This will get me going.

0 Kudos