Arposh New User Creation tool comes out of beta!

With the impending start of the 2012 Scripting Games, I had the urge to script.  Thanks to that, the Arposh New User Creation tool has been updated and is now at version 1.0!

New in 1.0:
  • Updated to be compatible with PowerShell v3 Beta
  • Enter custom sAMAccountName, Display Name, and userPrincipalName in single-user and CSV modes
  • Turn off auto-generation of sAMAccountName, Display Name, and userPrincipalName in single-user mode
  • Better error-handling during user creation
  • Set new accounts as enabled or disabled
  • Set 'Password must change at logon' to enabled or disabled 
  • Minor bug fixes
To download the new release and see more information, check out the download page on the TechNet ScriptCenter.

PowerShell Training: Back to Basics



PowerShell is quickly taking over IT departments and with such big names behind it, it’s no wonder.  If you already use PowerShell, chances are that you have used a module or snap-in from one of the companies below:

Microsoft
VMware
NetApp
Cisco
Intel
Quest

For those not familiar with PowerShell, when they see how quickly or easily things can be configured or automated, they of course want to get in on the action.  So how do you go about introducing someone to PowerShell and make them self-sufficient?  You give them a link to www.ScriptingGuys.com and tell them to study up. But what if I am giving them an in-person demo?  I show them my guide to using PowerShell for the first time and then usually start out with these five* commands:

Get-Command

The first thing that people usually want to know is, ‘What can I do with PowerShell?’  At that point, I load up the console and tell them to type in Get-Command.  A long list of available cmdlets starts scrolling by and you can see their eyes light up.  Once they find a cmdlet that interests them (there always is and most of the time it has to deal with a current issue they are facing), I move on to the next command.

Get-Help

This is my go-to command; I use it more often than any other.  If I ever come across a command that I want to use, but don’t know how, Get-Help is my first stop.  To see more details for a cmdlet, you can use one of the following:

Get-Help -Examples
Get-Help -Detailed
Get-Help -Full
Get-Help -Online

I’ve found that the –Examples switch is the best for beginners, as it gives them an idea of what can be done with the command and lists the information that they need to accomplish the task.  With these two cmdlets, they have more than enough to get started and get some work done.  Once they have had a little bit of practice, I continue on with where it gets really interesting, modules!

Get-Module / Import-Module

As with most IT professionals, you and the trainee have probably worked with a technology from at least one of the companies listed at the beginning of this post.  Did you know that they all provide PowerShell modules or snap-ins that help you automate their products?  To view all modules that are available on your machine, just type Get-Module –ListAvailable at the PowerShell console and you should see a list of each one available and the commands included.  If you were looking for one of the modules from a vendor listed above, be sure to download and install it first, then re-run the Get-Module cmdlet.  Once the modules are installed, you can import them using Import-Module .  Now you can use the commands you learned previously to view each of the cmdlets available in the module and their usage:

Get-Command –Module

Note: Some of the vendors are still providing their cmdlets in snap-ins, which is legacy for PowerShell v1.0.

Get-Member or Format-List

At this point, the trainee should have a general understanding of what PowerShell is and how to use it.  Depending on the background of the person, I tailor the last section for their professional background.  For anyone with a developer background, I typically show them Get-Member, as it shows them all of the methods, properties and other membertypes, which they are familiar with seeing.  For the IT Pros learning PowerShell, I typically stick with Format-List.  This gives them the information system administrators and technicians are looking for and when they are more comfortable, I loop back and show them Get-Member.

And that wraps up my beginner’s guide for PowerShell.  You provide the who and why and I provide the what and how.  ‘When’, you say?  The time for PowerShell is NOW!

Resources:
  1. Popular PowerShell Modules 
  2. Windows Features/Roles that use PowerShell 
  3. PowerShell-enabled technologies

Using PowerShell for the First Time

So you want to use PowerShell for the first time and you can’t figure out where to start.  You right-click on a PowerShell script that you downloaded from the internet and you are prompted with a security warning, or maybe you see some error messages and then the PowerShell window disappears.  Here are some simple advice to make sure your first PowerShell expedition is a successful one.

Make sure you are using the latest version of PowerShell

The PowerShell team has a great blog post which lists all available versions of PowerShell and related downloads.  If you are using Windows 7 or Server 2008 R2, you already have PowerShell 2.0 installed, but if you are using a previous OS, you will need to download the most recent version.  As of this posting, the latest production release is v2.0, which requires .Net Framework Version 2.0 to be installed.  It is recommended to install .Net Framework Version 3.5 SP1, as this is required for the Integrated Scripting Environment (ISE) and graphical cmdlets.

