June 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
  • Using String Functions

    PowerShell uses .NET objects everywhere. Anything is represented as .NET object, and .NET objects come with useful built-in methods. However, for string manipulation you do not need to look for sophisticated external commands as they are built right into...
  • Using Switch Parameters

    Switch parameters work like a switch, so they are either "on" or "off" aka $true or $false. To add a switch parameter to a function, cast the parameter to [switch] like this: function test([ switch ] $force ) { $force } When you call...
  • Calling VBScript From PowerShell

    Sometimes, you may have an existing VBScript that already does just what you want. You can easily incorporate any VBScript into PowerShell because PowerShell can call just about anything that is executable, including VBScript. The tricky part is that...
  • Casting Strings

    Strings represent text information and consist of individual characters. By casting, you can convert strings to individual characters and these into numeric ASCII codes: [ char []] "Hello" [ int []][ char []] "Hello" Casting helps...
  • Reading PowerShell Return Values From VBScript

    It is easy for VBScript to call a PowerShell script as you have learned in a previous tip. PowerShell can even return a numeric value so your VBScript knows if all went fine. Here is a short example that does not even call an external PowerShell script...
  • Returning Text Information From PowerShell To VBScript

    In a previous tip, you learned how to call PowerShell statements and read their return value. Return values are somewhat limited because they can only be numeric. There is an easy way to do this if you'd like to read more structured information from...
  • Checking File Names for Invalid Characters

    File names may not contain certain characters because they are illegal and cannot be processed by Windows. First, let's find out which characters are considered to be illegal in a file name. Use the System.IO.Path .NET class and its GetInvalidFileNameChars...
  • Checking Paths for Invalid Path Characters

    Paths may not contain certain characters because they are illegal and cannot be processed by Windows. First, let's find out which characters are considered to be illegal in a path. To get that list, use the System.IO.Path .NET class and its GetInvalidPathChars...
  • Removing Illegal File Name Characters

    If you have to batch-process tons of file names, you may want to make sure all file names are legal and automatically remove all illegal characters. Here is how you can do that: $file = "this*file\\is_illegal<>.txt" $file $pattern = "...
  • Using Test-Path to Validate A Path

    While raw .NET calls provides you with granular control over how to validate paths and file names, there is a cmdlet called Test-Path for simple purposes. Its primary purpose is to validate whether a file or path exists. When adding the -isValid parameter...
  • Trustworthy Folders

    If you want to launch a script file or executable, in PowerShell, you'll need to specify either a relative or absolute pathname. To do so by name, you’ll need to make sure the folder is trustworthy, which could be done simply by adding it to...
  • Returning Text Information from VBScript To PowerShell

    Sometimes, you may want to recycle old and proven VBScript scripts and call them from within PowerShell. In a previous tip, you have learned how to do that and use numeric return values to communicate. Today, let's look at how VBScript and PowerShell...
  • Removing Illegal Path Characters

    You can always strip all illegal characters from the path If you have no time to review path names and correct them manually to see if they contained illegal characters. Here is how you can do that: $path = "c:\<>illegal path" $path $pattern...
  • Finding Alias Names

    To find out all alias names associated with a given command, filter the alias list by its definition property. The following command lists all aliases that point to the Get-ChildItem cmdlet: Get-Alias | Where-Object { $_ . Definition -eq ' Get-ChildItem'...
    Filed under:
  • Using Advanced Path Functions

    Whenever the built-in Split-Path cmdlet isn't enough, you can always resort to the real .NET class behind it. This class is called System.IO.Path, Use Get-Member with the -static parameter to list its members: [ System.IO.Path ] | Get-Member -static...
1 2 Next >
Copyright 2012 PowerShell.com. All rights reserved.