powershell slides
TRANSCRIPT
Varun Varghese +91 9986599326 [email protected] 1
What’s PowerShell• Scripting Environment• Scripting Language• Windows equivalent of UNIX Shell Script (but even more powerful)
Varun Varghese +91 9986599326 [email protected] 2
Interactive Shell
Varun Varghese +91 9986599326 [email protected] 3
History
Varun Varghese +91 9986599326 [email protected] 4
Versions
Varun Varghese +91 9986599326 [email protected] 5
.Net Framework
Varun Varghese +91 9986599326 [email protected] 6
Installing the latest versionhttps://www.microsoft.com/en-us/download/details.aspx?id=46889
Varun Varghese +91 9986599326 [email protected] 7
ISE – The PowerShell IDE
Varun Varghese +91 9986599326 [email protected] 8
Case InsensitiveGet-serviceget-serviceGet-Service
Varun Varghese +91 9986599326 [email protected] 9
Installing/Accessing PowerShell
Varun Varghese +91 9986599326 [email protected] 10
Updating the help in PowerShell
Varun Varghese +91 9986599326 [email protected] 11
Get help in PowerShellGet-Help
Varun Varghese +91 9986599326 [email protected] 12
Execution Policy
Varun Varghese +91 9986599326 [email protected] 13
Get & Set CmdletsGet-<Command>Set-<Command>
Varun Varghese +91 9986599326 [email protected] 14
Comments
Varun Varghese +91 9986599326 [email protected] 15
Writing to Console
Varun Varghese +91 9986599326 [email protected] 16
Clear Screen
Varun Varghese +91 9986599326 [email protected] 17
Aliases
Varun Varghese +91 9986599326 [email protected] 18
Variables
Varun Varghese +91 9986599326 [email protected] 19
Data types
Varun Varghese +91 9986599326 [email protected] 21
Listing directory Contents
Varun Varghese +91 9986599326 [email protected] 22
Recursive listing
Varun Varghese +91 9986599326 [email protected] 23
ErrorAction SilentlyContinue
Varun Varghese +91 9986599326 [email protected] 24
Looping using Foreach-Object
Varun Varghese +91 9986599326 [email protected] 25
Filtering using Where-Object
Varun Varghese +91 9986599326 [email protected] 26
Sorting using Sort-Object
Varun Varghese +91 9986599326 [email protected] 27
PowerShell v/s UNIX Shell
Varun Varghese +91 9986599326 [email protected] 28
Assignment Operators=+=-=*=/=%=++--
Varun Varghese +91 9986599326 [email protected] 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 [email protected] 30
Comparison Operators: -eq, -ne
Varun Varghese +91 9986599326 [email protected] 31
Comparison Operators: -gt, -ge
Varun Varghese +91 9986599326 [email protected] 32
Comparison Operators: -lt, -le
Varun Varghese +91 9986599326 [email protected] 33
Comparison Operators: -replace
Varun Varghese +91 9986599326 [email protected] 34
Comparison Operators: -contains, -notcontains
Varun Varghese +91 9986599326 [email protected] 35
Comparison Operators: -in, -notin
Varun Varghese +91 9986599326 [email protected] 36
Comparison Operators: -match, -notmatch
Varun Varghese +91 9986599326 [email protected] 37
Comparison Operators: -like, -notlike
Varun Varghese +91 9986599326 [email protected] 38
Comparison Operators: -is, -isnot
Varun Varghese +91 9986599326 [email protected] 39
Comparison Operators: -as
Varun Varghese +91 9986599326 [email protected] 40
Logical Operators
Varun Varghese +91 9986599326 [email protected] 41
Split, Join, foreach
Varun Varghese +91 9986599326 [email protected] 42
Casting
Varun Varghese +91 9986599326 [email protected] 43
Redirection Operators
Varun Varghese +91 9986599326 [email protected] 44
Handling arrays
Varun Varghese +91 9986599326 [email protected] 45
Dictionary/hash tables
Varun Varghese +91 9986599326 [email protected] 46
Object Properties
Varun Varghese +91 9986599326 [email protected] 47
Object Methods
Varun Varghese +91 9986599326 [email protected] 48
String manipulation
Varun Varghese +91 9986599326 [email protected] 49
Sorting Objects
Varun Varghese +91 9986599326 [email protected] 50
PowerShell automatic variables
Varun Varghese +91 9986599326 [email protected] 51
Searching filesystem using PS
Varun Varghese +91 9986599326 [email protected] 52
Getting System processes
Varun Varghese +91 9986599326 [email protected] 53
Getting list of services
Varun Varghese +91 9986599326 [email protected] 54
Filtering objectshttps://technet.microsoft.com/en-us/magazine/2007.04.powershell.aspx
http://windowsitpro.com/powershell/powershell-basics-filtering-objects
http://www.howtogeek.com/138324/geek-school-learning-formatting-filtering-and-comparing-in-powershell/
http://searchwindowsserver.techtarget.com/feature/Filtering-output-from-Windows-PowerShell
Varun Varghese +91 9986599326 [email protected] 55
Copying files/directories
Varun Varghese +91 9986599326 [email protected] 56
Reading from file
Varun Varghese +91 9986599326 [email protected] 57
Writing to file
Varun Varghese +91 9986599326 [email protected] 58
Appending to a file
Varun Varghese +91 9986599326 [email protected] 59
Deleting file/directory
Varun Varghese +91 9986599326 [email protected] 60
Renaming a file/directory
Varun Varghese +91 9986599326 [email protected] 61
Reading from Excel
Varun Varghese +91 9986599326 [email protected] 62
Reading from CSV
Varun Varghese +91 9986599326 [email protected] 63
Writing to CSV
Varun Varghese +91 9986599326 [email protected] 64
Writing to Excel
Varun Varghese +91 9986599326 [email protected] 65
Export-CSV
Varun Varghese +91 9986599326 [email protected] 66
Reading large files
Varun Varghese +91 9986599326 [email protected] 67
Exporting as CSV
Varun Varghese +91 9986599326 [email protected] 68
Importing CSV
Varun Varghese +91 9986599326 [email protected] 69
Appending to file
Varun Varghese +91 9986599326 [email protected] 70
User defined Functions
http://windowsitpro.com/windows/create-your-own-powershell-functions
Varun Varghese +91 9986599326 [email protected] 71
Param in functions
Varun Varghese +91 9986599326 [email protected] 72
Passing parameters to functions
Varun Varghese +91 9986599326 [email protected] 73
Parameters from Pipeline
Varun Varghese +91 9986599326 [email protected] 74
Error Handling
Varun Varghese +91 9986599326 [email protected] 75
Logging Error
Varun Varghese +91 9986599326 [email protected] 76
Exception Handlinghttp://www.vexasoft.com/blogs/powershell/7255220-powershell-tutorial-try-catch-finally-and-error-handling-in-powershell
http://blogs.msdn.com/b/kebab/archive/2013/06/09/an-introduction-to-error-handling-in-powershell.aspx
http://blogs.technet.com/b/heyscriptingguy/archive/2014/07/09/handling-errors-the-powershell-way.aspx
Varun Varghese +91 9986599326 [email protected] 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 [email protected] 78
Advanced formatting
Varun Varghese +91 9986599326 [email protected] 79
Redirecting formatted output
Varun Varghese +91 9986599326 [email protected] 80
Modules
Varun Varghese +91 9986599326 [email protected] 81
Navigating the Registry
Varun Varghese +91 9986599326 [email protected] 82
Regex
Varun Varghese +91 9986599326 [email protected] 83
Starting a new Job
Varun Varghese +91 9986599326 [email protected] 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 [email protected] 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 [email protected] 86
WMI ExplorerDownload WMI Explorer from https://wmie.codeplex.com/
Varun Varghese +91 9986599326 [email protected] 87
WQL (WMI Query Language)
Varun Varghese +91 9986599326 [email protected] 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 [email protected] 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 [email protected] 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 [email protected] 91
PS DriveA PowerShell Drive is some sort of a storage adapted to look like a disk drive
Varun Varghese +91 9986599326 [email protected] 92
PS Drive
Varun Varghese +91 9986599326 [email protected] 93
New-PSDrive
Varun Varghese +91 9986599326 [email protected] 94
Administration Automation
Varun Varghese +91 9986599326 [email protected] 95
Connecting to SQL Server
Varun Varghese +91 9986599326 [email protected] 96
Creating Database, Tables in SQL
Varun Varghese +91 9986599326 [email protected] 97
Importing data into SQL Server
Varun Varghese +91 9986599326 [email protected] 98
Connecting to Remote machines
Varun Varghese +91 9986599326 [email protected] 99
Importing libraries
Varun Varghese +91 9986599326 [email protected] 100
OOP in PowerShellhttps://psclass.codeplex.com/