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

Archives

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
  • Type-Based Parameter Binding (Part 2)

    PowerShell 2+ In a previous tip we introduced automatic type-based parameter binding. Here is a use case. The function Test-Binding accepts files and folders. For incoming files, it calculates the file size. For incoming folders, it emits a warning. Note...
  • Understanding Type-Based Parameter Binding

    PowerShell 2+ PowerShell can automatically bind arguments to parameters based on type. Simply define different parameter sets. Here is an example: function Test-Binding { #Content [ CmdletBinding ( DefaultParameterSetName = ' Number ' )] param...
  • Find All Writeable Object Properties

    All Versions .NET objects often have properties that you can read to retrieve information. Some of these properties may actually be writeable, so you can use them to change the object. To find writeable properties, here is a trick. Take any .NET object...
  • Creating Custom Mandatory Parameters

    All Versions While you can declare a parameter as mandatory, this leaves not much control to you. If the user omits the mandatory parameter, PowerShell prompts the user with its ugly default prompt. Here is an alternative that allows you to define your...
  • Use a Shorter Prompt

    All Versions By default, PowerShell displays the current path in its input prompt which wastes as lot of space. When you overwrite the “prompt” function, you control how the prompt is displayed. Here is a prompt that displays the current location...
  • Doing Things in Parallel

    Any version By processing things in parallel rather than sequential, a script can complete much faster. Here is an example that uses background jobs to execute three tasks in parallel: # three things to do... $task1 = { Start-Sleep -Seconds 5 ; 1 } $task2...
  • More Splitting Fun

    In the previous tip, we explained how you can use a regular expression to split strings in groups of a given length. Let’s explore what else can be done with this approach: To split regular text in chunks of 5 character words, try this: ' Hello...
  • Splitting Groups

    All PowerShell Versions Ever wanted to split a string in chunks of a given length? Regular expressions can help. Here is an example that splits a list of numbers in groups of 8 digits each: ' 000111010010010000101001 ' -split ' (\d{8}) '...
  • Using Form-Based Windows in PowerShell

    WPF-based windows are the preferred way to create user interfaces this way - because the code is much easier to write, shorter, and WPF scales well on high-density high-resolution displays. Still, if you must use Windows Forms, here is a sample to get...
  • Safely Opening WPF Windows

    In the previous tip we explained how you can create WPF-based windows in PowerShell. However, when you play with WPF code inside PowerShell ISE, it might occasionally crash, or report "missing quotas" exceptions, indicating a resource problem...
  • Creating WPF Windows

    WPF is a great technique to create user interfaces in PowerShell. Most of the window content can be defined using XAML, a description similar to HTML but based on XML. The sample creates a "Fire Alarm" message window, and you can change text...
  • Sending Emails (and Diagnosing Mail Servers)

    Send-MailMessage has been around for many years. It can be used to quickly send an email without the need to have an email client at hand. All you need is an SMTP server. Likewise, it can be used to diagnose problems with a particular mail server: Send...
  • Saving Multiple Credentials

    Thanks to Jaap Brasser’s finding, here is an easy way of encrypting a bunch of credentials: $CredPath = " $home\Desktop\mycreds.xml " $creds = @ { Local = Get-Credential -Message LocalAccount Remote = Get-Credential -Message RemoteAccount...
  • Saving Credentials

    Here is a safe way of saving credentials to a file: $CredPath = " $home\Desktop\mycred.xml " Get-Credential | Export-Clixml -Path $CredPath This code generates the file mycred.xml on your desktop. The password is encrypted with your identity...
  • Clearing the Recycle Bin

    A much awaited new cmdlet surfaced in PowerShell 5.0: Clear-RecycleBin! You can clear the recycle bin on a particular drive, or on all drives. This will immediately clear all recycle bins and retrieve disk space: PS> Clear-RecycleBin -Force ReTweet...
< Previous 1 2 3 4 5 Next > ... Last »
Copyright 2012 PowerShell.com. All rights reserved.