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,...

Removing Leading Zero from IP Addresses

Here is another (and very solid) approach to remove leading zeroes from an IP address using a regular expression: '010.012.000.101' -replace '\b0+\B' It looks for one or more "0" following a word boundary (\b) and not followed by a word...

Get Fully Qualified Domain Name

There are two simple tricks to find out your current fully qualified domain name (FQDN). You can either resort to ping.exe: PS> ping -a localhost Or, you can use .NET Framework and ask DNS: PS> [System.Net.DNS]::GetHostByName('').HostName  

Finding Next Sunday

If you'd like to find out how long it is until next Sunday (or how many days have passed since last Sunday), simply use the property DayOfWeek. It is a number telling you the current day of the week. So it's easy to calculate the difference between the current...

Launching Applications with Alternate Credentials

If you must run an application with a different identity, Start-Process offers the parameter -Credential. This would launch the Notepad editor using the context of user mydomain\myuser: Start-Process -FilePath notepad -Credential mydomain\myuser However, you may run...