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

Power Tips

Power Tips

Syndication

Archives

  • Saving PowerShell User Defaults

    We are about to enter “Color Week” with plenty of tips how you can choose better colors for the PowerShell ISE editor and the console. Most changes that you apply to PowerShell are not saved. PowerShell ISE does save some of the color settings...
  • Finding ASCII Codes

    Here is an easy way to find the ASCII code for any character you may have scraped from a website, or found in a script that you copied from the internet. Simply open a PowerShell, and enter this: # paste character(s) inside the quotes $text = ''...
  • Checking Hard Drive Size (Local and Remote)

    WMI can provide the raw data about hard drive size and free space. PowerShell then takes that information and provides user-friendly results like this: PS C:\> # local PS C:\> Get-HardDriveSize DriveLetter Free(GB) Size(GB) Percent ----------- ...
  • Enabling Remote Administration

    PowerShell 2+ Many older DCOM-based commands require a “Remote Administration Firewall Exception” to access remote systems. This includes cmdlets like Get-WmiObject. One easy way of enabling this is to run the following command in a PowerShell...
  • Finding Auto Starts

    PowerShell 3+ If you’d like to know which programs start automatically on your machine, WMI may help: PS C:\> Get-CimInstance -ClassName Win32_StartupCommand | Select-Object -Property Name, Location, User, Command, Description Name : OneDrive...
  • Replacing CSV File Headers

    PowerShell 2+ When you read in CSV data and would like to rename the CSV headers, here is a simple approach: just read in the text line by line, and skip the first line (which holds the CSV headers). Then, replace the headers with a list of your own header...
  • Receiving Input via Pipeline

    In the previous tip we illustrated how Convert-Umlaut was able to convert special characters in a string. This becomes even more useful if a function accepts pipeline input. Let’s check out the changes required to add that. Without pipeline support...
  • Replacing Special Chars like “Umlauts”

    PowerShell 2+ Sometimes it becomes necessary to replace special characters like German “Umlauts” in order to normalize user names or email addresses. Here is a little function that illustrates how this can be done: #requires -Version 3 function...
  • Using Friendly Robocopy

    PowerShell 2+ Robocopy is a tool of choice to copy files, and that does not change with PowerShell. You can, however, use PowerShell to embed robocopy inside a user-friendly PowerShell function. This way, you no longer need to remember the awkward command...
  • Beware of Changes to PSModulePath

    PowerShell 3+ PowerShell examines the $env:PSModulePath environment variable to find out the locations where it searches for extension modules. A little known fact is that the content of this variable is partially synthesized. And this can become a big...
  • The Truth About WinRM

    PowerShell 3+ The popular winrm command to manage and configure PowerShell Remoting is really just a batch and a VBS file: PS> Get-Command winrm -All | ft -AutoSize CommandType Name Version Source ----------- ---- ------- ------ Application winrm.cmd...
  • Listening to Music in the Background

    PowerShell 3+ In the previous tip we presented to you a “Dancing Rick ASCII”, created by Lee Holmes. Lee uses music stored on his server as background. Here is an example that illustrates how you can spawn a background thread, and for example...
  • Smuggling In PowerShell Code

    PowerShell 2 There is a good reason why Invoke-Expression is considered risky. This cmdlet executes whatever string it gets, and attackers can download malicious code from the Internet, bypass script analysis, and execute it. Here is a benign example...
  • Display Windows

    PowerShell 3+ It is fairly easy to use WPF (Windows Presentation Foundation) to create and show simple dialog windows in PowerShell. If you’d like to display a quick message, check this out: Add-Type -AssemblyName PresentationFramework $window ...
  • Add a Clock to PowerShell

    PowerShell 2+ Here is a fun example that illustrates how to work with timers. It adds a clock to the title bar of the PowerShell console or the PowerShell ISE. Simply run the script, then call Start-Clock to start the clock, and Stop-Clock when you want...
1 2 3 4 5 Next > ... Last »
Copyright 2012 PowerShell.com. All rights reserved.