Monday 30 May 2016

PowerShell basis : frequently used commandlets (cmdlets)

PowerShell is scripting languages which is introduced in 2003 by Microsoft introduced.
it is an advanced automation-script language which replaces legacy DOS batch files. 

 Now a days Powershell is so famous and being used by several windows Administrators, IT Professionals, Network Admins and by different Developers of Microsoft Products.

Let's get started with some examples of using PowerShell to perform some tasks. There are around thousands of PowerShell commends used by IT, Network, SharePoint,Windows developers and Admins. To Run and execute PowerShell cmdlets, you must have appropriate permissions to execute the PowerShell commands on system.

You can load different library of C#/.net libraries (Snapin) to your session to run commands to send email, try catch exception handling logging errors, sending alert emails with attachments create interactive UI like windows forms and so many more things, by default same basis commands can be executed.

PowerShell is open source, you can run PowerShell on Linux and Mac OS X environments. Download and setup instructions are available.
 
To Start with PowerShell Yeah: lets start with me, go to strat type powershell you will get below result  that may vary based on your system version/theme








  
The first option in above screenshot is basic single command window to type and see output, second will give multi window to type see and run commands and output try both now.

Comparison Operators  in PowerShell –
  • -eq – Equals (==) to operator.
  • -lt –  Less than ( < )operator.
  • -gt – Greater than ( > )operator.
  • -le – Less than or equal to ( <= ).
  • -ge – Greater than or equal to ( >= ).
  • -like – pattern matching
lets have a basic comparison example

 $UserFirstname= "Praveen";
 if($UserFirstname -eq “Praveen”)
{
Write-Host “We are working in PowerShell ” $UserFirstName
}
else
{
Write-Host “User name is ” $UserFirstname.
}



We will look more interesting and in more details in out next part "powershell-frequently-used-commandlets-PART-2"


Some basics things you may want to know
  • Variable type need not to define.
  • Powershell cmdlets are case insensitive.
  • Commands cab be passed as input by using | (pipes) as we are using in bachfiles.
  • cmnlets can use aliases like cls is for Clear-Host, gc - Get-Content, ls - list.   
--