database-tools

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 =...

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

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...

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...

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...

Creating Scheduled Tasks From XML

In a previous tip, we showed how you can export a scheduled task to an XML file. Now, it's time to see how you can re-import that XML file to...

Output Scheduled Tasks to XML

Here's an easy way how you can export and dump a task that you created in "Scheduled Tasks" to XML: function Export-ScheduledTask {...

Converting Bitmaps to Icons

If you need a new icon and have no icon editor at hand, then you can take a bitmap file (create one with MS Paint if you must) and have PowerShell...

Finding Numbers in Text

Regular Expressions are a great help in identifying and extracting data from text. Here's an example that finds and extracts a number that ends...

Verbose Driver Information

In a previous tip you discovered driverquery.exe to list driver information. This tool sports a /V switch for even more verbose information....

Making Names Unique

To make a list of items or names unique, you could use grouping and then, when a group has more than one item, append a numbered suffix to these...

Home-Made Driver Query Tool

Some months ago we introduced to you the driverquery.exe tool and how to convert its output to PowerShell objects. Here's now an amazing...