powertips

Opening Databases from PowerShell

The easiest way of accessing databases right from PowerShell is to visit control panel and open the Data Sources (ODBC) module (which resides in...

Get Process Owners

One way to find out the owner of a process is to add the missing Owner property to process objects: $processes = Get-WmiObject Win32_Process -Filter...

Change Service Account Password

Ever wanted to automatically change the Password a service uses to log on to its account? WMI has a solution. Have a look: $localaccount =...

Adding a Hash property to file objects

You can easily add new properties and functions to object types using the extended type system. In this example, you append file objects with a new...

Adding File Age to file objects

PowerShell cmdlets return objects with rich information, and to see all the information, you can pipe the result to Format-List *: Dir $env:windir |...

Use Hash Tables for Custom Columns

Hash tables can generate "calculated" columns. All you need to do is store two pieces of information: a "label," which serves as...

Creating New Objects

There is a powerful new way in PowerShell v.2 to create new objects from scratch: You should first get yourself an empty hash table object, then add...

Exporting and Importing Credentials

You may have to use alternate credentials when you connect to different systems. You’ll find that a lot of cmdlets provide the -credential...

Exit a Script Immediately

Use the Exit statement if you run into a condition where a script should quit. The script breaks whenever you call exit from within your script. Add...

Get Remotely, Store Locally

When you start using PowerShell remotely, you may run into situations like this one: Invoke-Command -ComputerName remotepc { Get-Process |...

Dynamically Create Script Blocks

It is sometimes necessary to dynamically create script blocks. Here is an example how and why: function Get-RemoteLog($name) { $code =...

Remove Registry Keys and Values

Use Remove-Item to actually delete a registry key: function Remove-RegistryKey($key) { Remove-Item $key -Force} Use Remove-ItemProperty to delete a...

Using Real Registry Keys

In PowerShell, you access registry keys through virtual drives like HKCU: (for HKEY_CURRENT_USER) and HKLM: (representing HKEY_LOCAL_MACHINE). You...

Writing to the Registry

Adding or changing registry values is not always intuitive with PowerShell. Here is a function called Set-RegistryValue that will make your life...

Reading Registry Values

In PowerShell, you will need to use one of the Registry virtual drives to read from the Windows Registry as it is - not always intuitive. Here are...

Running Commands On Multiple Computers

You can work remotely not just for single computers. You can also run your commands against multiple computers like this: $computer = Get-Content...

Enabling PowerShell V.2 Remotely

Setting up the brand new PowerShell v.2 remotely in a domain environment is easy: simply run Set-WSManQuickConfig As long as you have proper...

Add New Properties To Your Objects

You can use Select-Object to add new properties to an existing object. In PowerShell v.2, Select-Object accepts a wildcard, which in turn adds all...

Calculating Time Differences

Use New-Timespan and submit a date if you'd like to know how long it is until next Christmas. New-Timespan automatically compares this date to the...

Analyze Parameter Binding

You probably know that PowerShell is pretty flexible when it comes to parameters you want to submit to cmdlets and functions. You can name them...

Why is my PowerShell console not blue?

When launching powershell.exe directly, you get a console with black background and only 300 lines of buffer text. When you launch PowerShell from...

Don’t be surprised by the Help bug

Get-Help is great for discovering cmdlet and function syntax but sometimes it fails on PowerShell v.2. Take a look at this: Get-Help...

Making Comment-Based Help Compatible

In a previous tip, you learned how to add Comment-Based Help information to your own functions so that Get-Help can auto-document the usage....

Using Comment-Based Help

PowerShell v.2 allows your functions to seamlessly integrate with the built-in PowerShell Help system. All you need to do is a Comment-Based- Help...

Using Block Comments

Another new feature in PowerShell v.2 is the introduction of a new block comment. Basically, anything you place between <# and #> will be...

1 87 88 89 90 91 98