powershell slides

Post on 12-Apr-2017

520 Views

Category:

Documents

1 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 1

What’s PowerShell• Scripting Environment• Scripting Language• Windows equivalent of UNIX Shell Script (but even more powerful)

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 2

Interactive Shell

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 3

History

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 4

Versions

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 5

.Net Framework

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 6

Installing the latest versionhttps://www.microsoft.com/en-us/download/details.aspx?id=46889

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 7

ISE – The PowerShell IDE

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 8

Case InsensitiveGet-serviceget-serviceGet-Service

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 9

Installing/Accessing PowerShell

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 10

Updating the help in PowerShell

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 11

Get help in PowerShellGet-Help

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 12

Execution Policy

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 13

Get & Set CmdletsGet-<Command>Set-<Command>

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 14

Comments

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 15

Writing to Console

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 16

Clear Screen

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 17

Aliases

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 18

Variables

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 19

Data types

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 20

Pipelining

.Net objects passed down the pipeline

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 21

Listing directory Contents

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 22

Recursive listing

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 23

ErrorAction SilentlyContinue

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 24

Looping using Foreach-Object

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 25

Filtering using Where-Object

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 26

Sorting using Sort-Object

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 27

PowerShell v/s UNIX Shell

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 28

Assignment Operators=+=-=*=/=%=++--

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 29

Comparison Operators-eq-ne-gt-ge-lt-le-replace-contains-notcontains-in-notin-match-notmatch-like-notlike

-is-isnot-as

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 30

Comparison Operators: -eq, -ne

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 31

Comparison Operators: -gt, -ge

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 32

Comparison Operators: -lt, -le

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 33

Comparison Operators: -replace

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 34

Comparison Operators: -contains, -notcontains

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 35

Comparison Operators: -in, -notin

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 36

Comparison Operators: -match, -notmatch

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 37

Comparison Operators: -like, -notlike

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 38

Comparison Operators: -is, -isnot

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 39

Comparison Operators: -as

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 40

Logical Operators

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 41

Split, Join, foreach

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 42

Casting

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 43

Redirection Operators

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 44

Handling arrays

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 45

Dictionary/hash tables

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 46

Object Properties

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 47

Object Methods

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 48

String manipulation

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 49

Sorting Objects

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 50

PowerShell automatic variables

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 51

Searching filesystem using PS

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 52

Getting System processes

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 53

Getting list of services

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 55

Copying files/directories

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 56

Reading from file

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 57

Writing to file

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 58

Appending to a file

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 59

Deleting file/directory

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 60

Renaming a file/directory

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 61

Reading from Excel

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 62

Reading from CSV

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 63

Writing to CSV

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 64

Writing to Excel

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 65

Export-CSV

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 66

Reading large files

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 67

Exporting as CSV

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 68

Importing CSV

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 69

Appending to file

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 70

User defined Functions

http://windowsitpro.com/windows/create-your-own-powershell-functions

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 71

Param in functions

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 72

Passing parameters to functions

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 73

Parameters from Pipeline

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 74

Error Handling

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 75

Logging Error

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 77

Output formattinghttps://technet.microsoft.com/en-us/library/dd347677.aspx

https://technet.microsoft.com/en-us/magazine/2008.06.windowspowershell.aspx

http://www.computerperformance.co.uk/powershell/powershell_format_table.htm

http://www.computerperformance.co.uk/powershell/powershell_-f_format.htm

http://blogs.technet.com/b/heyscriptingguy/archive/2011/02/23/format-powershell-output-with-an-easy-to-use-table.aspx

http://windowsitpro.com/powershell/powershell-basics-formatting

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 78

Advanced formatting

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 79

Redirecting formatted output

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 80

Modules

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 81

Navigating the Registry

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 82

Regex

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 83

Starting a new Job

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 84

WMI• Windows Management Interface• Created by Microsoft• Is Microsoft’s implementation of CIM• CIM is the super class for WMI. Eq Win32_DiskDrive is derived from CIM_DiskDrive• Doesn’t work with the routers, switches or other network devices• Doesn’t support discoverabilty

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 85

WMIhttp://blogs.technet.com/b/heyscriptingguy/archive/2009/08/05/hey-scripting-guy-can-windows-powershell-call-wmi-methods.aspx

http://www.computerperformance.co.uk/powershell/powershell_wmi.htm

http://www.darkoperator.com/blog/2013/2/6/introduction-to-wmi-basics-with-powershell-part-2-exploring.html

http://www.lazywinadmin.com/2015/03/standard-and-advanced-powershell.html

WMI Administrative Toolshttp://www.microsoft.com/en-us/download/details.aspx?id=24045

Windows COM (Component Object Model)

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 86

WMI ExplorerDownload WMI Explorer from https://wmie.codeplex.com/

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 87

WQL (WMI Query Language)

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 88

CIM• Common Information Model• Set up by DTMF (Desktop Management Task Force)• http://www.dmtf.org/standards/cim• An open model compared to WMI• Common model for managing systems, switches, routers and other n/w

devices• Enables extension of the API by vendors• The goal is to make PowerShell the platform to manage both windows & non-

windows • Faster than WMI

“CIM provides a common definition of management information for systems, networks, applications and services, and allows for vendor extensions. CIM’s common definitions enable vendors to exchange semantically rich management information between systems throughout the network.”

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 89

PS Provider• Its an interface• It makes any storage look like a disk drive

• Could be filesystem, registry• Providers are used to create drives

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 90

https://technet.microsoft.com/en-us/library/ee126186(v=vs.85).aspx

https://technet.microsoft.com/en-us/library/dd315335.aspx

https://technet.microsoft.com/en-us/library/ee176857.aspx

PS Provider

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 91

PS DriveA PowerShell Drive is some sort of a storage adapted to look like a disk drive

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 92

PS Drive

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 93

New-PSDrive

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 94

Administration Automation

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 95

Connecting to SQL Server

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 96

Creating Database, Tables in SQL

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 97

Importing data into SQL Server

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 98

Connecting to Remote machines

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 99

Importing libraries

Varun Varghese +91 9986599326 varunmuriyanat@gmail.com 100

OOP in PowerShellhttps://psclass.codeplex.com/

top related