Powershell

Sorting Multiple Properties

Sort-Object can sort on multiple properties at the same time. Have a look: Get-Service | Sort-Object Status, Name This will list stopped services...

Discover Hidden Object Members

Get-Member is a great cmdlet to discover object members, but it will not show everything: "Hello" | Get-Member You should add -force to...

Adding Extra Information

Sometimes you may want to tag results returned by a cmdlet with some extra information, such as a reference to some PC name or a timestamp. You can...

Making Objects Read/Write

Whenever you pipe objects through Select-Object, you actually get a copy of the original object. All properties are now readable and writeable, so...

Creating Relative Dates

To create relative dates like "10 days ago," there are two paths. Administrators often add or remove time spans created by New-Timespan:...

Create Remoting Solutions

Whenever you use WMI (Get-WMIObject) to retrieve information, it's a snap to turn a local solution into a remotable solution. You can just add...

How Much RAM Do You Have?

Ever wondered what type of RAM your PC uses and if there is a bank available to add more? Ask WMI! This example also converts the cryptic type codes...

Accessing Object Properties

Objects store information in various properties. There are two approaches if you would like to get to the content of a given property. One is...

Changing File/Folder Creation Date

You should use this approach if you need to change the creation time of a folder or file after you have created it: Get-Childitem c:\testfolder |...

Changing Error Background Color

If you would like to make error messages more readable, you can change their background color from black to white:...

Removing Empty Things

How do you exclude objects based on empty properties? For example, WMI returns all kinds of "network adapters:" Get-WMIObject...

Filtering Day of Week

You can also use this little helper function if you run scripts every day and want to make sure they don't do anything on weekends: function...

Finding Object Types

When you pipe the result of a command to Get-Member, it examines the returned objects and shows the properties and methods. Use this line if you...

Built-in Methods

Strings contain all the methods you may need to access its content or manipulate it otherwise. Here is how you can list those methods: "Hello" |...

Stopping Programs Gracefully

While Stop-Process will stop a process immediately in PowerShell, it will also destroy all data that hasn't yet been saved. You can try a more...

Create HTML System Reports

ConvertTo-HTML is a great way of creating system reports because you can combine information gathered from different sources into one report. The...

Create HTML reports

ConvertTo-HTML will convert text information into simple HTML, which can then be saved to disk. These reports will work fine, even though they are...

Printing Results

You will discover that Out-Printer can print results to your default printer. You can also print to any other printer when you specify its name:...

Outputting Text Data to File

When you output results to text files, you will find that the same width restrictions apply that are active when you output into the console. You...

Examining Object Data

If you need to see all properties a result object provides, you should probably add Select-Object * to it like this: Get-Process -Id $pid |...

Multi-Column Lists

If you need to display a lot of information in as little room as possible, you should use Format-List with -Column: Get-Service | Format-Wide...

Create Groups (and Examine Alias groups)

Format-Table has a parameter called -GroupBy which creates groups based on the property you supply. For example, you can use this to examine aliases...

Getting IPv4 Addresses

You should use WMI to list all IPv4 addresses assigned to a computer: Get-WMIObject win32_NetworkAdapterConfiguration | Where-Object { $_.IPEnabled...

Automating Native Commands

You'll discover that some native commands require interactive keystrokes before they work. For example, to format a drive, for security reasons you...

Finding Update History

Whenever Windows installs an update via Windows Update, it will log this in its windowsupdate.log file. PowerShell can then parse this file. You...

Get Assigned IP Addresses

If you've ever wanted to know all IP addresses assigned to a machine, you should use WMI: Get-WMIObject win32_NetworkAdapterConfiguration |...

ExpandProperty rocks – sometimes

Select-Object will select the object properties that you want to see. So it removes all properties you did not specify, but it always returns an...

Creating Range of Letters

PowerShell can easily provide a range of numbers, but creating them is not that easy - unless you convert ascii codes into characters: 65..90 |...

Exclude Unwanted Registry Values

When you query the values of a registry key, PowerShell will add a bunch of artifacts to the results. You'll get some new properties that all...

Assignment Operators Can Get in Your Way

Have a look at this line – do you see what's wrong with it? Get-WMIObject Win32_UserAccount | Where-Object { $_.Name = 'Guest' } PowerShell will use...

1 89 90 91 92 93 104