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
  • Switch Accepts Arrays

    Did you know that the Switch statement can accept arrays? Use this sample to translate numbers into words: PS > switch ( 1 , 5 , 2 , 4 , 3 , 1 ) { 1 { ' one ' } 2 { ' two ' } 3 { ' three ' } 4 { ' four ' } 5 { '...
    Filed under:
  • Check For Numeric Characters

    Try this if you need to check a single character and find out whether or not it is numeric: PS > [ char ] :: IsNumber ( ' 1 ' ) True PS > [ char ] :: IsNumber ( ' A ' ) False The type Char has a bunch of other useful methods. Here...
  • Check Array Content With Wildcards

    You may know the -contains operator. Try using it to check whether an array contains a specific element: PS > $names = dir $env:windir | Select-Object -ExpandProperty Name PS > $names -contains ' explorer.exe ' True However, -contains does...
    Filed under:
  • Adding New PowerShell Drives

    You can add a bunch of interesting new drives to PowerShell with just a single line of code: [ System.Enum ] :: GetNames ([ System.Environment + SpecialFolder ]) | ForEach-Object { New-PSDrive -Name ( $_ ) -Root ([ System.Environment ] :: GetFolderPath...
  • Re-Assigning Types to Variables

    You can no longer assign other types when you strongly type a variable: [ Int ] $a = 1 $a = ' does not work ' However, you can always re-assign a new type to a variable: [ String ] $a = ' works ' ReTweet this Tip!
  • Generate Random Passwords

    In a previous tip, we showed you how to create random passwords. Thanks to your feedback, here is an even shorter version: -join ([ Char []] ' abcdefgABCDEFG0123456&%$ ' | Get-Random -count 20 ) ReTweet this Tip!
  • Tile Windows

    Do you remember the ancient feature where you could tile or cascade all open windows? These features are still available. However, before you try out the code, you should be aware that these features will re-size your windows and may change their default...
  • Case-Sensitive Hash Tables

    PowerShell hash tables are, by default, not case sensitive: PS > $hash = @ {} PS > $hash . Key = 1 PS > $hash . keY = 2 PS > $hash . KEY 2 If you need case-sensitive keys, you can create the hash table this way: PS > $hash = New-Object...
  • Creating Byte Arrays

    You can try this to create a new empty byte array with 100 bytes: $byte = New-Object Byte [] 100 Try this if you need to create a byte array with a default value other than 0: $byte = [ Byte []] ( , 0xFF * 100 ) ReTweet this Tip!
  • Quickly Changing File Extensions

    If you want to quickly exchange a file extension to create a "bak" backup version or generate a new file name for output, you should use the ChangeExtension() method: $oldpath = ' c:\test\datei.csv ' $newpath = [ System.IO.Path ] ::...
  • Grouping Files Based On Size

    In a previous tip, we showed you how to group using your own criteria. Group-Object can also auto-create hash tables so that you can easily create groups of objects of a kind. Here is an example: $criteria = { if ( $_ . Length -lt 1 KB ) { ' tiny...
  • Grouping Using Custom Criteria

    Try using Group-Object to group objects by any property: PS > Get-Process | Group-Object -property Company You can also submit a script block and calculate the grouping criteria yourself. The next example shows you how to group by file size into three...
  • Parsing Text-Based Log Files - Faster!

    In a previous tip, we showed you how to parse text-based log files using the PowerShell pipeline. However, the pipeline has considerable overhead. Without the pipeline approach, you can get the same results about 10-times faster: foreach ( $line in (...
  • Parsing Text-Based Log Files

    Extracting useful information from huge text-based log files isn’t necessarily a difficult task. Check out this line: PS > Get-Content $env:windir\windowsupdate.log -Encoding UTF8 | Where-Object { $_ -like ' *successfully installed* '...
  • Finding IP Addresses

    Sometimes, classic tools like ipconfig.exe can yield useful information that you'd like to integrate with PowerShell. Here is sample code that illustrates how to grab all IPv4 addresses from ipconfig output: PS > ipconfig | Where-Object { $_ -like...
« First ... < Previous 57 58 59 60 61 Next > ... Last »
Copyright 2012 PowerShell.com. All rights reserved.