Powershell version of On Error Resume next…..Maybe

I’m sure powershell people will correct me, but coming from a VBScript background, ON ERROR RESUME NEXT had it’s uses. I worked on a script and needed to execute a command even though an error might happen.  I needed a quick a dirty execution statement, I found trap [Exception] {continue} did exactly what I needed.   I thought I would pass this along for VBScripters who have converted to Powershell

‘Read in a text file which contains a list of computers
$ComputerList = Get-Content(“c:computerlist.txt”)

‘Loop through the computer list executing the command
foreach($item in $ComputerList)


//Write out the host to keep track of the status
 Write-Host $item

//Continue the script even if an error happens
 trap [Exception] {continue}

//Add a domain group to the local Administrators group

PS:MoW, if you are reading this, feel free to correct me. 🙂  

PSS:This is for Powershell 1.0, I’ve not tested error handling in Powershell 2.0


Steve Schofield

One thought on “Powershell version of On Error Resume next…..Maybe”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: