Sysadmins shortcuts

Sysadmins shortcuts

Debugging PowerShell

PowershellPosted by Thomas Petersen Mon, February 18, 2013 16:03:35
Ok, first entry smiley

When working with powershell, one of the first things you will need is to debug your script.

There is actually functionality for this build in right out of the box.

A very basic way of making this work could be like the following:

# Add the two lines, for basic debugging functionality

[CmdletBinding()]

param ($param)

# Ok, this is what is needed.

# When you run your script, you can add various debugging parameters, that make the following write snippets fire :

write-output "This is standard output"

write-debug "Debug mode enabled"

write-verbose "Verbose output enabled"

write-output "all done"

So to enable debug-mode, run your script with -debug as parameter, or you could use -verbose for, well, verbose output.

More powershell related stuff to be online shortly. Currently I am working on a setup to automate patching of .wim files for Windows installation.

  • Comments(0)//www.ttp.dk/#post0