Month: March 2011

PowerShell ISE fun

Can you imagine how I could have got this output in PowerShell ISE? Any guess? @bielawb on twitter replied with the following code:

While this is technically the right way, this is not how I got the output you see here. The way I did: well, I just used PowerShell ISE object events. This post is just one of those funny ones. But, this post does show you how to use PowerShell ISE Object model. So, don’t get upset after you see the solution 😉 The trick here is to use the PowerShell ISE Object model and PowerShell ISE events. Here is the code:

This is it. Copy / Paste the above snippet to PowerShell ISE and run it. After that, just start typing at the PowerShell ISE console 🙂 Here is a video which shows this in action: httpvh://www.youtube.com/watch?v=ABrPOlLd3ks

PowerShell ISE Addon: Get-History GUI

Ok, that is a weird blog post title. I could not think of a better one for this post. Anyway, coming to the subject and as I mentioned earlier, I have several PowerShell ISE addons that I use on a regular basis. I kept writing them whenever I found the need. I have been polishing these addons for sharing here. So, here is another one in the ISE addons series. If you have used PowerShell console or even traditional console (cmd.exe), you might have used the F7 functionality of the console host. This, when used, displays a nice little pop-up menu with the command history. You can just scroll through the list and select an item to execute it again at the console. This will be very useful when you have very long command history and using arrows keys won’t really help. This is how that popup looks: However, this functionality is not available in PowerShell ISE. So, here is a simple addon that shows command history in a WinForms data grid and you can …

Coming soon: 2011 Scripting Games

The 2011 Scripting Games begin on April 4, 2011 and run through April 15, 2011. What is the Scripting Games, you may ask? Well simply put, the Scripting Games are the premier learning event of the year for IT Pro’s and others who wish to master Windows PowerShell. Comprising 10 events, a registered contestant has seven days to create a solution to a scenario driven problem and post their code to a MVP maintained script repository for evaluation by a panel of internationally recognized judges. Daily leaderboards and prize drawings help to maintain the suspense throughout the two-week international event. During the 2011 Scripting Games hundreds of contestants will submit thousands of scripts that will be reviewed by dozens of judges. Hundreds of thousands of spectators from all around the world will view the games themselves. Last year, participants from more than 100 countries participated in the Scripting Games. With an emphasis on real world scripting scenarios and problems, the scripts will be of immediate value to both the participants and to the spectators. Preparation …

Watch-Process: PowerShell to monitor local or remote process creation or deletion

After answering this question on StackOverflow, I started writing a simple function, for my own use, to monitor remote process creation or termination. I do lot of SharePoint installs on remote machines in my lab environment. This involves installing prerequisite software and SharePoint 2010 bits. I need a way to wait for the remote process to terminate and then do something based on the exit code of the process. This function is very useful to me. I don’t have to worry about event registrations every time I want to monitor a remote process. For the sake of sharing with others, I added monitoring of remote process creation also. If you think you can do this using Wait-Process, go head and explore it yourself. So, here it is: PoshCode: http://poshcode.org/2560 Update1: removed if ($computerName -eq “.”) check. Thanks to @cjwarwickps for the quick feedback. Update2: This results in a blocking call. This means, if you embed a call to Watch-Process in your script, your script just waits for this to complete before proceeding. I have not …

TechED India 2011: PowerShell in the enterprise – Best practices for adopting PowerShell as the automation platform

I will be speaking at TechED India 2011 this year. My session title is “PowerShell in the enterprise – Best practices for adopting PowerShell as the automation platform“. I got the inspiration for this session’s content from @jeffhicks’s whitepaper on PowerShell best practices for enterprise adoption. Here is the session abstract: PowerShell is slowly gaining ground as the automation platform within the enterprise data centers. It is not a “Microsoft Windows only” management interface anymore as several products such as VMWare ESX and RedHat Enterprise Virtualization are now supporting Windows PowerShell interfaces. There are also companies such as Intel, Dell and NetApp developing PowerShell interfaces for managing hardware. This session intends to cover the best practices and recommendations for adopting Windows PowerShell as the data center automation platform. In this session, you will learn about the security considerations, version control for the scripts, leveraging PowerShell community, and several tools for creating and sharing PowerShell scripts. This session is on 23rd, March at 2PM. If you are at the event and if you are interested in PowerShell as the …

PowerGUI Script Editor Addon: Custom menu item generator

PowerGUI Script Editor & PowerShell ISE support better extensibility. These two editors remain to be my script editors. So, I tend to port all my PowerShell ISE customizations to PGSE if such a feature isn’t available in PowerGUI. One such ISE customization I recently did was to enable custom menu item generation using GUI. You can read more about it here. While it is very easy to create addon menu items in ISE, PGSE isn’t that straight forward. So, I thought that this ISE customization should be ported to PowerGUI script Editor as well. So, here it is. You can download this addon from PowerGUI.org at http://powergui.org/entry.jspa?externalID=3311&categoryID=387 This is how the UI looks: The UI is pretty self-explanatory. In the options, “Menu Text”, “Menu Shortcut”, and “Script Block” are mandatory. At present, you can add only menu items under existing top-level menus. You won’t be able to add a top-level menu such as File or Edit. See To Do. Also, the code isn’t completely optimized. So, there is a very good chance that you will …