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

Power Tips

Power Tips

Syndication

Archives

  • Using Code Regions in ISE

    PowerShell 3.0 and later PowerShell ISE already supports collapsible code regions. When you write functions, loops, or conditions, you will notice a vertical line in the left margin with a “minus” symbol on top. Click it to collapse the region...
  • Process Killer (and some gotchas)

    PowerShell 3.0 and later In a previous tip we explained how you can turn Out-GridView into a selection dialog, and suggested a couple of ideas. One idea was to list all top level applications, and allow the user to select one, and kill it. To get all...
  • Copying Results to Clipboard

    PowerShell 3.0 and later In a previous tip we explained how you can easily copy and paste information from a grid view window produced by Out-GridView. This will not copy the column headers, though. Here is a line that you can add to any command, and...
  • Out-GridView: Universal Dialog

    PowerShell 3.0 and later By default, Out-GridView is a one-way road: you can pipe data into it and display it in a grid view window, but you cannot pass the data on. Once you add the –PassThru switch parameter, this changes, and Out-GridView displays...
  • Finding All Stoppable Services

    PowerShell 3.0 and later Get-Service lists all services installed on your computer. It has no parameter to select only running or stopped services, though. With a simple Where-Object clause, you can make up for this. Most often, you will see something...
  • Exporting Out-GridView Content

    PowerShell 3.0 and later Out-GridView is a very useful cmdlet to output results to an extra window. Unlike outputting to the console, Out-GridView will not cut off anything. And it has a not-so-obvious way of easily copying the information to other applications...
  • Getting a Clean PowerShell Environment

    PowerShell 3.0 and later When you develop PowerShell scripts in the PowerShell ISE, you will probably make a lot of changes and revisions, and regularly execute scripts for testing. This can “pollute” your environment: all variables defined...
  • Adding PowerShell Tools to Windows 8 Start Screen

    Windows 8/Windows 8.1 You may have noticed that the Windows 8 start screen by default is missing PowerShell tools like the PowerShell ISE. When you switch to the start screen and enter “ISE”, the search yields no result. To change this, make...
  • Find AD Replication Failures

    Windows 8.1, Server 2012 R2 Investigating Active Directory replication failures becomes easy with Windows 8.1 and Server 2012 R2. A new cmdlet called Get-ADReplicationFailure will output recent replication failure information. Use it to check a specific...
  • Useful Static .NET Methods

    All Versions PowerShell can access static methods of .NET types. Here are some real world one-liners that can do a lot for you: [ Math ] :: Round ( 7.9 ) [ Convert ] :: ToString ( 576255753217 , 8 ) [ Guid ] :: NewGuid () [ Net.Dns ] :: GetHostByName...
  • Mandatory Parameters with a Dialog

    All Versions Typically, when you declare a parameter as mandatory, and the user does not submit it, PowerShell takes care and prompts the user for the value: function Get-Something { param ( [ Parameter ( Mandatory = $true )] $Path ) "You entered...
  • Use Open File Dialog

    All PowerShell versions To add some sophistication to your script, here is a simple function that opens the OpenFile dialog and lets the user pick a file. function Show-OpenFileDialog { param ( $Title = ' Pick a File ' , $Filter = ' All|*...
  • Logging Folders with Access Denied Errors

    All Versions When you browse the file system with Get-ChildItem, you may stumble across folders that you have no access to view. If you’d like to keep a log of all the folders that raised errors, try this approach: $result = Get-ChildItem -Path...
  • Managing Terminal Service Settings

    ActiveDirectory Module Sometimes you may want to directly access properties related to the terminal service in an Active Directory account. Here is some sample code illustrating how this can be done: $Identity = ' SomeUserName ' $distinguishedName...
  • Credential Obfuscator

    PowerShell ISE 3.0 and later While it is generally not recommended to hard code passwords in scripts, there are sometimes scenarios where this is done. Rather than hard coding plain text passwords, at least an effort should be made to obfuscate passwords...
« First ... < Previous 26 27 28 29 30 Next > ... Last »
Copyright 2012 PowerShell.com. All rights reserved.