Powershell

Catching Errors in Native EXEs (Part 1)

All Versions When you run native console EXE commands such as robocopy.exe, ipconfig.exe, or similar commands, you can handle errors raised by these...

Using WMI Inheritance

All Versions WMI classes are inherited from each other, and that’s something you can take advantage of. Take this line: PS> Get-WmiObject...

Finding Process Owners

All PowerShell versions To find out who owns a particular process and how many instances are running, try this simple piece of code: $ProcessName =...

Parsing DISM Log File

PowerShell 2.0 and later In your Windows folder, you find all kinds of system log files. One is DISM.log which contains information about the...

Setting Active Directory Attributes

ActiveDirectory Module To set AD attributes for a user account, PowerShell uses hash tables. That’s a versatile approach that lets you specify...

Removing AD Group Members

Module ActiveDirectory To remove one or many users from an Active Directory group, try this approach: $user = @() $user += Get-ADUser -Filter { Name...

Steps to Configure PowerShell (Part 3)

All PowerShell versions If you use PowerShell at home or in an environment without central group policy management, here are some additional steps...

Steps to Configure PowerShell (Part 2)

PowerShell 2.0 and later If you use PowerShell at home or in an unmanaged environment, here are some additional steps you should consider to make...

Steps to Configure PowerShell (Part 1)

PowerShell 2.0 and later If you use PowerShell at home or in an unmanaged environment, here are some steps you should consider to make PowerShell...

NULL Values in Arrays

All PowerShell versions Whenever you assign NULL values to array elements, they will count as array elements, but will not be output (after all,...

Randomize Lists of Numbers

All PowerShell versions This line will take a list of numbers and randomize their order: Get-Random -InputObject 1, 2, 3, 5, 8, 13 -Count...

Reading Disks and Partitions

Windows 8.1 / Server 2012 R2 Disk management has been greatly simplified with the many new client and server cmdlets that ship with Windows 8.1 and...

Finding Out Windows Version

All PowerShell Versions Do you own Windows 8.1 Basic, Pro, or Enterprise? Finding out the Windows version is easy. Finding out the exact subtype is...

Join-Path Fails with Nonexistent Drives

All Versions To construct path names from parent folders and files, you may have been using Join-Path. This cmdlet takes care of the correct number...

Looking Up Cryptic Error Codes

All PowerShell versions Often, WMI and API calls return cryptic numeric error codes. To find out what went wrong, try this little helper function:...

Converting Error Numbers

All PowerShell Versions Error numbers that are returned by Windows API calls often appear as very large negative numbers. To give meaning to these...

Creating HTML Colors

All Versions To convert decimal color values to a hexadecimal representation, like the one used in HTML, try this line: PS>...

Getting Help

PowerShell 3.0 and later Provided you have downloaded PowerShell help via Update-Help, you can create yourself an excellent help topic viewer with...

Break Into Script with PowerShell 5.0

PowerShell 5.0 Preview As you might know, PowerShell 5.0 Preview is available and comes with vast debugging improvements. One is to be able to debug...

Watch Rick Astley Dance and Sing!

All PowerShell Consoles (not PowerShell ISE) Before you try this, you may want to click the icon in the upper left corner of the PowerShell title...

Changing PowerShell Priority

All PowerShell versions Maybe you’d like a PowerShell script to work in the background, for example copy some files, but you do not want the...

Reading System Logs from File

All PowerShell Versions Sometimes, you may have to evaluate system log files that have been exported to disk, or you want to read a system log file...

WMI Search Tool

All PowerShell Versions WMI is a great and powerful technique: simply specify a WMI class name, and back you get all the instances of that class:...

List All Information

All PowerShell Versions Most of the time, PowerShell will not show you the complete results that you get from cmdlets. Instead, PowerShell limits...

Getting US ZIP Codes

All PowerShell Versions Ever wanted to find out the ZIP code of a city, or vice versa find out the city that belongs to a ZIP code? Then simply ask...

Reading Registry Values with Type

All PowerShell Versions Reading all registry values is simple when you do not need the data type: simply use Get-ItemProperty: Get-ItemProperty...

Finding Files plus Errors

All PowerShell Versions When you use Get-ChildItem to recursively search directory paths for files, you may stumble across subfolders where you do...

1 55 56 57 58 59 104