December 2009 - Power Tips

Share |

Join PowerShell.com!
Subscribe to Feed

PowerShell eBook
Sign up for
Your PowerTip of the Day:

Award-winning PowerShellPlus


Admin Guide to PowerShell Remoting


Mastering PowerShell eBook

Welcome to the archive of tips delivered through Tobias' Tip of the Day RSS Feed and Your Power Tip of the Day email. Subscribe in the sidebar to get the latest tips!

Sort by: Most Recent | Most Viewed | Most Commented
  • Getting Hotfix Information

    PowerShell v.2 comes with a new cmdlet called Get-Hotfix. It retrieves for you all installed hotfixes and updates. You can use it locally or remotely. You should use its -computername parameter to query a remote computer: Get-Hotfix -computername 10.10...
  • Validating Input Type

    The -as parameter is not widely known but is extremely versatile. It tries to convert data into a .NET type, and when it fails, it simply returns $null. This way, you can create your own functions to test data types. For example, you should use the following...
  • 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 { Get-WmiObject Win32_BIOS -ComputerName $_ } Here, Get-WMIObject contacts all machines listed in the...
  • 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 Simply specify a value between 0 and 100, which is the cursor size in percent. ReTweet this Tip!
  • 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 Get-HostToIP ( $hostname ) { $result = [ system.Net.Dns ]:: GetHostByName ( $hostname ) $result . AddressList | ForEach...
  • 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. You can make them constant if you'd like to create functions that cannot be changed as long as the...
  • 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 function "read-only": function ImportantFunction { "You cannot overwrite me!" } (dir function...
  • Converting Database Records into PowerShell objects

    When you access a database, the result is not automatically wrapped as objects so you cannot pipe the result into other cmdlets like Sort-Object or Group-Object. You can with PowerShell v.2. Here is a sample based on a previous tip (refer to the previous...
  • 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 Administrative Tools inside control panel). Use the GUI to set up the database type by clicking the "User...
  • 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 "name='notepad.exe'" $appendedprocesses = foreach ( $process in $processes ) { Add...
  • 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 = ".\sample-de-admin-local" $newpassword = "secret@Passw0rd" $service = Get-WmiObject win32_Service...
  • 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 script property which creates a file hash. File hashes are an excellent way of finding duplicate files...
  • 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 | Format-List * You can easily append more properties if the information returned is not sufficient. For...
  • 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 information: "Name" (which is the new property name) and "expression" (which is the code...
  • 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 new column header, and an "expression," which is the code used to calculate the column: $age...
1 2 Next >
Copyright 2012 PowerShell.com. All rights reserved.