When you handle errors, you may sometimes want to replace the original exception with your own. Here is a sample: function Do-Something { # function...
ps1
Launching Applications as Someone Else
Let’s assume you would like to open multiple PowerShell consoles running under different identities – or launch whatever application you...
Shed Light into the PowerShell Version Jungle
Meanwhile, there are five major versions of PowerShell around. Toss in the new minor versions such as PowerShell 5.1 on Windows 10 and Server 2016....
Fixing PowerShell 5 Help Bug
When you download PowerShell help via Update-Help, there was a bug in PowerShell 5 that might be fixed by now: text-based help files had the...
Prohibiting Positional Parameters
When you create PowerShell functions, parameters can be named or positional. Here is an example: If you’d like to detect illegal characters in...
Using Named Parameters in PowerShell Functions
When you create a PowerShell function, all parameters are positional until you start adding the “Position” attribute. Once you start to...
Launching PowerShell Hidden
Sometimes a PowerShell script should just produce something, for example a report, which then opens in Excel or notepad. You don’t want to...
Time Zone Management in PowerShell 5.1
PowerShell 5.1 (available on Windows 10 and Server 2016) comes with some new cmdlets to manage computer time zones. Get-TimeZone returns the current...
Exploring Function Source Code
The only fundamental difference between cmdlets and functions in PowerShell is the way how they are programmed: functions use plain PowerShell code,...
Running 32-bit Code on the Same Machine
If you need to run 32-bit PowerShell code from within a 64-bit script, and provided you are Administrator and use remoting, you can remote against...
Modern Replacement for systeminfo.exe
For ages, systeminfo.exe returned all profiling information for a computer, and could made object-oriented in Powershell – somewhat: PS...
Built-In Support for Local Accounts
Beginning in PowerShell 5.1, there is finally built-in support for local user accounts. PowerShell 5.1 is currently available with Windows 10 and...
Careful with Add-Member!
Frequently, Add-Member is used to create custom objects, for example like this: $o = New-Object -TypeName PSObject $o | Add-Member -MemberType...
How PSCustomObject Really Works
In a previous tip we explained how PSCustomObject can create new objects really fast: $o = [PSCustomObject]@{ Date = Get-Date BIOS = Get-WmiObject...
Fast Approach to Creating New Objects
To wrap up multiple pieces of information, you best store them in custom objects. The easiest and fastest way is to use the PSCustomObject:...
Exploiting Your Command History
PowerShell “records” all your interactive command input to its command history, and Get-History shows them. If you played around with...
Getting Latest PowerShell Gallery Module Version
On www.powershellgallery.com, Microsoft hosts a public script and module repository where you can exchange PowerShell code with others (see more on...
Testing Files and Folders (separately)
Test-Path is highly useful to test whether a file or folder exists, and it can be used with any of the PowerShell drives, so it can also test...
Getting Help for Cmdlet Parameters
There seems to be a bug in PowerShell 5.0 that limits the usefulness of the built-in help window. Whenever you run Get-Help with -ShowWindow, the...
Updating PowerShell Help with One-Liner
To get the most out of PowerShell, you should at least update PowerShell help once. This downloads and installs the base set of help files that show...
Getting IntelliSense for Cmdlet (PowerShell ISE)
If you’re reviewing some PowerShell code loaded into the PowerShell ISE, it’s really simple to get additional information. Click the...
Downloading Pictures from Website
There are awesome websites out there, and one is www.metabene.de (at least for German visitors)-- on 33 pages, the artist presents his drawings for...
Simple Strategy for Cmdlet Error Reporting
In PowerShell, you can create complex error handlers but sometimes you might just want to know what went wrong so you can log it. No overkill...
Check File Names for Illegal Characters
File names are quite sensitive and may not contain a number of reserved characters. To validate file names and make sure they are legal, here is a...