Windows PowerShell V2 Sessions and Debugging
- Posted: Apr 09, 2009 at 12:17 PM
- 4,891 Views
- 2 Comments
Download
How do I download the videos?
- To download, right click the file type you would like and pick “Save target as…” or “Save link as…”
Why should I download videos from Channel9?
- It's an easy way to save the videos you like locally.
- You can save the videos in order to watch them offline.
- If all you want is to hear the audio, you can download the MP3!
Which version should I choose?
- If you want to view the video on your PC, Xbox or Media Center, download the High Quality WMV file (this is the highest quality version we have available).
- If you'd like a lower bitrate version, to reduce the download time or cost, then choose the Medium Quality WMV file.
- If you have a Zune, WP7, iPhone, iPad, or iPod device, choose the low or medium MP4 file.
- If you just want to hear the audio of the video, choose the MP3 file.
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 Closed
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
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