Power Tips

Share |

Join PowerShell.com!
Subscribe to Feed

PowerShell eBook
Sign up for
Your PowerTip of the Day:

Powershell Plus


13 Free SQL Tools from Idera


Free Ebook: Mastering Powershell

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
  • Executing Code after Script Is Done

    For monitoring purposes, it is often not known how long a script needs to run. So here, an endless loop is used. The script runs for as long as the user wants, and stops only when the user aborts the script by pressing CTRL+C or closing PowerShell. When...
  • Setting Permanent Environment Variables

    When you set or change environment variables in PowerShell, this only affects the process set, so changes apply only to the current PowerShell session. To set Windows environment variables permanently, use a function like this: #requires -Version 2 function...
  • Replacing Special Characters

    Sometimes it is crucial to replace special characters in text before you can use it. For example, if you plan to create Active Directory accounts, names cannot contain language-specific special characters. Here is a universal function that can turn text...
  • Getting Airports and Weather Info near You

    PowerShell can talk to web services, and there are some public web services that you can contact via internet. Here are two functions: Get-Airport gets all supported airports in a given country. Get-Weather then gets the current weather information: #requires...
  • Monitoring Log Files

    To monitor text-based log files, you can use a statement like this: #requires -Version 3 $path = ' c:\somefile.txt ' Get-Content -Tail 0 -Wait -Path $path | Out-GridView Just replace the path to the file you want to monitor. Get-Content uses ...
  • Identifying Essential Add-Type Statement

    When you access .NET types and objects directly in your PowerShell code, you must make sure that the appropriate .NET assemblies are loaded. If you do not, you risk that your script will break once it runs in a simple PowerShell console. Here is a way...
  • Exporting and Importing Credentials

    It is trivial to save credentials to disk so you can later re-import them. This is the part that takes a credential and saves it to disk: #requires -Version 3 $path = " $home\Desktop\cred.xml " $cred = Get-Credential $cred | Export-Clixml -Path...
  • Understanding the –f Operator

    You may have come across the –f operator before and wondered what it does. It’s the format operator and provides an extremely easy way of accessing array elements to create strings. Let's start with an array of values, like this one: ...
  • Creating Backup Copies of Many Files

    PowerShell can quickly create backup files of your files. All you need to adjust is the type of files you want to backup, and the file extension you want to use for your backup files. This example would affect all PowerShell scripts stored (directly)...
  • Piping Results Straight Into Office Word

    With only a few lines of code you can implement a command called Out-OfficeWord. It takes the data you pipe into it and inserts them into a new Word document (provided Word is installed). #requires -Version 1 function Out-OfficeWord { param ( $Font =...
  • Search WMI for Useful Information

    WMI is a great source of information but it is not always easy to find out the names of valid WMI classes to query. Here is a little search tool: it asks for a keyword, then searches WMI for all valid classes with this keyword. The results are shown in...
  • Use a Grid View Window as a Universal Dialog

    Out-GridView can be much more than just a window showing results. You can turn it into a pretty useful universal dialog. Let's assume you want to present to the user a number of running applications, and have him/her choose one to stop. The classic...
  • Outputting File Sizes in Different Formats

    When you store a number in a variable, you may want to display the number in different units. Bytes are very precise, but sometimes displaying the bytes as kilobytes or megabytes would be more appropriate. Here is a clever trick that overwrites the internal...
  • Converting Date/Time Formats

    Here is a simple PowerShell filter that can convert any DateTime object into any date/time-format you like: #requires -Version 1 filter Convert-DateTimeFormat { param ( $OutputFormat = ' yyyy-MM-dd HH:mm:ss fff ' ) try { ([ DateTime ] $_ ) . ToString...
  • Waiting for Process Launch

    PowerShell has a built-in support to wait until a process or many processes end: simply use Wait-Process. There is no support to do the opposite: wait until a process has started. Here is a function that can wait for any process: #requires -Version 1...
« First ... < Previous 2 3 4 5 6 Next > ... Last »
Copyright 2012 PowerShell.com. All rights reserved.