Month: January 2010

PowerShell 2.0 remoting guide: Part 3 – Enable remoting

I’ve published a free book on PowerShell 2.0 remoting. You can download it at: In this part of the series of articles on PowerShell 2.0 remoting, we will look at how to enable remoting in different scenarios. This post assumes that you are running a supported operating system and you have installed all necesary pre-requisite software. So, how do you enable remoting? Remoting in PowerShell 2.0 can be enabled by just running the following cmdlet Enable-PSRemoting Note: You have to run this at a elevated PowerShell prompt. Also, all your active networks should be set to “Home” or “Work” network location. Setting firewall exceptions for remoting will fail if the network location is set to “Public”. Yes. That is it. You will be asked to respond to a couple of questions — based on OS architecture — as you see in the screenshot here. Enable-PSRemoting As you see above, Enable-PSRemoting internally uses Set-WSManQuickConfig and a few other cmdlets. The second prompt around Microsoft.PowerShell32 will appear only on x64 OS. However, you should always use the more comprehensive Enable-PSRemoting cmdlet. If you don’t want to …

Programming CodePlex release web service in PowerShell

CodePlex provides a basic web service to add releases to an existing project. I wrote a quick module around using these web services to create releases and upload files to that release. This module itself is available as a CodePlex Project — PSCodePlex. You can download release 0.1 here. This module is a simple one. It has only two functions. Add-Release Add-Release function can be used to create a CodePlex release. The following list describes the input parameters to it. pName Project Name of your CodePlex project. This is a mandatory parameter. rName Release Name of the new release you are creating under the specified project. This is a mandatory paramter. rDescription Decription for the new release. This parameter is not mandatory. If not specified, rName will be used as description status Status of the new release. Possible values are “Planning”, “Alpha”, “Beta”, “Stable”. This is a mandatory parameter. IsPublic Specifies if you want to show this release to everyone or not. Possible values are $true, $false. This is a mandatory parameter IsDefault Specifies if this …

PowerShell 2.0 remoting guide: Part 2 – Overview of remoting cmdlets

I’ve published a free book on PowerShell 2.0 remoting. You can download it at: In part 1 of this series I gave a quick introduction to PowerShell 2.0 remoting. Before we look at how to enable or configure a computer for remoting, let us take a quick look at PowerShell 2.0 remoting cmdlets. Here is a complete list of cmdlets with a brief overview. This list will also include cmdlets that are not directly used within remoting but help configure various aspects of remoting. The knowledge of  these cmdlets such as WSMan, etc in this list is not mandatory for basic usage of PowerShell remoting. In this post, I will only discuss what each of these cmdlets are capable of and list any gotchas. A detailed usage of these cmdlets will be discussed later in the series. Enable-PSRemoting The Enable-PSRemoting cmdlet configures the computer to receive Windows PowerShell remote commands that are sent by using the WS-Management technology. This cmdlet will be the first one to run if you want to use PowerShell 2.0 remoting …

PowerShell 2.0 remoting guide: Part 1 – The basics

I’ve published a free book on PowerShell 2.0 remoting. You can download it at: I am starting a series of articles on remoting feature of PowerShell 2.0. This is one of the best features of PowerShell 2.0 and my favorite feature for sure. The number of very cool things one can achieve using this feature is just un-imaginable. I have started digging deep in to this feature as I start writing a network file browser powerpack as a part of hands-on. I hope it is worth sharing what I learn by writing about it here. So, this is the first in that series of posts. In this post, we will look at absolute basics to start using PowerShell remoting. What is PowerShell remoting? This is a new feature in PowerShell 2.0 that enables remote management of computers from a central location. Remoting uses WS-Management to invoke scripts and cmdlets on remote machine(s). This feature also enables what is known as “Universal Code Execution Model” in Windows PowerShell v2. UCEM means that whatever runs locally should run anywhere. PowerShell …

