To create multi-line text in a script, you can simply enter the multi-line text into your script using quotes: $text = 'First Line Second Line...
powertips
Identifying .NET Framework 4.5
PowerShell 3.0 can run both on .NET Framework 4.0 and 4.5. .NET Framework 4.5 adds additional objects and members, so for example this line will...
Testing Numbers and Date
With a bit of creativity (and the help from the -as operator), you can create powerful test functions. These two test for valid numbers and valid...
Get List of Type Accelerators
Ever wondered what the difference between [Int], [Int32], and [System.Int32] is? They all are data types, and the first two are type accelerators,...
Getting Help for Objects – Online
In PowerShell 3.0, you finally can extend object types dynamically without having to write and import ps1xml-files. Here is an especially useful...
Listing Currently Loaded Format Files
The internal PowerShell formatting system (called ETS) relies on XML-based formatting data that comes from .ps1xml files. To see all files currently...
Renaming Object Properties in Powershell
Let's say you want to output just your top-level processes like this: PS> Get-Process | Where-Object { $_.MainWindowTitle } | Select-Object...
Examine "Extended" Object Members
PowerShell is based on .NET objects but often refines them by adding more. If you'd like to see just what PowerShell has added, use Get-Member...
Writing Back WMI Property Changes
Only a few properties in WMI objects are actually writeable although Get-Member insists they are all "Get/Set": PS> Get-WmiObject...
Errors Travel in the Opposite Direction
Here's a piece of code for you to wrap your head around: 1..10 | ForEach-Object { trap { Write-Host "Phew: $_"
Creating Dynamic Breakpoints
The PowerShell 3.0 ISE editor has a simple debugger built-in that supports line breakpoints. Simply press F9 to set a breakpoint (which only works...
Creating "Mini-Modules"
Did you know that every PowerShell function can be turned into a script module with just one line of code? To test drive this, open the ISE editor...
Ripping All Links from a Website
PowerShell 3.0 comes with a great new cmdlet: Invoke-WebRequest! You can use it for a zillion things, but it can also simply retrieve the content of...
Splitting Hexadecimal Pairs
If you'd have to process a long list of encoded information, let's say a list of hexadecimal values, how would you split the list into pairs...
Splitting Texts without Losing Anything
Typically when you split a text using the -split operator or the Split() method, the split character is removed from the text: $profile -split...
Cutting Off Text at the End
Cutting off a part of a text at its beginning is easy. This line eats the first 3 characters: PS> 'C:\folder\file.txt'.SubString(3)...
Use Comparison Operators for Logfile Parsing
Comparison operators usually return either $true or $false, but when applied to an array, return the array elements that match the comparison. You...
Use -f with N0
Often, it is necessary to output numbers, but you may want to control the number of digits and would like to control the formatting. The -f operator...
Sending Results to Excel
Here's a little function called Out-ExcelReport. Just pipe anything to it, and it will open in Microsoft Excel - provided it is installed on...
Colors Become Even More Important in the New ISE Editor
When you type in code into the new PowerShell 3.0 ISE editor, your code is not just "colorful". You may know that each color stands for a specific...
Controlling Process Priority and Processor Affinity
When you get yourself a process using Get-Process, what you get back is an object that has useful methods and writeable properties. This line will...
Executing Elevated PowerShell Code
Sometimes, a script may want to execute some portion of its code elevated, for example to write to HKLM in the Registry or change protected...
Examine Parameter Binding
PowerShell caters all tastes which is why the next two lines do the exact same thing and get all JPG pictures from your Windows folder: PS>...
Show-Command Creates PowerShell-Code for You
In PowerShell 3.0, there is a cool new cmdlet called Show-Command: PS> Show-Command Get-Process It works both in the console and the ISE editor,...