Basic Powershell Scripting: Level 1

Basic Powershell Scripting: Level 1

Basic PowerShell Scripting: Level 1 What You Will Learn...................................................................................................................... 1 What is PowerShell ......................................................................................................................... 2 Leveraging .NET....................................................................................................................... 2 PowerShell ISE ............................................................................................................................... 3 PowerShell ISE Console ........................................................................................................... 3 PowerShell ISE Toolbar ........................................................................................................... 4 PowerShell ISE Windows ......................................................................................................... 5 Objects ............................................................................................................................................ 6 Members, Properties and Methods ........................................................................................... 6 Using the Property or Method of an Object .............................................................................. 7 PowerShell Commands ................................................................................................................... 8 Breaking Out of a Command .................................................................................................... 8 PowerShell Command Types and Aliases ................................................................................ 8 Commands that Provide Help ................................................................................................. 10 Line Continuation ................................................................................................................... 12 Pipelines ........................................................................................................................................ 13 Execution Policy ........................................................................................................................... 15 Execution Policy Scope .......................................................................................................... 15 Local Policy Setting and Group Policy Setting ...................................................................... 16 Determine the Execution Policy ............................................................................................. 16 Setting the Execution Policy ................................................................................................... 16 To Display the Current User Policy Setting ........................................................................... 17 Remove the Execution Policy ................................................................................................. 17 Setting the Scope of the Execution Policy .............................................................................. 17 PowerShell Scripts ........................................................................................................................ 18 What is a PowerShell Script ................................................................................................... 18 Running Scripts from the Current Directory .......................................................................... 18 Running Scripts from a Different Directory ........................................................................... 19 Specifying Parameters (Arguments) when Running Scripts .................................................. 19 PowerShell Variables .................................................................................................................... 20 Variable Declaration and Naming .......................................................................................... 20 The $ Method of Declaring Variables and Viewing Variable Values .................................... 20 Declaring and Initializing Multiple Variables ........................................................................ 21 Assignment Operators ............................................................................................................. 22 Comparison Operators ............................................................................................................ 24 Get-Variable Cmdlet ............................................................................................................... 26 Set-Variable and New-Variable Cmdlets ................................................................................ 26 Basic PowerShell Scripting: Level 1 www.cetc.umsl.edu Remove-Variable Cmdlet ....................................................................................................... 32 Data Types .............................................................................................................................. 32 PowerShell Variables and the Read-Host Cmdlet .................................................................. 35 The .NET Framework Graphical of Getting User Input ......................................................... 35 Environment Variables ........................................................................................................... 36 Exercise 1 ...................................................................................................................................... 38 Literals .......................................................................................................................................... 39 String Literals .......................................................................................................................... 39 Special Characters (Escape Characters) .................................................................................. 42 Here-String String Literals ...................................................................................................... 43 SubString Method ................................................................................................................... 46 The Length Property ............................................................................................................... 47 Trimming Strings .................................................................................................................... 48 Numbers and Numeric Literals ............................................................................................... 49 Exercise 2 ...................................................................................................................................... 51 Conditional If Statement ............................................................................................................... 52 Exercise 3 ...................................................................................................................................... 56 Arrays or Lists............................................................................................................................... 57 Exercise 4 ...................................................................................................................................... 64 Hash Tables: Associative Arrays .................................................................................................. 65 Appendix A: Operators ................................................................................................................. 67 Appendix B: Aliases for Class Cmdlets........................................................................................ 72 Appendix C: Solutions to Exercises ............................................................................................. 73 Basic PowerShell Scripting: Level 1 www.cetc.umsl.edu .

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    2 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us