database-tools

Restart required

Check out this line to determine when an installation required a system restart: Get-EventLog -InstanceId 1038 -LogName Application | ForEach-Object...

Finding multiple RegEx matches

In a previous tip, you learned that Select-Object can find multiple matches. Here is a function called matches. You can submit a regular expressions...

Find multiple matches

When you want to find matches based on regular expressions, PowerShell will only support the -match operator which finds the first match. There does...

Translate EventID to InstanceID

Sometimes, you may need to have the event ID for a system event, though what you really need is the instance ID. For example, Get-EventLog will only...

Windows license validation

Search for the appropriate events in your event log to discover when Windows has validated your license: get-eventlog -LogName Application...

Analyze automatic defragmentation

Check out this line to visualize when your system defragmented your hard drives: get-eventlog -LogName Application -InstanceId 258 | ForEach-Object...

Find system restore points

Windows Update and Software installations will frequently create system restore points. Run this to get a list of such events: Get-EventLog -LogName...

Secret history shortcut

PowerShell will keep a history of the commands you entered and then you can list the history with Get-History, configuring the maximum length of...

Error handling for native commands

When you need to handle errors created by native commands, you can use a wrapper function like Call. It will automatically discover when a native...

Calculate time zones

If you need to find out the time in another time zone, you can convert your local time to Universal Time and then add the number of offset hours to...

Checking all event logs

What if you would like to get a quick overview of all error events in any event log. Get-EventLog can only query one event log at a time. So, you...

Creating IP segment lists

If you need a list of consecutive IP addresses, you can check out this function. You can see that it takes a start and an end address and then...

Getting significant bytes

If you need to split a decimal into bytes, you can use  a function called ConvertTo-HighLow, which uses a clever combination of type casts to...

Test Internet connection

Try this line if you would like to know whether a machine is currently connected to the Internet:...

Splitting hex dumps

Imagine you have a text string with a hex dump so that each hex number consists of two characters. How would you split this into individual hex...

Finding new processes

Get-Process will return a list of all processes. If you just want to see those started within the last 10 minutes, you can check StartTime. Both...

Load registry user hive

If you need to manipulate registry data from another user, you may be out of luck because HKEY_CURRENT_USER always points to your own user data....

Dump enumerations

You can create a simple helper function called Get-Enum  to list all the values in an enumeration: function Get-Enum($name){...

Compare services on two computers

Ever wondered why one computer runs well and another does not? Here is an example of how you can compare service configuration on two machines as...

Appending text files without new line

You can use Out-File with -Append to append lines to a text file, but there is no way to add text information without a line break. To do that, you...

Creating random passwords

Take a look how easy it is for PowerShell to create random passwords: PS > $list = [Char[]]'abcdefgABCDEFG0123456&%$' PS > -join...

Formatting multiple text lines

Use the awesome formatting operator -f to insert dynamic information into text! You can store the formatting information in a variable and use it in...

Creating new GUIDs in various formats

You can easily create new GUIDs (Globally Unique Identifiers) using the GUID type and its NewGUID() method. But did you know that you can use a...

Read text files that are in use

Get-Content can read text files only line-by-line. Use .NET directly if you need the exact content of a text file as one large text. Here is how you...

Enumerate Device Services

You will find that Get-Service will not  list device services. Here is how you can enumerate those low-level services:...

Find Latest Processes

You should try this piece of code to find all processes that were started within the past 10 minutes: Get-Process | Where-Object { try {...