Opening the PowerShell console

There are numerous ways to access the PowerShell console (when installed) and I’ll list just a few of them for you here.

  • Taskbar
    • An icon that looks like a blue square with >_ in white lettering
    • Windows 7 and Server 2008 R2 (by default)
  • Start Menu
    • Start > Programs > Accessories > Windows PowerShell > Windows PowerShell
    • Windows XP/Vista/7 and Server 2003/2008/2008R2
  • Windows Explorer
    • C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
    • Windows XP/Vista/7 and Server 2003/2008


Configure the Execution Policy for PowerShell

Configuring the PowerShell execution policy requires access to a user account that has local administrator rights to the system that you wish to configure.  To begin the process, locate the PowerShell executable at one of the locations listed above, right-click the icon and select ‘Run As Administrator’.  If UAC is enabled, you will be required to accept a security warning.  You should now have a blue PowerShell console with a title of ‘Administrator: Windows PowerShell’.  To see the current execution policy, you can use the Get-ExecutionPolicy cmdlet.  In a default install of PowerShell, the value Restricted will be returned. To change the policy, use the Set-ExecutionPolicy cmdlet. 

For more information on available execution policies and how your system will be affected, you can read the about_Execution_Policies documentation.

Microsoft Community Contributor Award

Hi again everyone.  Just stopping by to give some good news.  I was awarded as a Microsoft Community Contributor for 2012!  Although they don't go into great detail as to what you were awarded for, I'm assuming that it was for my contributions to all aspects of TechNet (forums, gallery, wiki and blogs).  Here is my shiny new MCC logo:



Click this link to check out my TechNet profile and see my contributions.

PowerShell range operator: real-world examples

The beauty of PowerShell is how it includes little tidbits that seem so simple but can make your job much easier.  One example of this is the range operator '..'  I have run into multiple occasions where it came in handy and kept me from having to use an external program or perform manual steps.

For example, if I wanted to find an available IP address within a subnet, I could load a network scanning tool or use this one-liner in PowerShell:

    1..255 | %{Test-Connection 192.168.1.$_ -Count 1}

The above line will ping all IP addresses in the 192.168.1 subnet.  On a similar note, if I had seven test machines that I wanted to open an RDP session with I could use the following one-liner:

    1..7 | %{mstsc /v:QA$_}

The command above would open an RDP session with machines QA1 through QA7.  This next example isn't so much a real-world example but was a question that a PowerSheller was confronted with in an interview.


With a little knowledge of ASCII characters, I could create an array of uppercase characters and compare it against the first letter of each line as it was piped in via Get-Content.

    Get-Content file.txt | ?{(65..90 | %{[Char]$_}) -contains $_[0]}

While this approach is not the most economical when it comes to scaling, it suits the purpose for a quick interview question.  

My last example is one that allows you to test out your command on a subset of items before releasing the hounds on the whole array, so to say.

    $VM = Get-VM
    $VM[0] | Move-VM -Datastore DS02
    $VM[1..$VM.Count] | Move-VM -Datastore DS02

The example above uses the PowerCLI snapin from VMware.  The first line retrieves all of your VMs and stores them in the $VM variable.  Before you move all of the VMs to the new datastore in bulk, you can grab the first VM in the array and move it as a test.  If the test is successful, you can then run the same command with a slight modification to move the rest.  Using the 1..$VM.Count range operator allows you to count the total number of VMs in your array and move all of them to the new datastore, while skipping over the one that you already moved.

And there you have it, a few examples of what you can do to save yourself some time with just a simple feature as a range operator.

Interview with a Wiki Ninja

(Hint: it's me!)

Thanks to Ed Price and the TechNet Wiki Ninjas who decided to interview me on their blog!  I'm honored to be added to an impressive list of community contributors on the TechNet site.  I hope to be able to continue contributing in the future and promote the TechNet and PowerShell communities. A link to the interview is below:

Interview with a Wiki Ninja: Rich Prescott, MCC - PowerShell & Windows Engineering

Be sure to check out the comments for additional interview questions!

Guest Article on Microsoft's Hey Scripting Guy blog

Hi Everyone!

Just stopping by to let you know I was featured on Microsoft's Hey Scripting Guy blog with an article discussing the Microsoft community and how you can benefit from it.  Check it out!

-Rich