December 2012 - 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
  • Creating "Mini-Modules"

    Did you know that every PowerShell function can be turned into a script module with just one line of code? To test drive this, open the ISE editor and create a function: function Get-BIOS { param ( $ComputerName , $Credential ) Get-WmiObject -Class Win32_BIOS...
  • Ripping All Links from a Website

    PowerShell 3.0 comes with a great new cmdlet: Invoke-WebRequest ! You can use it for a zillion things, but it can also simply retrieve the content of a website. It will even do basic parsing, so opening a window with all links on that website is a piece...
  • Splitting Hexadecimal Pairs

    If you'd have to process a long list of encoded information, let's say a list of hexadecimal values, how would you split the list into pairs of two? Here is a way: ' this gets splitted in pairs of two ' -split ' (?<=\G.{2})(?=....
  • Splitting Texts without Losing Anything

    Typically when you split a text using the -split operator or the Split() method, the split character is removed from the text: $profile -split ' \\ ' C : Users Tobias Documents WindowsPowerShell Microsoft.PowerShell_profile.ps1 If you want to...
  • Cutting Off Text at the End

    Cutting off a part of a text at its beginning is easy. This line eats the first 3 characters: PS > ' C:\folder\file.txt ' . SubString ( 3 ) folder \ file.txt Cutting off text at its end is not so easy because there is no method for it. You...
  • Use Comparison Operators for Logfile Parsing

    Comparison operators usually return either $true or $false , but when applied to an array, return the array elements that match the comparison. You can use this to easily parse text-based logfile information. This simple line returns all updates installed...
  • Use -f with N0

    Often, it is necessary to output numbers, but you may want to control the number of digits and would like to control the formatting. The -f operator can do this and has a trillion options but there's just one you need to remember: N0 (the "0"...
  • Sending Results to Excel

    Here's a little function called Out-ExcelReport . Just pipe anything to it, and it will open in Microsoft Excel - provided it is installed on your system: function Out-ExcelReport { param ( $Path = " $env:temp\$(Get-Random).csv " ) $Input...
  • Colors Become Even More Important in the New ISE Editor

    When you type in code into the new PowerShell 3.0 ISE editor, your code is not just "colorful". You may know that each color stands for a specific element, so variables are red and operators are gray. These colors can help you prevent errors...
  • Controlling Process Priority and Processor Affinity

    When you get yourself a process using Get-Process, what you get back is an object that has useful methods and writeable properties. This line will assign a high priority to your current PowerShell host and would run on all four CPU cores (provided your...
  • Executing Elevated PowerShell Code

    Sometimes, a script may want to execute some portion of its code elevated, for example to write to HKLM in the Registry or change protected settings. Instead of requiring the user to run the entire script elevated, you can execute portions of it in a...
  • Examine Parameter Binding

    PowerShell caters all tastes which is why the next two lines do the exact same thing and get all JPG pictures from your Windows folder: PS > Get-ChildItem -Path $env:windir -Filter * . jpg -Name -Recurse -ErrorAction SilentlyContinue PS > ls -r...
  • Show-Command Creates PowerShell-Code for You

    In PowerShell 3.0, there is a cool new cmdlet called Show-Command : PS > Show-Command Get-Process It works both in the console and the ISE editor, and when you specify a cmdlet, a dialog window opens and shows a form that helps you discover and fill...
  • Blocking Interactive Console Apps in the ISE editor

    The ISE editor in PowerShell 3.0 seems to have an interactive console, but it really isn't. It is just a simulated console. So any command that requires direct console input will block the ISE forever - like this one: PS > choice.exe To prevent...
  • Multiline-Input in ISE Editor

    If you'd like to enter long lines of code into the console panel in the new PowerShell 3.0 ISE, you can press SHIFT+ENTER. This will add a line break without sending the line to PowerShell yet. ReTweet this Tip!
1 2 Next >
Copyright 2012 PowerShell.com. All rights reserved.