No code in this post, just a pointer to a great free resource for learning PowerShell. The Microsoft Virtual The Microsoft Virtual Academy. There are a couple of couple of courses I can recommend; one for general PowerShell learning and one for those using PowerShell in Enterprises.
Getting Started with PowerShell 3.0 Jump Start is a good starting point, even though version 3 is no longer the most recent version.
Using PowerShell for Active Directory is aimed at helping those familiar with PowerShell to use their skills automating AD tasks.
There are a number of other courses available for PowerShell on the site, as well as a whole host of other Microsoft technologies.