Windows PowerShell V2 Sessions and Debugging
- Posted: Apr 09, 2009 at 12:17 PM
- 5,141 Views
- 2 Comments
Loading User Information from Channel 9
Something went wrong getting user information from Channel 9
Loading User Information from MSDN
Something went wrong getting user information from MSDN
Loading Visual Studio Achievements
Something went wrong getting the Visual Studio Achievements
Right click “Save as…”
This video demonstration walks through the steps of creating and using sessions in Windows PowerShell v2. It also introduces the debugging functions such as working with breakpoints.
See additional information via
MSDN Code Gallery.
Demo:
The Universal Code Execution Model means that you can run your cmdlets, scripts, and functions in any session, locally or remotely. A Windows PowerShell session is actually a persistent connection to the computer using the Windows Remote Management (WinRM) service. Creating sessions is performed using the New-PSSession cmdlet.
First, display the current process ID using the $pid environment variable. Next, create a new session on the localhost using New-PSSession.
The Invoke-Command cmdlet will cause script to be invoked on the given session, and in this case will simply output the value of $pid, the process ID, on the given session. This is a quick way to verify that the session is truly a different process from the original state.
The Get-PSSession cmdlet will display any running sessions. This does not include your terminal window which is not managed as a connection. Without running New-PSSession, the Get-PSSession cmdlet will not return any objects.
Next, execute the Some-Functions.ps1 script file containing a simple Square-Root function. Once invoked, you can execute the functions in the session, but not in the local terminal. The Import-PSSession cmdlet, run next, imports the sqrtAdvance function so it can be used locally.
Finally, the Remove-PSSession cmdlet is invoked to destroy the session and its underlying connection. Calling Get-PSSession confirms that it is no longer active.
Next, the video covers debugging using the Integrated Scripting Environment (ISE). The Set-PSBreakpoint cmdlet allows you to declare a breakpoint on a line, variable, or command. In the video, the breakpoint is placed on the variable "s1" which is the session variable. A breakpoint also specifies AccessMode, by default, Write. As soon as anything attempts to modify the value of "s1" code execution will break.
The existing script for working with sessions is started and as soon as the New-PSSession cmdlet is run, the breakpoint takes effect. ISE has a Debug menu which supports creating and managing breakpoints, stepping through and resuming code, and evening showing the call stack. The video steps through the code and demonstrates these features.
Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation,
please create a new thread in our Forums,
or
Contact Us and let us know.
Follow the Discussion
Oops, something didn't work.
What does this mean?
Following an item on Channel 9 allows you to watch for new content and comments that you are interested in. You need to be signed in to Channel 9 to use this feature.What does this mean?
Following an item on Channel 9 allows you to watch for new content and comments that you are interested in and view them all on your notifications page.sign up for email notifications?
Just a head's up this needs to be re-edited... it contains the end of the PS V2 Functions video which is why its 13:29 long.
thanks Jonvate! Argh! I'll take care of that soon.
- phil
Remove this comment
Remove this thread
close