Codementor Events

Why you should learn PowerShell?

Published Sep 11, 2017Last updated Sep 12, 2017
Why you should learn PowerShell?

The answer to that question is obviously YES.

So why should you learn PowerShell?

Simple Answer would be that it would make your life as a Windows IT Admin a lot easier.

This article is intended for people who (Fresher’s or Experience) don't think PowerShell is that important to learn or some who are not learning because they don't know much about PowerShell or some who think learning PowerShell is going to be very difficult and complicated because they don't have any prior knowledge about any scripting language.

First, I am not writing this article to teach you PowerShell or how to use it, the intention is to let you know, why it is important to learn PowerShell. And maybe once you understand the advantage of learning PowerShell, I hope maybe then you will try to learn PowerShell.

PowerShell is Important to learn even if you are New or an Experience Windows IT Admin. Couple of years ago learning PowerShell was an option but today it is important, in the future it going to be really necessary. Nearly every Microsoft Product use PowerShell and some heavily relies on PowerShell like Exchange Server. PowerShell is available for Windows Server, SQL Server, SharePoint, Exchange Server, Azure, Office 365, Hyper-V & Nano Server. And in order to configure or manage Nano Server, you need to know PowerShell. It is also available for Non Microsoft Products like VMware vSphere, Dell, Linux, Cisco, Amazon Web Service Cloud (AWS). Microsoft current Products and even future Products will have PowerShell.

Anything you do in Exchange Server via GUI, it is actually running PowerShell Cmdlet in the background. Exchange Server Manager Console is just GUI front-end to PowerShell.

When you create New Mailbox via GUI, the Mailbox is actually created via PowerShell New-Mailbox Cmdlet.

AAEAAQAAAAAAAAhTAAAAJDQ1NmQ5ZWRjLTAyZDgtNGFhOS1hNTA3LTBkYjc2NGY3ZWIxYw.png

Even Active Directory Administrative Centre does the same thing, the GUI is built on top of Windows PowerShell.

As you can see in the Image below, when you reset the password for a User via GUI, it is actually running the PowerShell Set-ADAccountPassword Cmdlet.

AAEAAQAAAAAAAAl0AAAAJDE1MjBkZTMxLWE1YWUtNGE3Ni05MjIzLTU2MmRkZTE5ODljZg.jpg

So if you could master or even became really good at PowerShell, you could a lot more things quickly and efficiently then you are doing currently using GUI. Microsoft is clearly pointing it out plain and simple that you have to learn PowerShell, it's not an option anymore.

Most of the task when done via GUI could take lot of time. 

One of my collegue had a simple task, the Company where he worked wanted to add their Employees Contact number in Active Directory. So he had a excel file with the Employees SamAccountName & Mobile number, so all he had to do was open AD Users & Computers then right click on that User & Select Properties then click on Telephones Tab and then simply enter their Mobile Number then check if you have entered it correctly and then press Apply and OK. Simple thing to do but there was a small problem, he had to do that same process nearly 6000 times. Another problem was that they had nearly 6000 Users but he didn't get the list of all users, he got a list of around 600 Users list first. The problem was that the list which had the Users were not from one OU, Users were from multiple OU.

If he had knowledge about PowerShell then for him this would have been a simple task.

How?

Some might understand this, some might not.

All he had to do was save that Excel file as CSV file.

CSV File format - Header: - SamAccountName & Mobile

SamAccountName, Mobile
User01,1234567890
User02,0987654321
...
User600,3219876540

Then run this Command.

Import-Csv -Path D:\Users.Csv | Foreach-Object 
{
  Set-ADUser -Identity $_.SamAccountName -Add @{Mobile = $_.Mobile}
}

I have created 11,000 Dummy Account in my Test Lab. And I am updating all Users Mobile Attribute. Tested on Windows Server 2012 R2 using PowerShell v4.

It only took nearly 4 minute to update all Users Mobile Attribute.

AAEAAQAAAAAAAAiIAAAAJDhlMzM2ZjY5LWRiZGItNDMzNy04ZTdlLWY5ODM4Mzc1MGMxNw.jpg

And what if some User Mobile number was 9 (or less) digit instead 10 or it was 11.

He could write a simple PowerShell Script to do this too.

This script would first check the csv file where the Users Mobile number is less than 10 or greater than 10 digit. And if it does then it would create a new Csv file named IncorrectNumber, this file would contains the list of users whose mobile number were incorrect.

Import-Csv D:\Users.csv | ForEach-Object 
{
  If ($_.Mobile.Length -lt 10 -or $_.Mobile.Length -gt 10) 
  {
       $_ | Export-Csv D:\IncorrectNumber.csv -Append
  }
  Else 
  {
       Set-ADUser -Identity $_.SamAccountName -Add @{Mobile = $_.Mobile}
  }
}

Some PowerShell Examples:

Search AD User whose Password has not been set for the past 90 days.

Get-ADUser -Filter "PasswordLastSet -lt '$($(Get-Date).AddDays(-90))'" -Properties PasswordLastSet | Select Name,PasswordLastSet

Search Disabled AD Users Account and move those Users to a Disabled OU.

Search-ADAccount -UsersOnly -AccountDisabled | ForEach-Object 
{
  Move-ADObject -Identity $_ -TargetPath 'ou=disabled,dc=test,dc=org'
}

Get the last update from one or more Computers.

Get-ADComputer -Filter * -SearchBase 'ou=servers,dc=test,dc=org' | ForEach-Object
{
  Get-WinEvent @{Logname='System';ID=19;ProviderName='Microsoft-Windows-WindowsUpdateClient'} -ComputerName $_.Name | Select-Object -First 1
}

Check if any specified Service is running and if not then start that Service from one or more Computers.

Get-ADComputer -Filter * | ForEach-Object 
{
    $Service = Get-Service Dnscache
    If ($Service.Status -eq 'Running') 
    {
        Write-Host "$($Service.Name) is running"
    }
    Else 
    {
        Start-Service $Service
        Write-Host "$($Service.Name) is Started"
    }
}

The most Important Cmdlet in PowerShell is Get-Help

Get-Help Get-Help -Full
Get-Help Get-Service -Detailed
Get-Help Get-Process -Examples

As you can see, Learning PowerShell will be great for your career.

Thanks for Reading.

Some Links if you want to Learn PowerShell.
PowerShell Video Training from Microsoft
PowerShell.org Youtube
Microsoft Virtual Academy
Windows PowerShell Scripting - Technet

Discover and read more posts from Vincent K
get started
post commentsBe the first to share your opinion
Show more replies