Reader small image

You're reading from  Mastering PowerCLI

Product typeBook
Published inOct 2015
Reading LevelIntermediate
PublisherPackt
ISBN-139781785286858
Edition1st Edition
Languages
Right arrow
Author (1)
Sajal Debnath
Sajal Debnath
author image
Sajal Debnath

Sajal Debnath is a highly certified Cloud computing technocrat with more than 12 years of experience in virtualized data center design, Cloud computing, and BC/DR solutions. He is an EMCISA, VCAP-DCD/DCA, VCAP-CID/CIA, RHCE 4/5/6, RHCVA, Openstack, and ITIL certified person. He is presently associated with VMware Software India Pvt. Ltd. as a senior system engineer. Previously, he worked with France Telecom, Hewlett Packard, and many more in multiple roles. He is involved in prestigious Indian government projects, such as National Cloud, Digital Locker, and so on.
Read more about Sajal Debnath

Right arrow

Error handling in PowerShell


Before we go ahead and talk about how to handle errors or avoid them while writing scripts in PowerShell, let's speak about a few of the inherent features of advanced functions that can help end users. These are Write-Verbose, Write-Error, Write-Warning, and –Whatif. These are not typical error handling ways in PowerShell, but by using these in advanced functions, you can provide more ways to avoid errors in scripts.

Write-Verbose allows you to define more information for end users when they run the script/function/cmdlet with the –Verbose option. The same goes for the Write-Error and Write-Warning options. Defining –Whatif would allow end users to know what exactly the script will do if it is run normally. The following is a sample script showing all of these:

–WhatIf will only show the purpose of the script. If more than two VMnames are provided, then there will be an error message shown but not providing any VM name will result in an error. The following is...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Mastering PowerCLI
Published in: Oct 2015Publisher: PacktISBN-13: 9781785286858

Author (1)

author image
Sajal Debnath

Sajal Debnath is a highly certified Cloud computing technocrat with more than 12 years of experience in virtualized data center design, Cloud computing, and BC/DR solutions. He is an EMCISA, VCAP-DCD/DCA, VCAP-CID/CIA, RHCE 4/5/6, RHCVA, Openstack, and ITIL certified person. He is presently associated with VMware Software India Pvt. Ltd. as a senior system engineer. Previously, he worked with France Telecom, Hewlett Packard, and many more in multiple roles. He is involved in prestigious Indian government projects, such as National Cloud, Digital Locker, and so on.
Read more about Sajal Debnath