Introduction to Powershell Version 5
-
Upload
nishtha-kesarwani -
Category
Technology
-
view
56 -
download
3
Transcript of Introduction to Powershell Version 5
![Page 1: Introduction to Powershell Version 5](https://reader036.fdocuments.in/reader036/viewer/2022062306/58e980751a28aba6498b5035/html5/thumbnails/1.jpg)
MicrosoftPowershell v5
Presented By:Nishtha Kesarwani
![Page 2: Introduction to Powershell Version 5](https://reader036.fdocuments.in/reader036/viewer/2022062306/58e980751a28aba6498b5035/html5/thumbnails/2.jpg)
AgendaWhat is Powershell ?
Working with Powershell
Cmdlets
Scripting in Powershell
Powershell Classes
![Page 3: Introduction to Powershell Version 5](https://reader036.fdocuments.in/reader036/viewer/2022062306/58e980751a28aba6498b5035/html5/thumbnails/3.jpg)
What is Powershell Task automation and
configuration management framework
Interactive object-oriented command line shell
Interactive editor Scripting language Based on .Net Framework Access to COM and WMI Both local and remote
![Page 4: Introduction to Powershell Version 5](https://reader036.fdocuments.in/reader036/viewer/2022062306/58e980751a28aba6498b5035/html5/thumbnails/4.jpg)
How to install Powershell in Mac https://github.com/PowerShell/PowerShell http://www.howtogeek.com/267858/how-to-install-microsoft-po
wershell-on-linux-or-os-x/
![Page 5: Introduction to Powershell Version 5](https://reader036.fdocuments.in/reader036/viewer/2022062306/58e980751a28aba6498b5035/html5/thumbnails/5.jpg)
Working with Powershell
Cmdlets
Scripts
Classes
![Page 6: Introduction to Powershell Version 5](https://reader036.fdocuments.in/reader036/viewer/2022062306/58e980751a28aba6498b5035/html5/thumbnails/6.jpg)
Cmdlets Heart-and-Soul of Windows
PowerShell Written in .Net framework
language PowerShell cmdlets use the
Verb-Noun format as in Get-Service, Stop-Service, or Import-Csv
![Page 7: Introduction to Powershell Version 5](https://reader036.fdocuments.in/reader036/viewer/2022062306/58e980751a28aba6498b5035/html5/thumbnails/7.jpg)
Difference between cmdlets and commands Instances of .NET Framework classes; they are not stand-alone
executables. Can be created from as few as a dozen lines of code. Parsing, error presentation, and output formatting are handled
by the Windows PowerShell runtime. Process input objects from the pipeline rather than from
streams of text Deliver objects as output to the pipeline. Cmdlets are record-oriented as they process a single object at
a time.
![Page 8: Introduction to Powershell Version 5](https://reader036.fdocuments.in/reader036/viewer/2022062306/58e980751a28aba6498b5035/html5/thumbnails/8.jpg)
5 cmdlets to get started with Powershell
Get-CommandGets all commands that are installed on the computer
Get-HelpHelp describe powershell cmdlets, functions, scripts and modules
Get-MemberGets the members, the properties and methods of objects
Get-ProcessGets the processes on a local or remote computer
Where-ObjectFilter input from the pipeline and control which objects will be passed along
![Page 9: Introduction to Powershell Version 5](https://reader036.fdocuments.in/reader036/viewer/2022062306/58e980751a28aba6498b5035/html5/thumbnails/9.jpg)
Get-Help
![Page 10: Introduction to Powershell Version 5](https://reader036.fdocuments.in/reader036/viewer/2022062306/58e980751a28aba6498b5035/html5/thumbnails/10.jpg)
Scripting in Powershell Script file in Powershell is a plain-text file with .PS1 extension Supports variables, functions, branching, loops, structured
error/exception handling as well as integration with .NET Fundamental Concepts
Pipelining Pipelining is the term for feeding one command's output into
another command, to pipeline two commands (or cmdlets), simply separate them with the pipe symbol (|)
Variables Can store a command's full output, variables in PowerShell
scripts are prefixed with $ @ symbol
This symbol can turn the contents of a list into an array
![Page 11: Introduction to Powershell Version 5](https://reader036.fdocuments.in/reader036/viewer/2022062306/58e980751a28aba6498b5035/html5/thumbnails/11.jpg)
Set-Execution Policy
Restricted : Scripts won't run
RemoteSigned : Locally-created scripts will run
AllSigned : Scripts will only run if signed by a trusted publisher
Unrestricted : All scripts will run regardless of who created them and whether or not they are signed
![Page 12: Introduction to Powershell Version 5](https://reader036.fdocuments.in/reader036/viewer/2022062306/58e980751a28aba6498b5035/html5/thumbnails/12.jpg)
Script Example $colItems = get-wmiobject -class "Win32_Printer" -namespace "root\CIMV2" -computername $strComputer
![Page 13: Introduction to Powershell Version 5](https://reader036.fdocuments.in/reader036/viewer/2022062306/58e980751a28aba6498b5035/html5/thumbnails/13.jpg)
Powershell Classes Class
Definition of a template for creating objects. The class can define properties (data fields) and methods (the way to perform a task)
Object An object is created from a class definition. New-
Object cmdlet is used to create an object Module
A PowerShell module is a .psm1 file that contains one, or more, PowerShell functions – usually advanced functions.
![Page 14: Introduction to Powershell Version 5](https://reader036.fdocuments.in/reader036/viewer/2022062306/58e980751a28aba6498b5035/html5/thumbnails/14.jpg)
Class Syntax Class <Class_Name> { #Properties <Data_Type> $<Variable_Name> } #Methods [Return Type] <Method_Name> { # Script } #Creating an object $<Object_Name> = New-Object –TypeName <Class_Name> #Calling a method <Object_Name>.<Method_Name>()
![Page 15: Introduction to Powershell Version 5](https://reader036.fdocuments.in/reader036/viewer/2022062306/58e980751a28aba6498b5035/html5/thumbnails/15.jpg)
Class Exampleclass Person {#Properties [string]$lastName [string]$firstName#Methods [void] SetLast ( [string]$ln ) { $this.lastName = $ln }[string] ToString ( [String]$firstName, [String]$lastName ) { return $firstName + " " + $lastName }}# end class Person
![Page 16: Introduction to Powershell Version 5](https://reader036.fdocuments.in/reader036/viewer/2022062306/58e980751a28aba6498b5035/html5/thumbnails/16.jpg)
Summary Powershell is a task automation tool built on .Net framework with
interactive command line shell and editor Scripting language designed specially for administrative tasks Built-in Windows PowerShell commands, called cmdlets, that allows
us to manage the computers from the command line 5 basic cmdlets to get started with Powershell Powershell script files have a .PS1 extension Scripting in Powershell supports pipelining and can handle functions,
branching, loops and exception handling Execution Policy for running scripts in Powershell for avoiding
malicious code execution Powershell classes contains properties and methods; Objects can be
created with New-Object cmdlet
![Page 17: Introduction to Powershell Version 5](https://reader036.fdocuments.in/reader036/viewer/2022062306/58e980751a28aba6498b5035/html5/thumbnails/17.jpg)
Resources https://msdn.microsoft.com/en-us/powershell/scripting/core-po
wershell/ise/introducing-the-windows-powershell-ise https://blogs.technet.microsoft.com/heyscriptingguy/2015/01/0
2/what-is-powershell/ https://msdn.microsoft.com/en-us/library/ms714395(v=vs.85).
aspx http://www.howtogeek.com/114344/5-cmdlets-to-get-you-start
ed-with-powershell/ https://technet.microsoft.com/en-us/library/cc732114(v=ws.10).aspx https://technet.microsoft.com/en-us/scriptcenter/dd742419
![Page 18: Introduction to Powershell Version 5](https://reader036.fdocuments.in/reader036/viewer/2022062306/58e980751a28aba6498b5035/html5/thumbnails/18.jpg)