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
  • Listing Currently Loaded Format Files

    The internal PowerShell formatting system (called ETS) relies on XML-based formatting data that comes from .ps1xml files. To see all files currently loaded by PowerShell and 3rd party extensions, use this line: $host . Runspace . InitialSessionState ...
  • Renaming Object Properties in Powershell

    Let's say you want to output just your top-level processes like this: PS > Get-Process | Where-Object { $_ . MainWindowTitle } | Select-Object Name , Product , ID , MainWindowTitle This works like a charm, but you'd like to rename the column...
  • Examine "Extended" Object Members

    PowerShell is based on .NET objects but often refines them by adding more. If you'd like to see just what PowerShell has added, use Get-Member with its parameter -View Extended. You'll be surprised how many useful properties are invented by PowerShell...
  • Writing Back WMI Property Changes

    Only a few properties in WMI objects are actually writeable although Get-Member insists they are all "Get/Set": PS > Get-WmiObject -Class Win32_OperatingSystem | Get-Member -MemberType Properties That's because WMI only provides "copies"...
  • Errors Travel in the Opposite Direction

    Here's a piece of code for you to wrap your head around: 1 . .10 | ForEach-Object { trap { Write-Host "Phew: $_" ; continue } $_ } | ForEach-Object { if ( $_ -gt 4 ) { Throw "Too big!" } else { $_ } } Ten numbers are fed into the...
  • Creating Dynamic Breakpoints

    The PowerShell 3.0 ISE editor has a simple debugger built-in that supports line breakpoints. Simply press F9 to set a breakpoint (which only works if the file has been saved). In addition, Set-PSBreakpoint can set dynamic breakpoints. This one would halt...
  • 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...
« First ... < Previous 58 59 60 61 62 Next > ... Last »
Copyright 2012 PowerShell.com. All rights reserved.