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...
database-tools
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 |...
Using Calculated Columns in New Objects
Select-Object can add new properties to objects and fill them with calculated content. All you need for this is a hash table with two pieces of...
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...
Configuring WSMan Remotely for multiple computers
When working remotely in a peer-to-peer or cross-domain scenario, you will have to add all the computers you'd like to communicate with into the...
Remote Configuration in a Peer-to-Peer environment (or across domains)
By default, PowerShell requires Kerberos authentication to operate remotely, so you cannot use it in a simple peer-to-peer scenario. You can also...
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...
Retrieving Error Messages From Your Event Logs
Event logs record all kinds of stuff. To find the important things, use Get-EventLog and query for the events you are seeking. In PowerShell v.2,...
Use Regular Expression to Validate Input
PowerShell can use regular expressions to validate user input. All you need is a regular expression that adequately defines the pattern you are...
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...