If you would like to make error messages more readable, you can change their background color from black to white: $host . PrivateData.ErrorBackgroundColor = 'White' Use this line to see the colors that you can assign: [ System.Enum ]:: GetNames...

Regular expressions are extremely powerful - and complex. Fortunately, there are plenty of sources for good regular expressions that describe all kinds of patterns. This is how you turn a RegEx pattern into a regular expression engine: $regex = [ RegEx...

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 would like to focus on the different object types a command returns: Dir $env:windir | Get-Member | Group...

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 is-Weekend { ( Get-Date ). DayOfWeek -gt 5 } You can use it like this: If ( is-Weekend ) { 'no service...

How do you exclude objects based on empty properties? For example, WMI returns all kinds of "network adapters:" Get-WMIObject Win32_NetworkAdapterConfiguration To focus only on those that have an IPAddress assigned, you should exclude any object...

PowerShell is great for parsing log files. Here is a function that extracts all installed Windows updates from an internal log file and returns the information as pure PowerShell objects. Have a look as this code uses a number of powerful parsing and...

Have you ever wanted to find out the effective uptime of your PC (or some servers)? The information can be found inside the event log. Here is an example on how to select and prepare event data and create a report. This even works remotely. function Get...

Did you know that you can compile any .NET source code on the fly and use this to create your own types? Here is an example illustrating how to create a new type from c# code that has both static and dynamic methods: $source = @ ' public class Calculator...

Adding parameters to your functions is fairly easy. You can add a param() block and specify the parameters. But what if you wanted to assign values to different parameters based solely on type? Let's say you want a function that accepts both numbers...

Have you ever wondered how PowerShell would store a jpeg picture into your Active Directory user account? With the help of some low-level .NET calls, it's doable. You should simply adjust the path to your picture and the LDAP path to your user account...

Group-Object creates groups based on object properties. For example, you could group processes by company or folder listings by extension: Dir $env:windir | Group-Object Extension Get-Process | Group-Object Company If the object has no property that reflects...

While you can use Get-WMIObject to query for WMI objects and then select the ones you are really after, you can also cast a WMI object path to a WMI object and get to that instance immediately. For example, the following accesses the WMI object representing...

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 | Foreach-Object { $_ . CreationTime = '1/1/1972 10:35' } It will change creation time of c:\testfolder...

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 commonly used among developers, the other one among admins. Both will get you the same result. Have a look: #...