PowerShell is loading .NET assemblies. These assemblies can be precompiled using the tool ngen.exe which improves loading times (because the DLLs no...
database-tools
Get Localized Month Names
To get a list of month names, you could use this line: PS>...
Creating Symmetric Array
By default, PowerShell uses jagged arrays. To create conventional symmetric arrays, here's how: PS> $array = New-Object 'Int32[,]'...
Finding Domain Controllers
If your computer is logged on to an Active Directory, here is some code to get to your domain controllers. Note that this will raise errors if you...
Executing Commands in Groups
In traditional batch files, you can use "&&" to execute a second command only if the first one worked. In PowerShell, the same can...
Listing All WMI Namespaces
WMI is organized into namespaces which work similar to subfolders. Here's a line that lists all namespaces you got: PS> Get-WmiObject -Query...
Formatting XML Files
Here's a cool little XML formatting tool. It takes the path to any XML file and allows you to specify an indent. Then, it saves the file as new...
Get .NET Runtime Directory
Ok, this is more for the developers. To find out where your .NET Runtime folder is, try this line: PS> $path =...
Communicating Between Multiple PowerShells via UDP
Assume you want to send some information to another PowerShell session, or you'd like to have one session wait until another is ready. Here are...
Custom Formatting DateTimes
In a previous tip we published the list of placeholders to define datetime patterns. You can use the very same placeholders to define your own...
Parsing Custom DateTime Formats (Part 2)
In a previous tip we illustrated how you can use ParseExact() to parse custom datetime formats. This only works though if the date and time...
Parsing Custom DateTime Formats
Sometimes, date and time information may not conform to standards, and still you'd like to interpret that information correctly as date and...
Parsing Date and Time
Parsing a date and/or time information is tricky because formatting depends on the regional settings. This is why PowerShell can convert date and...
Comparing Services in PowerShell
Compare-Object is one of the most widely ignored most powerful cmdlet around. It can compare results and figure out differences. For example, if...
Map Network Drive
Sure you can use the command net use to map a network drive. But this would not check for existing mapped drives. Here's a small function that...
Getting Windows Product Key
Ever wanted to read out the Windows license key? In the Windows Registry, this key is present, but it is stored as a digital ID. To convert it back...
Mapping Printers Part 2
In a previous tip we explained how you can install and map printers remotely using a low level command: rundll32 printui.dll,PrintUIEntry /in /n...
Using "Elevator Music" In Your Scripts
Maybe you'd like to give some feedback to the users of your script while it processes a long-running task. One of the easiest (and most...
Sharing Folders
Console commands are first class PowerShell citizens, so sometimes it may be easier to use classic console commands to solve a problem. Here is a...
Executing PowerShell on Computer Lock
PowerShell can respond to system events such as locking or unlocking a session. Here is a fun sample. Provided you have your sound card turned on,...
Sending Email to Multiple Recipients
Send-MailMessage can send emails to multiple recipients. You just need to make sure the list of recipients is provided as an array. When you call...
Adding Progress to Long-Running Cmdlets
Sometimes cmdlets take some time, and unless they emit data, the user gets no feedback. Here are three examples for calls that take a long time...
Killing Long-Running Scripts
You can use a background thread to monitor how long a script is running, and then kill that script if it takes too long. You can even write to an...
Listing Processes and Process Ownership
Get-Process can list processes but does not provide information about who is running the process. Here, WMI can help. Get-ProcessEx is a clever...