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

Power Tips

Power Tips

Syndication

  • Check Installed Server Roles and Features

    Beginning with Server 2008 R2, there is a PowerShell module called ServerManager that you can use to manage server features and optional components. Simply import the module in PowerShell v2: PS > Import-Module ServerManager In PowerShell v3, the module...
  • Finding Published Printers

    Finding printers that have been published in your Active Directory becomes trivial with Windows 8 or Server 2012. PS > Get-Printer -ComputerName dc1 | Where-Object published ReTweet this Tip!
  • Calculating Time Differences Using Custom Formats

    Calculating time differences is easy - provided you can convert the date and time information into a DateTime type. If the date is in a custom format, you can use the method ParseExact() and submit your own pattern. So if you have custom dates formatted...
  • Get CPU Load

    To get the average total CPU load for your local system or a remote system, use Get-Counter. The example below returns the average total CPU load for a 10 second interval: PS > ( Get-Counter ' \processor(_total)\% processor time ' -SampleInterval...
  • Calling WMI Methods with CIM Cmdlets

    It can be very useful to call WMI methods, for example to create new shares, but in PowerShell v2 you had to know the names and exact order of arguments to submit: $rv = Invoke-WmiMethod -Path ' Win32_Share ' -ComputerName $ComputerName -Name...
  • Temporarily Activate High Performance Power Plan

    It may be useful to automatically and temporarily switch to a "high performance" power plan from inside a script. Maybe you know that a script has to do CPU-intensive tasks, and you would like to speed it up a bit. Here is how a script can change...
  • Listing Power Plans

    There is a somewhat hidden WMI namespace that holds WMI classes you can use to manage power plans. The code below lists all power plans on your local machine, and using -ComputerName, you can easily retrieve this information remotely as well: PS >...
  • Mixing DCOM and WSMan in WMI Queries

    Using the new CIM cmdlets in PowerShell v3, you can run remote WMI queries against multiple computers using multiple remoting protocols. The sample code below gets WMI BIOS information from five remote machines. It uses DCOM for the old machines in $OldMachines...
  • New Operator -In

    In PowerShell v3, you can use a new simplified syntax for Where-Object. Both lines below list all files in your Windows folder that are larger than 1MB: # old syntax: PS > Dir $env:windir | Where-Object { $_ . Length -gt 1 MB } # new alternate simplified...
  • Removing Leading "0" in IP Addresses

    Leading "0" in IP addresses can cause confusion because many network commands interpret octets with leading "0" as octal numbers: # no leading "0": PS > ping 10.10.5.12 Pinging 10.10.5.12 with 32 bytes of data : ( ......
  • CIM-Cmdlets Work Against Old Windows Boxes

    The new CIM cmdlets require PowerShell v3, but you can still remotely target older boxes without PowerShell v3 or PowerShell at all. By default, CIM cmdlets use WSMan for remote connections. If you want to use the old DCOM technique, create a CIMSession...
  • New WMI Cmdlets with DateTime Support

    In PowerShell v3, to work with WMI you can still use the old WMI cmdlets like Get-WmiObject. There is a new set of CIM cmdlets, though, that pretty much does the same - but better. For example, CIM cmdlets return true DateTime objects. WMI cmdlets returned...
  • Finding Keyboard and Mouse

    You can use WMI to quickly find all details about your mouse and keyboard: PS > Get-WmiObject win32_PointingDevice | Where-Object { $_ . Description -match ' hid ' } PS > Get-WmiObject win32_Keyboard | Where-Object { $_ . Description -match...
  • Finding Built-In Variables Part 2

    In a previous tip we featured a piece of undocumented code that works in PowerShell v3 to list all built-in variables. Here is another approach that also works in PowerShell v2. It creates a fresh new runspace and dumps all variables. Since the runspace...
  • Adjust Text to Specific Length

    If you must make sure that a text has a fixed length and is neither shorter nor longer, here is the code to pad and cut the text to the desired length: $text1 = ' some short text ' $text2 = ' some very very very very long text ' $desiredLength...
« First ... < Previous 26 27 28 29 30 Next > ... Last »
Copyright 2012 PowerShell.com. All rights reserved.