Get-DefaultBrowserPath from PowerShell prompt

Update: I removed the old content about using PowerShell to open a URL in the default browser. There is no need for a long script to do that. We could just do Start “URL” to open the default browser and open the specified URL. So, I updated this post to show a function that can get you the default browser’s exe path. Update: @ShayLevy suggested a one-liner @ http://twitter.com/ShayLevy/statuses/7945284388 and that one-liner is (New-Object -com Shell.Application).Open(http://www.microsoft.com). Nice..! I did not think about this. LL: Always look around for better ways 🙂 Update: The method I had posted earlier is meaningless since we can open a URL using start-Process or just start. Refer to the comments below. While experimenting with one of my PowerShell libraries, I thought it would be a good idea to be able to open a URL from a cmdlet or script or even command line. However, I did not want to hard code any browser details (path/image name/etc) in the script. The idea is to find out the default browser setting and then invoke …

Watermark images using PowerShell

We have been to a jungle resort over the weekend and took some good quality pictures. I wanted to watermark a few of them and then post it on a photo sharing site. Being a scripting fanatic and PowerShell lover, I wanted to see if I can achieve this using a PowerShell script. And, here is the result I used System.Drawing namespace to achieve this. You can download this script here After you dot-source the downloaded script, you can start watermarking images by running the following command Watermark-Image -Source “C:\Images” -Destination “C:\WaterMarkedImages” -text “All rights reserved” As you see in the above sample pictures, watermark text will be black color. You can modify the same by changing the following line in the script $color = [System.Drawing.Color]::FromArgb(153, 0, 0,0) The position of watermark will be the top-left corner. You can change that by specifying the pixel positions in the following line $gImg.DrawString($text,$font,$myBrush,0,100) Also, I am not taking care of output image format. It will always be JPEG. We can add that support as well by looking …

Generate a quick reference HTML table from Get-Command output

Get-Command cmdlet gets basic information about cmdlets and other elements of Windows PowerShell commands. One interesting property returned by this cmdlet is the link to online (TechNet) source which provides detailed documentation of the cmdlet. Wouldn’t it be nice if we have all the links from each cmdlet captured in to a simple HTML table? Here is a sample built on my system. This way, we can just click on the link related to any cmdlet and reach the online documentation easily. Let us see how we can achieve this. Get-Command | ConvertTo-Html Name, ResolvedCommand, helpuri, CommandType | Out-File C:\dell\testhelp.html ConvertTo-HTML can be used generate HTML content. However, this is not so well formatted. As you see here, there are no table borders and the HelpURI is not a clickable link. Let us quickly see how we can modify this further. Get-Command | % { $_ | Add-Member -name Url -memberType NoteProperty -value “<a target=_blank href=”$( $_.helpuri )“>$( $_.helpuri )</a>” } $htmlContent = $commands | Sort-Object -Property CommandType | ConvertTo-Html Name, ResolvedCommand, Url, CommandType -head $a [System.Web.HttpUtility]::HtmlDecode($htmlContent) …

Listen to Twitter messages using Speech API and PowerShell

First of all, Happy new year 2010 to all my blog readers..! Text-to-speech in PowerShell isn’t a new thing. I was experimenting a few things and came across this. Also, this post is a nice and fun way to start a brand new year while learning something at the same time. Let us dive in to this now.. Windows provides us access to Speech API for creating text-to-speech applications. This is a COM object and can pretty well be accessed using PowerShell. Twitter — as all you know — already provides a API to do various things. This post just combines both these aspects. First, let us create a web client object and assign twitter credentials $webClient = New-Object -ComObject System.Net.WebClient $webClient.Credentials = Get-Credential Now — if required, assign proxy credentials too for proxy authentication $webClient.Proxy.Credentials = Get-Credential It is time to setup the Twitter API to access your home timeline. This API usually returns 20 recent tweets. However, for the sake of this simple experiment, let us restrict the number of tweets to just one using the …