database-tools

Checking Loaded Assemblies

Use this line to check which .NET assemblies are currently loaded into PowerShell: $host.Runspace.RunspaceConfiguration.Assemblies ReTweet this...

Checking -STA Mode

PowerShell needs to run in STA mode to display Windows Presentation Foundation (WPF) windows. ISE runs in STA mode by default whereas the console...

Filtering Multiple File Types

If you want to filter files based on multiple extensions, you should use this filter: filter Where-Extension { param( [String[]] $extension =...

Cleaning Transcript

When you run Start-Transcript, PowerShell will document all console input and output in a file. To remove all output and create a file with your...

Automated Authentication

You will not want a credential dialog to pop up if you need to run scripts unattended that need to authenticate using credentials. Here is an...

Get Logged On User

You can use this code to find out which user is locally logged on a machine: $computername = 'SomeMachine-or-IP'Get-WmiObject...

Finding Parameter Aliases

Sometimes, cmdlet parameters have additional alias names, but these names aren't well documented. Here is a script that will list all parameter...

Identifying Computer Hardware

If you must identify computer hardware, you could do so on the hard drive serial number: Get-WmiObject -Class Win32_DiskDrive | Select-Object...

Formatting a Drive

In Windows Vista and higher, there is a new WMI class called Win32_Volume that you can use to format drives. However, you should be careful when...

Sending Mails With Outlook

You can use PowerShell to automatically prepare your e-mails and send them via Outlook. The code requires that you first launch Outlook as an...

Setting Mouse Position

PowerShell can place the mouse cursor anywhere on your screen. Here's the code:...

Comparing Services

Compare-Object can help when troubleshooting computers. For example, you should try this to compare the service status on two machines and find out...

Reading Text Files as One Chunk

In a previous tip, you learned how to quickly read in text files. The result was a string array. If you want to read the text as one large string...

Reading Text Files Fast

Let's assume you want to read a large text file. Let's create one: Get-Process | Export-CliXML $home\data.xml(Dir $home\data.xml |...

Disabling Automatic Page Files

If you would like to programmatically control page file settings, you can use WMI but must enable all privileges using -EnableAllPrivileges. The...

Eliminating Duplicate Words

Let's assume you want to eliminate duplicate words in a text. Here is how you can do this: 'this text text contains duplicate words words...

Add Whitespace after Commas

Operator replace is extremely powerful when you use back references. For example, to make sure in a text that there is a space after each comma, you...

Use Back References with -Replace

If you need to replace text with some other text and keep a reference to the original text, you can use the backreferenceback reference placeholder...

Adding Quotes in Quotes

If you need quotes to appear inside a quoted string, you should use quotes: $text = "Hello ""World"""$text =...

Running Native Commands in PowerShell

Sometimes it only takes a little tweaking to make a native command run well inside PowerShell. For example, this line runs in cmd.exe but fails in...

Create Complex Random Passwords

Here is how you can create random passwords that meet certain requirements: function Get-RandomPassword { param( $length = 10, $characters =...

Create Random Passwords

Whenever you need to create a new random password, be sure to check out this function: function Get-RandomPassword { param( $length = 10,...

Using MsgBox Dialogs

Have you ever used VBScript? Would you like your MsgBox dialog back? Here is how:...

Creating Shortcuts on your Desktop

PowerShell and .NET can do amazing things, but they are not good at creating shortcuts. However, you can create a shortcut on your Desktop in a...

Resolving Host Names

In a previous tip, you learned how to quickly ping network segments. Next, you could resolve online IPs and get host lists of systems currently...

Finding Systems Online (Fast)

Using PowerShell Background Jobs, you can find a large number of online systems within only a few seconds: function Check-Online { param(...

Auditing PowerShell Scripts

How would you know if all PowerShell scripts on a production critical server are safe? Here is a simple line that can help you conduct a security...