Powershell

Understanding the –f Operator

You may have come across the –f operator before and wondered what it does. It’s the format operator and provides an extremely easy way...

Creating Backup Copies of Many Files

PowerShell can quickly create backup files of your files. All you need to adjust is the type of files you want to backup, and the file extension you...

Piping Results Straight Into Office Word

With only a few lines of code you can implement a command called Out-OfficeWord. It takes the data you pipe into it and inserts them into a new Word...

Search WMI for Useful Information

WMI is a great source of information but it is not always easy to find out the names of valid WMI classes to query. Here is a little search tool: it...

Converting Date/Time Formats

Here is a simple PowerShell filter that can convert any DateTime object into any date/time-format you like: #requires -Version 1 filter...

Waiting for Process Launch

PowerShell has a built-in support to wait until a process or many processes end: simply use Wait-Process. There is no support to do the opposite:...

Finding Script Block Variables

Script blocks define a PowerShell code without executing it. The easiest way of defining script blocks is placing code into braces. Script blocks...

Getting Installed Software Remotely

In a previous tip we introduced the Get-Software function that was able to retrieve installed software from local computers. If you have enabled...

Reading Installed Software from Registry

Here is a very quick way of finding installed software. The Get-Software function reads both the 32- and 64-bit locations for software installed for...

Display Message Box Dialog

PowerShell is console-based, but sometimes it would be nice to add some simple dialogs. Here is a function called Show-MessageBox that can display...

Checking for AC Power

Ask WMI to find out whether your notebook is connected to AC: #requires -Version 1 $battery = Get-WmiObject -Class Win32_Battery | Select-Object...

Creating Enumerations

PowerShell 5.0 added the capabilities to define enumerations but in older PowerShell versions, you can create enumerations too, simply by compiling...

Crazy Prompt Function

The built-in "prompt" function is invoked whenever PowerShell completed interactive input, and you can use it to change the way your...

Conversation with PowerShell

Today's tip is using the programmable CommandNotFoundHandler to have PowerShell talk with you once you enter an unknown command:...

Finding Operating System Version

One of the easiest ways of getting your operating system version is this one line of code: PS> [Environment]::OSVersion Platform ServicePack...

Why Some Errors Aren't Caught

When you receive a red error message from PowerShell, you can always encapsulate the code in a try…catch block and handle the error yourself:...

Using Paths in Prompts

The default PowerShell prompt displays the current location. When you are deep inside nested folders, this steals room for your actual input, and...

Help Make PowerShell a Better Place!

Rather than ranting about things that don't work as expected, or things you feel are missing, be constructive! The PowerShell team takes great...

Try CTRL+SPACE!

In the PowerShell ISE, there are two key shortcuts that can help you. Pressing TAB works just like in the console, and each time you press TAB, you...

Adding Command Not Found Handler

Whenever PowerShell comes across a command name that it does not know, you see a red error message. However, starting with PowerShell 3.0, there is...

Auto-CaseCorrecting PowerShell Code

Often when you write PowerShell scripts, you may not have used the correct casing, used only partial parameter names, or used aliases instead of...

Finding Loaded Assemblies

To dump all .NET assemblies that are loaded in a PowerShell session, try this: System.AppDomain]::CurrentDomain.GetAssemblies() | Where-Object...

Finding Cmdlet Parameter Aliases

PowerShell cmdlets and functions can have parameters, and these parameters can have (shorter) alias names. One prominent example is the...

Simplify Parameter Attributes

If all of your systems run PowerShell 3.0 or better, you can start shortening function parameter attributes. Boolean attributes now all default to...

1 47 48 49 50 51 104