Power Tips

Share |

Join PowerShell.com!
Subscribe to Feed

PowerShell eBook
Sign up for
Your PowerTip of the Day:

Award-winning PowerShellPlus


Admin Guide to PowerShell Remoting


Mastering PowerShell eBook

Welcome to the archive of tips delivered through Tobias' Tip of the Day RSS Feed and Your Power Tip of the Day email. Subscribe in the sidebar to get the latest tips!

Sort by: Most Recent | Most Viewed | Most Commented
  • Using Cmdlets to Manage Virtual Hard Drives

    Windows 8.1 Pro/Enterprise or Server 2012 R2 Both Windows 8.1 and Server 2012 R2 come with a vast number of additional cmdlets, some of which can be used to manage virtual disks. However, before you can find and use these cmdlets, you need to activate...
  • Looking Up Cryptic Error Codes

    All PowerShell versions Often, WMI and API calls return cryptic numeric error codes. To find out what went wrong, try this little helper function: function Get - HelpForErrorCode ([ String ] $Code ) { if ( $Code . StartsWith ( ' - ' )) { $Code...
  • Converting Error Numbers

    All PowerShell Versions Error numbers that are returned by Windows API calls often appear as very large negative numbers. To give meaning to these numbers, convert them to hexadecimal values like this: PS> $errornumber = -2146828235 PS> '0x...
  • Creating HTML Colors

    All Versions To convert decimal color values to a hexadecimal representation, like the one used in HTML, try this line: PS> '#{0:x2}{1:x2}{2:x2}{3:x2}' -f 255,202,81,0 #ffca5100 PS> '#{0:x2}{1:x2}{2:x2}{3:x2}' -f 255,0,121,204 #ff0079cc...
  • Getting Help

    PowerShell 3.0 and later Provided you have downloaded PowerShell help via Update-Help, you can create yourself an excellent help topic viewer with just one line of code: PS> Get-Help about* | Out-GridView –PassThru | Get-Help –ShowWindow...
  • Break Into Script with PowerShell 5.0

    PowerShell 5.0 Preview As you might know, PowerShell 5.0 Preview is available and comes with vast debugging improvements. One is to be able to debug into any running script. So you do not have to set breakpoints in advance. Instead, once you press CTRL...
  • Watch Rick Astley Dance and Sing!

    All PowerShell Consoles (not PowerShell ISE) Before you try this, you may want to click the icon in the upper left corner of the PowerShell title bar, go to properties, and choose a small font. Next, try and run this command: ( New-Object Net.WebClient...
  • Pinging via IPv4

    All PowerShell versions You can use ping.exe just like any other command inside PowerShell scripts. By adding “-4” to the command line, you can force ping to use IPv4 (add “-6” to force IPv6 instead). PS> ping localhost -4 ReTweet...
  • Use F1 in PowerShell ISE

    PowerShell ISE 3 and later When you have downloaded the PowerShell help files (using Update-Help from an elevated shell), you can use the Get-Help cmdlet to find background information about many useful topics. This would list all topics, for example...
  • Functions Always Beat Cmdlets

    All PowerShell versions Functions always have higher rank than cmdlets, so if both are named alike, the function wins. This function would effectively change the behavior of Get-Process: function Get-Process { ' go away ' } And this is the not...
  • Encrypting and Decrypting Files with EFS

    All PowerShell versions Provided EFS (Encrypting File System) is enabled on your system, and you are saving files to a NTFS location, then this is how you can encrypt any file and make sure only you can read it: (Get-Item -Path 'C:\path..to..some...
  • Use Out-Host instead of More

    PowerShell Console Note that any of this will only work in a “real” console. It will not work in the PowerShell ISE. To output data page by page, in the PowerShell console many users pipe the result to more.com, like in the old days: PS>...
  • Invoke-Expression is Evil

    All PowerShell versions Try and avoid Invoke-Expression in your scripts. This cmdlet takes a string and executes it as if it was a command. In most scenarios, it is not needed, but introduces many risks. Here is a--somewhat constructed--show case: function...
  • Display Command History in PowerShell Console

    All PowerShell Versions In the PowerShell console (not the PowerShell ISE), you can open a list with the last commands you entered, simply by pressing F7. There will be no list if you did not execute any command yet, obviously. ALT+F7 will clear the command...
  • Importing and Installing Certificate

    All PowerShell versions To programmatically load a certificate from a file and install it in a specific location inside the certificate store, have a look at this script: $pfxpath = ' C:\temp\test.pfx ' $password = ' test ' [ System.Security...
1 2 3 4 5 Next > ... Last »
Copyright 2012 PowerShell.com. All rights reserved.