powershell pdf.pdf - Getting Started With Microsoft...

This preview shows 1 out of 6 pages.

Getting Started With Microsoft PowerShell James E. Jarvis November 24, 2016 1
Image of page 1

Subscribe to view the full document.

Contents 1 About PowerShell 3 2 Getting started 3 2.1 Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 3 Commands 5 3.1 Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 4 Aliases 6 5 Variables in PowerShell 8 5.1 Integer Variables . . . . . . . . . . . . . . . . . . . . . . . . . 8 5.2 Doubles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 5.3 String Variables . . . . . . . . . . . . . . . . . . . . . . . . . . 9 5.4 Special variables . . . . . . . . . . . . . . . . . . . . . . . . . . 10 5.5 Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 5.6 Arrays of Objects . . . . . . . . . . . . . . . . . . . . . . . . . 13 5.7 Hashes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 5.8 Removing variables . . . . . . . . . . . . . . . . . . . . . . . . 15 5.9 Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 6 The PowerShell environment 16 7 Redirection and pipes 17 8 Reading and writing to files 18 8.1 Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 9 Scripts 21 9.1 Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 10 Logic and loops for flow control 22 10.1 If . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 10.2 For . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 10.3 Foreach . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 10.4 Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 11 Advanced Topics 25 11.1 More date and time . . . . . . . . . . . . . . . . . . . . . . . . 25 11.2 Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 11.3 Handling Data - Using CSV files . . . . . . . . . . . . . . . . . 26 2
Image of page 2
11.4 Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 11.5 Advanced: Handling XML data and loading a .Net framework 28 12 Further Help 30 13 Listings 32 3
Image of page 3

Subscribe to view the full document.

1 About PowerShell PowerShell is a registered trademark of Microsoft Corporation. PowerShell is provided by Microsoft Corporation and is a well thought out, very usable and powerful scripting language. The influence of other scripting languages, not just Microsoft can be seen In PowerShell commands (often called cmdlets ) have the form: verb-noun that is a verb indicating the action and a noun indicating the object for example: get-childitem PowerShell itself is provided as a command line environment. In addi- tion to all the PowerShell "cmdlets" one may call a non-PowerShell program directly (e.g. notepad.exe). 2 Getting started This document assumes you are working on a University of Edinburgh Sup- ported Windows Desktop. The exercises may work in other environments but this has not been tested. If following this document you may need to search the Internet for additional modules and follow the instructions on how to install them. Unless you know what you are doing, it is sensible to only install extra PowerShell functionality from genuine Microsoft sites. Readers will find the exercises easier if they have previous experience of scripting or programming languages. Additionally, PowerShell uses pipelines extensively so prior attendance at Unix 1 and Unix 2 courses will be and advantage. 1. Click on the Start button 2. Type PowerShell 3. You should now see: Windows PowerShell (Figure 1) Windows PowerShell ISE (Figure 2) 4
Image of page 4
Figure 1: PowerShell - the command line environment. If running scripts, the first option of using the PowerShell directly is fine. For creating and editing scripts the PowerShell ISE (Integrated Scripting Environment) is very useful. You may see additional options but these are the two to use for this course. 2.1 Exercise 1. Run PowerShell. Type exit and press the Enter key. What happens? 2. Run PowerShell ISE. Click on the Help menu. Click on Update Win- dows PowerShell Help . You will notice in the window below a com- mand update-help runs and then usually produces an error. This is normal on the University of Edinburgh Supported Windows Desktop.
Image of page 5

Subscribe to view the full document.

Image of page 6
You've reached the end of this preview.
  • Spring '04
  • JewishGuy
  • Microsoft Corporation, Windows PowerShell

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern