Powershell Tutorial for Beginners: Learn in 1 Day

Powershell Tutorial,What is PowerShell?

Powershell Tutorial,Windows PowerShel is object-orientated automation engine and scripting language. It is designed specially for the system administrators. It facilitates IT, specialists, to manipulate & automate the management of the Window OS and different packages.

It delivered some compelling new principles that allow you to increase the

Powershell Tutorial,the information you have got gained and the scripts which you have created within the Windows Command Prompt and Windows Script Host environments.

It combines the flexibility of scripting, command-line speed, and the strength of a GUI-primarily based admin tool. It allows you to remedy issues efficiently by means of helping machine admin to remove destiny manual hard work hours. We will undergo all the critical issue that you need to realize to learn PowerShell.

In this training course, you will learn

  • What is PowerShell?
  • Why Use Powershell?
  • PowerShell History
  • Features of Powershell
  • How to launch PowerShell
  • PowerShell Cmdlet
  • Cmdlet vs Command:
  • Powershell Data types:
  • Special Variables
  • PowerShell Scripts
  • First PowerShell Script
  • What is PowerShell ISE?
  • PowerShell Concepts
  • PowerShell Vs Command Prompt
  • Applications of Powershell

This is a complete guide to PowerShell… let’s begin!

Powershell Tutorial,Why Use Powershell?

Here, are some important reason for using Powershell:

  • Powershell offers a well-integrated command-line experience for the operation system
  • PowerShell allows complete access to all of the types in the .NET framework
  • Trusted by system administrators.
  • PowerShell is a simple way to manipulate server and workstation components
  • It’s geared toward system administrators by creating a more easy syntax
  • PowerShell is more secure than running VBScript or other scripting languages

Powershell Tutorial,PowerShell History

PowerShell first model 1.0 became released in 2006. Today, PowerShell is at model 5.1. As the year and model long gone by using, PowerShell’s competencies and web hosting environments grew considerably.

Let See Version wise History of Powershell:

PowerShell version 1 supported the neighborhood administration of Windows Server 2003 PowerShell 2.Zero was incorporated with Windows 7 and Windows Server 2008 R2. This model helps for remoting and complements the competencies of PowerShell like transactions, background jobs, activities, debugging, and so forth.

PowerShell three.Zero become launched as an inner a part of the Windows control framework. It changed into mounted on Windows eight and Windows Server 2012. You can upload and scheduled jobs, session connectivity, automated module loading, and so on.

PowerShell 4.0 changed into shipped with Windows eight.1 and Windows Server 2012 R2. In this model delivered assist for desired nation configuration, superior debugging, network diagnostics.

PowerShell 5.Zero become launched as internal a part of Windows management framework five. The feature gives on this model are remote debugging, magnificence definitions, .NET enumerations, , and so on.

Powershell Tutorial,Features of Powershell

PowerShell Remoting: PowerShell permits scripts and cmdlets to be invoked on a far flung machine.

Background Jobs: It lets you invoked script or pipeline asynchronously. You can run your jobs either at the local system or multiple remotely operated machines.

Transactions: Enable cmdlet and allows builders to perform Evening: This command helps you to listen, forwarding, and performing on control and gadget occasions.

Network File Transfer: Powershell gives native guide for prioritized, asynchronous, throttled, transfer of files between machines using the Background Intelligent Transfer Service (BITS) technology.

Powershell Tutorial,How to launch PowerShell

PowerShell is pre-established in all latest versions of Windows. We need to release PowerShell for that we want to comply with the given steps:

Step 1) Search for PowerShell in Windows. Select and Click

Step 2) Power Shell Window Opens

PowerShell Cmdlet

A cmdlet which is likewise referred to as Command allow is a is a lightweight command used in the Window base PowerShell surroundings. PowerShell invokes those cmdlets within the command spark off. You can create and invoke cmdlets command the usage of PowerShell APIS.

Cmdlet vs. Command:

Cmdlets are different from commands in other command-shell environments in the following manners −

  • Cmdlets are .NET Framework class objects It can’t be executed separately
  • Cmdlets can construct from as few as a dozen lines of code
  • Parsing, output formatting, and error presentation are not handled by cmdlets
  • Cmdlets process works on objects. So text stream and objects can’t be passed as output for pipelining
  • Cmdlets are record-based as so it processes a single object at a time
  •  

Most of the PowerShell capability comes from Cmdlet’s that’s constantly in verb-noun format and now not plural. Moreover, Cmdlet’s return gadgets no longer textual content. A cmdlet is a series of commands, that’s multiple line, saved in a text document with a .Psl extension.

A cmdlet constantly includes a verb and a noun, separated with a hyphen. Some of the verbs use a good way to learn PowerShell is:

  • Get — To get something
  • Start — To run something
  • Out — To output something
  • Stop — To stop something that is running
  • Set — To define something
  • New — To create something
  •  

PowerShell instructions

Following is a list of essential PowerShell Commands:

Get-Help: Help about PowerShell instructions and topics

Example: Display help statistics approximately the command Format-Table

Get-Help Format-Table 

Get-Command: Get information about anything that can be invoked

Example: To generate a list of cmdlets, functions installed in your machine

Get-Command

Get-Service: Finds all cmdlets with the word ‘service’ in it.

Example: Get all services that begin with “vm”

Get-Service "vm*"

Get- Member: Show what can be done with an object

Example: Get members of the vm processes.

Get-Service "vm*" | Get-Member

Other Commands:

  • Get Module Shows packages of commands
  • Get Content This cmdlet can take a file and process its contents and do something with it
  • Get- get Finds all cmdlets starting with the word ‘get-

Example: Create a Folder

New-Item -Path 'X:\Guru99' -ItemType Directory

Output

Powershell Data types:

Special Variables

Special Variable Description
$Error An array of error objects which display the most recent errors
$Host Display the name of the current hosting application
$Profile Stores entire path of a user profile for the default shell
$PID Stores the process identifier
$PSUICulture It holds the name of the current UI culture.
$NULL Contains empty or NULL value.
$False Contains FALSE value
$True Contains TRUE value

Powershell Tutorial,PowerShell Scripts

Powershell scripts are store in .Ps1 file. By default, you can’t run a script with the aid of just double-clicking a document. This protects your machine from accidental damage. To execute a script:

Step 1: proper-click on it and click “Run with PowerShell.”

 

Moreover, there is a coverage which restricts script execution. You can see this policy by jogging the Get-ExecutionPolicy command.

You will get one of the following output:

Restricted— No scripts are allowed. This is the default setting, so it will show first time whilst you run the command. AllSigned— You can run scripts signed by means of a relied on developer. With the help of this putting, a script will ask for affirmation which you need to run it earlier than executing. RemoteSigned— You can run your or scripts signed via a depended on developer. Unrestricted— You can run any script which you desires to run Steps to Change Execution Policy

Step 1) Open an elevated PowerShell prompt. Right Click on PowerShell and “Run as Administrator”

 

Step 2) Enter the Following commands

  1. Get-ExecutionPolicy
  2. Set-execution policy unrestricted
  3. Enter Y in the prompt
  4. Get-ExecutionPolicy
  5.  

Powershell Tutorial,First PowerShell Script

In a notepad write the following command

Write-Host "Hello, Guru99!"

PowerShell Scripts have an extension ps1. Save the file as FirstScript.ps1

In Powershell, call the script using the command

& "X: Output.ps1"

PowerShell Concepts

Cmdlets Cmdlet are build-command written in .net languages like VB or C#. It allows developers to extend the set of cmdlets by loading and write PowerShell snap-ins.
Functions Functions are commands which is written in the PowerShell language. It can be developed without using other IDE like Visual Studio and devs.
Scripts Scripts are text files on disk with a .psl extension
Applications Applications are existing windows programs.
What if Tells the cmdlet not to execute, but to tell you what would happen if the cmdlet were to run.
Confirm Instruct the cmdlet to prompt before executing the command.
Verbose Gives a higher level of detail.
Debug Instructs the cmdlet to provide debugging information.
ErrorAction Instructs the cmdlet to perform a specific action when an error occurs. Allowed actions continue, stop, silently- continue and inquire.
ErrorVariable Tells the cmdlet to use a specific variable to hold the output information
OutVariable It specifies the variable which holds error information.
OutBuffer Instructs the cmdlet to hold the specific number of objects before calling the next cmdlet in the pipeline.

Advantages of using PowerShell script

  • PowerShell scripts are really powerful and could do much stuff in fewer lines.
  • Variables are declared in the form $<variable>
  • Variables could be used to hold the output of command, objects, and values.
  • “Type” of a variable need not be specified.

PowerShell Vs. Command Prompt

PowerShell Command Prompt
PowerShell deeply integrates with the Windows OS. It offers an interactive command line interface and scripting language. Command Prompt is a default command line interface which provided by Microsoft. It is a simple win32 application that can interact and talk with any win32 objects in the Windows operating system.
PowerShell uses what are known as cmdlets. It can be invoked either in the runtime environment or the automation scripts. No such features offer by command prompt.
PowerShell considers them as objects. So the output can be passed as an input to other cmdlets through the pipeline. Command Prompt or even the *nix shell, the output generated from a cmdlet is not just a stream of text but a collection of objects.
The PowerShell is very advanced regarding features, capabilities and inner functioning. Command prompt is very basic.

Powershell Tutorial,Applications of Powershell

Today, PowerShell has come to be a great choice for IT directors because it eases control operation and effort in large company networks. For instance, let’s anticipate which you are handling a large network which includes extra than 4 hundred servers. Now you need to implement a new safety solution. This protection answer relies upon on a sure carrier which wishes to run on the ones servers.

You can virtually log in to every server and spot in the event that they have that provider install and going for walks or no longer. However, it sincerely takes a whole lot of human errors as your staff needs to spend lots of time in this non-productive process.

However, in case you use PowerShell, then you could whole this undertaking in only a few mins. That’s because the entire operation is performed with a single script which gathers information approximately the offerings jogging on the servers.