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
  • Randomize Lists of Numbers

    All PowerShell versions This line will take a list of numbers and randomize their order: Get-Random -InputObject 1 , 2 , 3 , 5 , 8 , 13 -Count ([ int ] :: MaxValue ) Piping works too, but it's slower: 1 , 2 , 3 , 5 , 8 , 13 | Sort-Object -Property...
  • Reading Disks and Partitions

    Windows 8.1 / Server 2012 R2 Disk management has been greatly simplified with the many new client and server cmdlets that ship with Windows 8.1 and Server 2012 R2. Let’s start with looking at disks and partitions. This would list all disks you have...
  • Finding Out Windows Version

    All PowerShell Versions Do you own Windows 8.1 Basic, Pro, or Enterprise? Finding out the Windows version is easy. Finding out the exact subtype is not so trivial. At best, you may get the SKU number which tells you exactly the Windows version you have...
  • Join-Path Fails with Nonexistent Drives

    All Versions To construct path names from parent folders and files, you may have been using Join-Path. This cmdlet takes care of the correct number of backslashes when you combine path components: $part1 = ' C:\somefolder\ ' $part2 = ' \myfile...
  • 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...
1 2 3 4 5 Next > ... Last »
Copyright 2012 PowerShell.com. All rights reserved.