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

Power Tips

Power Tips

Syndication

  • Bulk Creating AD Users from Excel Sheets

    Module ActiveDirectory To create a large number of new Active Directory users, you can import the user data from a CSV file, for example export an Excel sheet to CSV. Next, this piece of code will turn the CSV data into real Active Directory user accounts...
  • Removing AD Group Members

    Module ActiveDirectory To remove one or many users from an Active Directory group, try this approach: $user = @ () $user += Get-ADUser -Filter { Name -like ' H* ' } $user += Get-ADUser -Filter { Name -like ' *ll* ' } $user . Name Remove...
  • Steps to Configure PowerShell (Part 3)

    All PowerShell versions If you use PowerShell at home or in an environment without central group policy management, here are some additional steps you should consider to make PowerShell fully functional. To use the PowerShell remoting feature against...
  • Steps to Configure PowerShell (Part 1)

    PowerShell 2.0 and later If you use PowerShell at home or in an unmanaged environment, here are some steps you should consider to make PowerShell fully functional. To check out the PowerShell version you use, try this: PS> $PSVersionTable.PSVersion...
  • NULL Values in Arrays

    All PowerShell versions Whenever you assign NULL values to array elements, they will count as array elements, but will not be output (after all, they are NULL aka nothing). This can lead to tough debugging situations, so when the size of an array does...
  • 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...
« First ... < Previous 3 4 5 6 7 Next > ... Last »
Copyright 2012 PowerShell.com. All rights reserved.