Power Tips

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
  • Use the Force!

    Many cmdlets support the -force switch parameter. With it, the cmdlet will do more than usual. What exactly -force does depends on the cmdlet. For example, Get-Childitem (aka Dir) by default does not list hidden files. However, with -force, it does. Another...
  • Listing Program Versions

    You may already know about the Get-Process cmdlet, which lists all running processes, locally and remotely (use -computername for remote access). But did you know that the folks at Microsoft added the -FileVersion switch parameter in PowerShell v.2? With...
  • Using Relative Dates

    Sometimes, you need relative dates. What date was 14 days ago? Maybe you want to use this relative date to select files of a certain age. You can use Get-Date in conjunction with New-Timespan to construct relative dates. The following line will get you...
  • Creating Temporary File Names

    Get-Date not only will retrieve the current date, but you can also construct a custom date format to create time-stamped temporary file names: ( Get-Date -format 'yyyy-MM-dd hh-mm-ss' ) + '.tmp' ReTweet this Tip!
  • 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...
« First ... < Previous 57 58 59 60 61 Next > ... Last »
Copyright 2012 PowerShell.com. All rights reserved.