Finding Public IP Address

Whenever a machine is connected to the Internet, it gets a public IP address (typically assigned by the ISP), and this public IP address is not identical to your machine's IP address. In PowerShell 3.0, there is a new and extremely useful cmdlet called...

Creating a Drawing Panel

In PowerShell 3.0, WPF is a great (and easy) way of creating GUIs. If you have a touch-enabled machine, check out how easily you can open a drawing window from PowerShell: Add-Type -AssemblyName PresentationFramework Add-Type -AssemblyName PresentationCore Add-Type...

Changing Files without Changing Modification Date

Whenever you change a file, the file system automatically updates the LastWriteTime property. If you'd like to change a file without leaving such traces, try this: # make sure this file and folder exist!! $path = 'c:\temp\somefile.txt' $file = Get-Item...

Getting Holiday Dates

Ed Wilson from the Scripting Guys demonstrated how PowerShell can use free web services to find out holidays. You do need direct (non-proxy) Internet access for this to work. This is how you connect to the holiday web service: $URI =...

Replacing Aliases with Command Names

Aliases are shortcuts for commands and useful in interactive PowerShell. Once you write scripts, however, you should no longer use aliases and instead use the underlying commands directly. You can always use Get-Command to find out the underlying command for an alias:...

Identifying Origin of IP Address

Ever wondered how a website knew which country you are from? That's because there are IP address segments assigned to certain regions. And here's a web service that you can use from PowerShell to test and find out where a given IP address is located: $ip =...

Documenting CPU Load for Running Processes

Get-Process can easily return the CPU load for each running process, but this information by itself is not very useful: Get-Process | Select-Object -Property Name, CPU, Description (Note that if you run this code from an elevated PowerShell, you see information for...

Temporarily Locking the Screen

PowerShell 3.0 uses .NET Framework 4.x so it has WPF (Windows Presentation Foundation) capabilities built-in. This way, it only takes a few lines of code to generate GUI elements. Here's a sample function called Lock-Screen that places a transparent overlay window...

Renaming Script Variables

Often, when you start writing a PowerShell script, you use temporary (dirty) variable names that later you'd like to polish. Renaming script variables by find/replace is not a very good idea, though, because searching for text can find text inside of strings,...

Using Outlining to Make Scripts Easier to Read

ISE 3.0 features automatic outlining, so structures like braces can be collapsed or expanded by clicking the small "+" or "-" symbols next to them. To quickly collapse or expand all outline, press CTRL+M. Collapsing all outlines can be useful to...

SQLite, good enough for guided missle destroyers

SQLite is an Open Source embedded database that has become very popular over the years. Our support for SQLite has been limited because of the lack of demand from large enterprises, but that seems to have changed over the last year. The inclusion of SQLite in Android...

Auto-Documenting Script Variables

PowerShell can automatically find and list all variables that you use in a script. This way, you can easily create variable documentation for your scripts (and also find variables that may be misspelled): Function Get-ISEVariable { $text =...

Turning ISE into a Custom PowerShell Console

A lot of products come with their own PowerShell consoles. There are special PowerShell consoles for Exchange, for SQL Server, for Active Directory, you name it. In reality, all of these legacy PowerShell consoles are just plain vanilla PowerShell consoles that...

Using the ISE Debugger

ISE has a simple yet effective debugger built-in that you can use to step through your code. The debugger does require that you save your script first. Unsaved scripts cannot be debugged. To start, add breakpoints to your script by selecting the lines where you want...

Greenplum, PostgreSQL's Big Little Brother

The Greenplum database by EMC, is based on PostgreSQL, and has done a good job at keeping compatibility with PostgreSQL on the protocol layer and the system catalog level. For this reason, Greenplum bundles pgAdmin as the GUI client and also includes the PostgreSQL...

Switching Between Console and Editor

In ISE 3.0, you can easily switch focus between the interactive console pane and the editor script pane by pressing CTRL+D (to go to the console) and CTRL+I (to go to the script editor pane). Likewise, CTRL+R toggles the script pane altogether, so if you want to work...

Finding Matching Brackets

Sometimes, in larger PowerShell scripts it is hard to find the corresponding opening or closing bracket or brace. One thing you can do, of course, is to write clean code by aligning opening and closing brackets where possible. Another trick in ISE 3.0 is to place the...

Finding Built-In ISE Keyboard Shortcuts

Thanks to MVP Shay Levy from http://powershellmagazine.com fame, here's a quick way of dumping all ISE 3.0 keyboard shortcuts; a lot of them are undocumented: $gps = $psISE.GetType().Assembly $rm = New-Object System.Resources.ResourceManager GuiStrings,$gps $rs =...

Secret Script Block Parameters

If you think you understand PowerShell parameter binding, then have a look at this simple function which exposes a little-known PowerShell behavior: Function Test-Function { param ( [Parameter(ValueFromPipeline=$true)] [Int] $Number,...

Get-Member Receives Array Contents

  If you need to know the object nature of command results, you probably know that you can pipe them to Get-Member like this: Get-Process | Get-Member  A less know fact is that the pipeline always unpacks arrays, so Get-Member will always receive array contents,...