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

Power Tips

Power Tips

Syndication

  • Use a Lock Screen

    With WPF, PowerShell can create windows in just a couple of lines of code. Here's a funny example of a transparent screen overlay. You can call Lock-Screen and submit a script block and a title. PowerShell will then lock the screen with its overlay...
  • Creating Temporary Password

    Here's a chunk of code that creates random passwords of different lengths for you: $length = 8 $characters = [ Char []](( 31 . .50 ) + ( 65 . .90 ) + ( 97 . .122 )) $characters = $characters -ne ' O ' -ne ' o ' -ne ' l ' -ne...
  • Obfuscating Credentials

    How can you securely embed confidential passwords in a PowerShell script? You can't. But you can make it harder for people to discover the secret. Here is a code generator script that is designed to run inside the PowerShell ISE editor: # ask for...
  • Create a Folder Selector

    To add a little glamour to your scripts, here are a few lines of code that display a folder selector dialog. When a user selects a folder, your script receives the selection and can work with the selected path: Add-Type -AssemblyName System.Windows.Forms...
  • Getting Folders by Prefix

    Did you know that Group-Object can easily group elements by custom criteria? Here's a line that groups folders by their first three letters: Get-ChildItem -Path C:\Windows -Directory | Group-Object -Property { $_ . Name . PadRight ( 3 ) . Substring...
  • Finding Known USB Drives

    Did you know that Windows maintains a list of all USB storage devices ever hooked up to your machine? And it's simple to dump that list: $Path = ' HKLM:\SYSTEM\CurrentControlSet\Enum\USBSTOR\*\* ' Get-ItemProperty -Path $Path | Select-Object...
  • Getting DLL File Version Info

    Ever needed a list of DLL files and their versions? Get-ChildItem can get this information for you. You just need to unpack some properties like so: Get-ChildItem c :\ windows \ system32 \ * . dll | Select-Object -ExpandProperty VersionInfo | Select-Object...
  • Executing Code Remotely

    In a domain environment, PowerShell remoting is working almost out of the box. All you might have to do is enable Remoting on target machines (beginning with Server 2012, PowerShell remoting is enabled by default for Administrators). In PowerShell 3.0...
  • Accessing All Users Desktop

    Resolve-Path is an excellent cmdlet to find paths that have the same nesting level. For example, here's a really short script that creates a text file on the desktop for all users of your machine: $root = Split-Path $env:USERPROFILE Resolve-Path ...
  • Quickly Selecting Results in ISE

    If you'd like to quickly select and copy results from the Console Pane of the PowerShell 3.0 ISE editor into your blog or favorite word processor, for example to document command results or illustrate "howto" articles, here is how: After...
  • Speeding Up Multiple WMI Queries

    Whenever you run Get-WmiObject against a remote system, it will create a new connection. So if you query different WMI classes, each query will use its own connection, which slows down overall performance. Beginning with PowerShell 3.0, there is a new...
  • Visit the Ultimate PowerShell Survival Guide

    Are you familiar with the PowerShell Survival Guide? It's the ultimate PowerShell Wiki page, including videos, modules, and information about every PowerShell-related resource you possibly could want. The best part: it's an open Wiki, so if you...
  • Getting WMI IntelliSense

    Get-WmiObject provides no IntelliSense for WMI classes, so you either need to know the WMI class name off hand, or use the parameter -List to search for it. But there's a clever trick: Get-CimInstance does almost the same thing, and its parameter...
  • Listing "Real" Hard Drives

    WMI can provide lots of information about a system, but sometimes it is just a bit too much. So when you query for logical disks, you often get back many more than just the physical ones. Setting an additional filter will do. This line returns only physical...
  • Improving Module Auto-loading

    PowerShell 3.0 will auto-load modules as you have seen in a previous tip. However, with some modules, this technique may fail. Their cmdlets will still only be available after you manually import the module using Import-Module. The reason most likely...
« First ... < Previous 26 27 28 29 30 Next > ... Last »
Copyright 2012 PowerShell.com. All rights reserved.