Powershell

Speeding Up Remote Inventory

Get-WMIObject is a fantastic cmdlet to query information locally and on remote systems. Have a look: Get-Content c:\management.txt |ForEach-Object {...

Enabling Block Cursor

How would you like to get back the big ugly block cursor you may know from Commodore 64-systems? Here is a way: $Host.UI.RawUI.CursorSize = 100...

Resolve Host Names

Have you ever needed to resolve a host name to find its IP address? Simply use a .NET method and wrap it as PowerShell function: function...

Creating "Constant" Functions

When you make a function read-only, it can no longer be overwritten but you would still be able to delete the function and recreate it from scratch....

Adding Write Protection to functions

Functions by default have no write protection so they can easily be overwritten and redefined. You should do this if you'd like to make a...

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

1 93 94 95 96 97 104