Powershell

IntelliSense Trick to Show Variables

In the PowerShell ISE editor, when you enter a dollar sign, an IntelliSense menu opens and displays all variables that are currently defined. When...

Writing Events to Own Event Logs

Often, there is a need to log information when a script runs. Instead of writing log information to a text file that you would have to maintain and...

Logging All Errors

In a previous tip you have seen that cmdlet errors can only be caught by an error handler if the -ErrorAction is set to "Stop". Doing this...

Catching Non-Terminating Errors

Non-terminating errors are errors that are handled by a cmdlet internally. Most errors that can occur in cmdlets are non-terminating. You cannot...

Hiding Terminating Errors

Occasionally, you may have noticed that cmdlets throw errors although you specified "SilentlyContinue" as -ErrorAction. The -ErrorAction...

Getting Events From All Event Logs

Recently, a reader asked how to retrieve all events from all event logs from a local or remote system, and optionally save them to file. Here is a...

Running Background Jobs Efficiently

Using background jobs to run tasks concurrently often is not very efficient as you might have seen in a previous tip. Background job performance...

Parallel Processing in PowerShell

If a script needs some speed-up, you might find background jobs helpful. They can be used if a script does a number of things that also could run...

Converting Ticks into Real Date

Internally, Active Directory uses ticks (100 nanosecond units since 1601) to represent date and time. It has been hard in the past to convert these...

Logging Script Runtime

If you'd like to monitor how long a script takes to run, you could use Measure-Command, but this cmdlet is for diagnostic purposes only and...

Fixing Encoding for Excel CSV

When you save Microsoft Excel data as CSV, unfortunately the encoding does not match the default encoding used by Import-Csv. So when you import the...

Reading All Text

You can use Get-Content to read in any plain text file. However, Get-Content will return the file content line by line, and you get back a string...

Storing Secret Data

If you wanted to store sensitive data in a way that only you could retrieve it, you can use a funny approach: convert some plain text into a secure...

Testing UNC Paths

Test-Path can test whether or not a given file or folder exists. This works fine for paths that use a drive letter, but can fail with pure UNC...

Enabling PowerShell Remoting

If you'd like to use PowerShell Remoting to execute commands and scripts on another machine, then you need to enable Remoting on the target side...

Enabling Classic Remoting

Many cmdlets have built-in remoting capabilities, for example Get-Service and Get-Process both have the parameter -ComputerName, and so does...

Finding USB Stick Information

Did you know that Windows logs any USB stick type you ever used? To get that information from the Registry, simply use this function: function...

Finding Expired Certificates

PowerShell grants access to your certificate stores by using the cert: drive. You can use this drive to find certificates based on given criteria....

Submitting Arguments to EXE Files

Running applications such as robocopy.exe from PowerShell sometimes is not trivial. How do you submit arguments to the EXE so that PowerShell...

Applying NTFS Access Rules

There are many ways to add or change NTFS permissions. One is to reuse existing tools such as icacls.exe. This function will create new folders that...

Profiling Systems

If you just want to profile a local or remote system and get back the most commonly used pieces of information, then do not waste time for your own...

Get-WirelessAdapter

In the previous tip, we illustrated how you can use Registry information to find wireless network adapters. Here is now a function...

Finding Wireless Network Adapters

There are many ways of finding network adapters, but apparently none to identify active wireless adapters. All information about your network...

Drive Data in GB and Percent

When a cmdlet returns raw data, you may want to convert the data into a better format. For example, WMI can report the free space of a drive but...

Finding Errors since Yesterday

Relative dates are important to get data within a special time frame, avoiding hard-coded dates and times. This script will get all error and...

1 60 61 62 63 64 104