introduction to powershell version 5

18
Microsoft Powershell v5 Presented By: Nishtha Kesarwani

Upload: nishtha-kesarwani

Post on 09-Apr-2017

56 views

Category:

Technology


3 download

TRANSCRIPT

Page 1: Introduction to Powershell Version 5

MicrosoftPowershell v5

Presented By:Nishtha Kesarwani

Page 2: Introduction to Powershell Version 5

AgendaWhat is Powershell ?

Working with Powershell

Cmdlets

Scripting in Powershell

Powershell Classes

Page 3: Introduction to Powershell Version 5

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

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

Working with Powershell

Cmdlets

Scripts

Classes

Page 6: Introduction to Powershell Version 5

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

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

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

Get-Help

Page 10: Introduction to Powershell Version 5

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

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

Script Example $colItems = get-wmiobject -class "Win32_Printer" -namespace "root\CIMV2" -computername $strComputer

Page 13: Introduction to Powershell Version 5

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

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

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

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 18: Introduction to Powershell Version 5