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
  • Why Using Here-Strings?

    To create multi-line text in a script, you can simply enter the multi-line text into your script using quotes: $text = ' First Line Second Line Third Line ' $text Why should you ever bother using the so-called here-strings? $text = @' First...
  • Identifying .NET Framework 4.5

    PowerShell 3.0 can run both on .NET Framework 4.0 and 4.5. .NET Framework 4.5 adds additional objects and members, so for example this line will list the members of an enumeration such as System.ConsoleColor in .NET 4.5, but not in .NET 4.0: PS > ...
  • Testing Numbers and Date

    With a bit of creativity (and the help from the -as operator), you can create powerful test functions. These two test for valid numbers and valid DateTime information: PS > function Test - Numeric ( $Value ) { ( $Value -as [ Int64 ]) -ne $null } PS...
  • Get List of Type Accelerators

    Ever wondered what the difference between [Int] , [Int32] , and [System.Int32] is? They all are data types, and the first two are type accelerators, so they are really all the same. To list all the type accelerators PowerShell provides, use this undocumented...
  • Getting Help for Objects - Online

    In PowerShell 3.0, you finally can extend object types dynamically without having to write and import ps1xml-files. Here is an especially useful example: PS > $code = { $url = ' http://msdn.microsoft.com/en-US/library/{0}(v=vs.80).aspx ' -f...
  • 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...
« First ... < Previous 59 60 61 62 63 Next > ... Last »
Copyright 2012 PowerShell.com. All rights reserved.