PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Forum experts available to answer your PowerShell questions

Power Tips

Power Tips

Syndication

  • Auto-Discovering Online Help for WMI

    Get-WmiObject is a great and simple cmdlet to retrieve WMI information, and the parameter -List returns all available WMI class names that you can specify: # search for WMI class name: PS > Get-WmiObject -Class * Share * -List # retrieve all instances...
  • Using MemberSets

    In a previous tip you learned how PropertySets can create groups of properties for easier access. Yet another (hidden) feature of PowerShell objects is MemberSets. Objects can contain a MemberSet called PSStandardMembers which normally is hidden (along...
  • Using PropertySets

    PropertySets are lists of properties, and PowerShell sometimes adds PropertySets to result objects to make picking the right information easier. Get-Process for example returns process objects, and these contain two PropertySets: PS > Get-Process ...
  • Getting Weather Forecast from an Airfield near You

    PowerShell can access web services and automatically retrieve information such as weather forecasts. New-WebServiceProxy does all the work for you, and you only need to submit the web service URL. Note however that New-WebServiceProxy requires direct...
  • Checking System Uptime

    In a previous tip we explained how you read date and time information from WMI and convert it into a regular date and time information. With this technique, you can then manipulate and calculate with the regular date and time functions. So, this piece...
  • Converting Date to WMI Date

    WMI (Windows Management Instrumentation, Get-WmiObject ) uses a specific (DTMF) format for date and time. You can easily convert regular date and time information into this format: PS > $date = Get-Date PS > $wmidate = [ System.Management.ManagementDateTimeConverter...
  • Accessing PowerShell Host Process

    With this line, you always get back the process object representing the current PowerShell host: PS > [ System.Diagnostics.Process ] :: GetCurrentProcess () This is the equivalent to: PS > Get-Process -ID $PID Either way, the process object returned...
  • Using Specific Error Handlers

    If you want error handler to handle specific error types, you can add the error type after the keyword trap or catch . However, this will only work with so-called "terminating" errors. Any error that is handled by PowerShell internally (non...
  • Finding Popular Historic First Names

    To find popular first names for given decades, check out the function Get-PopularName . It accepts a decade between 1880 and 2000 and then uses the new and awesome Invoke-WebRequest in PowerShell 3.0 to visit a statistical website and retrieve popular...
  • 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 ...
« First ... < Previous 26 27 28 29 30 Next > ... Last »
Copyright 2012 PowerShell.com. All rights reserved.