Windows PowerShell: A First L k. Charlotte McGary

Size: px
Start display at page:

Download "Windows PowerShell: A First L k. Charlotte McGary"

Transcription

1 Windows PowerShell: A First L k Charlotte McGary

2 Copyright 2007 Charlotte McGary. All Rights Reserved. No portion of this book may be reproduced by any means whatsoever without the expressed written permission of the author. Windows PowerShell: A First Look 2010 Charlotte McGary 2

3 Table of Contents GETTING STARTED... 5 Setting the Default Directory... 5 WORKING WITH FILES AND DIRECTORIES... 7 Get-ChildItem (View Directory Information)... 7 New-Item (Create a Directory or File)... 7 Copy-Item (Copy a Directory or File)... 8 Move-Item (Move a Directory or File)... 9 Rename-Item (Rename a Directory or File)... 9 Remove-Item (Delete a Directory or File)... 9 VARIABLES IN POWERSHELL The PowerShell Version of the Batch File Environment Variable The PowerShell Version of the Batch File Command-Line Argument LOOPS FOREACH LOOP FOR LOOP WHILE LOOP DO WHILE LOOP DO UNTIL LOOP STRING SEARCHES AND PIPING Write-Host versus Write-Output GETTING INPUT User Inputs File Inputs CONDITIONAL STATEMENTS Comparison Operators If/ElseIf/Else CASTING STRINGS VS. NUMBERS ARRAYS Defining Arrays Combining Arrays COMMAND REFERENCE PRACTICE PowerShell Lab # PowerShell Lab # PowerShell Lab # PowerShell Lab # Windows PowerShell: A First Look 2010 Charlotte McGary

4 (This page intentionally left blank.) Windows PowerShell: A First Look 2010 Charlotte McGary 4

5 Windows PowerShell: A First Look This tutorial provides a step-by-step introduction to Windows PowerShell. After completing the tutorial, you should be comfortable with the PowerShell window and with creating and running simple scripts. GETTING STARTED 1. Create folder C:\PowerShell\MyScripts. 2. Create a shortcut to PowerShell on Desktop. 3. Double-click on PowerShell shortcut to open PowerShell. (Note the folder in the command window that PowerShell opens in.) 4. Change to the C:\PowerShell\MyScripts directory by typing set-location C:\PowerShell\MyScripts 5. Create Hello1.ps1 by typing notepad Hello1.ps1 then enter the following text in the Notepad window: # file: Hello1.ps1 The # symbol makes any line a comment 'Hello world!' 6. Try to execute Hello1.ps1 by typing.\hello1.ps1 in the PowerShell (PS) command window. 7. If it doesn't execute, type Get-ExecutionPolicy. 8. If the command returns "restricted" then reset the execution policy by typing set-executionpolicy remotesigned or set-executingpolicy unrestricted 9. Now try running the program again. 10. Exit PowerShell. Setting the Default Directory By default PowerShell opens in your home directory. Now we're going to change that default directory to the MyScripts directory you created earlier so that you don't have to set your location to that directory each time you open PowerShell. 1. Right-click on the PowerShell shortcut on your desktop. 2. Change the %HOMEDRIVE%%HOMEPATH% in the Start in: window to C:\PowerShell\MyScripts as shown in the screen shot to the right. 3. Click OK then re-open PowerShell. Notice that you now are in your MyScripts directory. 5 Windows PowerShell: A First Look 2010 Charlotte McGary

6 4. Type Get-ChildItem and you should see your Hello1.ps1 file. 5. Type Copy-Item whatif Hello1.ps1 Hello2.ps1. 6. Now do the actual copy by typing Copy-Item Hello1.ps1 Hello2.ps1 7. Type Get-ChildItem and you should see both.ps1 files now. 8. Type notepad Hello2.ps1 and edit the file so it has the following text: # file: Hello2.ps1 # outputs a blank line to the screen # Note that single quotes around text or # double quotes around text is okay when # displaying simple text. 'Hello World!' "Have a nice day!" 9. After saving the changes, run Hello2.ps1 by typing.\hello2.ps1 at the PS command line. 10. Now copy Hello2.ps1 to Hello3.ps1 and edit Hello3.ps1 to read as follows then run the script. # file: Hello3.ps1 'Hello World!' 'from Charlotte' "Have a nice day!`n" # `n above produces a new line like the first # command in this file Windows PowerShell: A First Look 2010 Charlotte McGary 6

7 WORKING WITH FILES AND DIRECTORIES Like Linus and DOS/Windows file and directory manipulation, PowerShell has its own set of cmdlets for getting around. This section touches on some of the indispensable cmdlets you'll want at your disposal. Get-ChildItem (View Directory Information) As you saw in the previous section, the Get-ChildItem cmdlet displays the contents of the current directory. Just type the cmdlet to get a listing of the current directory or add the path to view information for a different directory. For example, to see a directory listing of the folder "SubFolder" (a sub folder of MyScripts), type the following: get-childitem.\subfolder New-Item (Create a Directory or File) To create a new directory, use the New-Item cmdlet. This cmdlet can also create a file, so you'll want to differentiate between the two using the type parameter. For example, to create a subfolder called "MyNewFolder" in the current directory, type the following code: new-item. name MyNewFolder type directory The resulting screen output should look like this: Now create two more directories one a subdirectory of MyNewFolder, and the other a subdirectory of MyScripts: new-item path.\mynewfolder name SubFolder type directory new-item. name Test type directory To create a new empty file, use the New-Item cmdlet. As previously mentioned, this cmdlet is also used to create directories. Use the type parameter to define what you are creating. For example, to create an empty file called "MyNewFile" in the subdirectory created in the section on "Working With Directories," type the following code (it is assumed you are still in your MyScripts directory): new-item path.\mynewfolder name MyNewFile type file 7 Windows PowerShell: A First Look 2010 Charlotte McGary

8 Note that the use of quotes around the values "MyNewFile" and "File" are optional, but it's always a good idea to put them in, as in many cases they are required (see the example after this one). The resulting screen output after creating MyNewFile should look like this: The 0 length indicates the file is empty. If you want to add some text to a file at the time you created it, you can do that by adding the value parameter. For example, to create a file called File2.txt with the content "This is Charlotte's file." in the same directory as MyNewFile, type the following line of code: new-item path.\mynewfolder name File2.txt type file value "This is Charlotte's file" The resulting screen output should look like this: Copy-Item (Copy a Directory or File) To copy the complete contents of one directory to another, use the Copy-Item cmdlet shown in the following example The recurse parameter copies all subdirectories also. If the destination directory does not already exist, the command will create it. copy-item.\mynewfolder destination.\backup -recurse Note that no output will be generated unless there is an error. You can use the Get-ChildItem cmdlet to confirm that the copy was successful. To copy one or more files from one location to another, use the Copy-Item cmdlet shown in the following example. To copy all.txt files from your.\backup directory to.\mynewfolder\subfolder, enter the following code. (The original files will not be deleted.) copy-item.\backup\*.txt destination.\mynewfolder\subfolder Windows PowerShell: A First Look 2010 Charlotte McGary 8

9 After using the Get-ChildItem cmdlet to view the contents of the Backup folder, you should see output similar to this: Move-Item (Move a Directory or File) To move a file or directory from one location to another, use the Move-Item cmdlet shown in the following example. It works just like Copy-Item except the file or directory no longer exists in its original location after the move. If you had wanted to move rather than copy all.txt files in the previous example, you would have typed the following code instead: move-item path.\backup\*.txt destination.\test Rename-Item (Rename a Directory or File) To rename a file or directory, simple use the Rename-Item cmdlet shown in the following example. If the item to be renamed is in a location outside of the current directory, you must preface the name with the path. rename-item oldname newname Now change to your.\test directory and rename File2.txt to test.txt. Remove-Item (Delete a Directory or File) To move a file or directory from one location to another, use the Remove-Item cmdlet. To remove an entire directory, whether or not it is empty, use the recurse parameter. For example, if you wanted to delete the sub folder of MyScripts called Test, you'd type remove-item.\test -recurse Suppose you want to remove all files from a directory named SubFolder that have an extension, i.e. have a "." in the file name. To do that you would type: remove-item.\mynewfolder\*.* Unless a directory name (or a file name) has a "." in it, it will not be deleted. 9 Windows PowerShell: A First Look 2010 Charlotte McGary

10 VARIABLES IN POWERSHELL Up to this point, you have "hard-coded" all your text. Now we'll explore the use of variables in PowerShell. Suppose, instead of the line of code above that writes "from yourname" to the screen, you want to store your name in a variable. The following example shows you how to accomplish this. The PowerShell Version of the Batch File Environment Variable Copy the file Hello3.ps1 to Hello4.ps1 and edit Hello4.ps1 to read as follows then run the script. # file: Hello4.ps1 # Assigning the string "Charlotte" to the variable called # $name is like setting an environment variable in a Windows # Batch File. $name = "Charlotte" "Hello World!" "from" $name "Have a nice day!`n" The PowerShell Version of the Batch File Command-Line Argument Now suppose you want to be able to change "Charlotte" in the above example to any name. The way your script is currently set up, you'd have to edit it each time you want to change the name. A better way is to send the name through to the script at the time you execute it at the PowerShell command line. (Sound familiar? i.e., the Command Line Argument/Pass- Through Parameter in Windows Batch Files.) Copy the file Hello4.ps1 to Hello5.ps1 and delete all the text. Enter the following code into Hello5.ps1 then run the script by typing in.\hello5.ps1 "Capt. Kirk" "Mr. Spock" "Dr. McCoy" # file: Hello5.ps1 # To pass a value through at the command line type # the value after the script name. # For example:.\hello5.ps1 "Capt. Kirk" "Mr. Spock" "Dr. McCoy" # will send the above three strings through to the script as the # first argument. (Arrays start their numbering at zero, so an array # with 5 elements will number those elements 0-4.) # In the line of code below, the variable named $name is assigned # the value of the first argument passed through at the command # line ($args[0]). Note that $args is a special object which stores # command-line input. $name1 = $args[0] $name2 = $args[1] $name3 = $args[2] # First argument # Second argument # Third argument "Hello World!" "from" $name1"," $name2", and" $name3 `n$name1 "says have a nice day!`n" $name2 "says have a nice day!`n" Windows PowerShell: A First Look 2010 Charlotte McGary 10

11 $name3 "says have a nice day!`n" "Actually" $name2 "says live long and prosper.`n" Your output should look like this: 11 Windows PowerShell: A First Look 2010 Charlotte McGary

12 LOOPS Up till now, we've executed one line at time systematically to display the output we wanted. That is, in the example from Hello5.ps1, we had to type a line three times to have each of our input names say "have a nice day!" FOREACH LOOP We can reduce those three lines to single line using a foreach loop. To see an example, copy Hello5.ps1 to Hello6.ps1, delete all but the first and last comments, and edit Hello6.ps1 to read as follows. Run the script by typing in.\hello6.ps1 "Capt. Kirk" "Mr. Spock" "Dr. McCoy" # file: Hello6.ps1 "Hello World!" foreach ($name in $args) $name "says have a nice day!`n" Your output should look like this: So exactly is that foreach statement doing? If you remember FOR statements from Windows Batch Files, the foreach is acting in a similar fashion. In the above example, foreach ($name in $args) $name "says have a nice day!`n" temporarily defines the variable $name to each value of $args one at a time, then does whatever you tell it to do within the curly braces. In this example, there are three values stored in the array $args (args[0], args[1], and args[2]), so $name first takes on the value stored in $args[0], then displays the contents of $name followed by the text "says have a nice day!" Next $name takes on the value stored in $args[1], displays the contents of $name followed by the text "says have a nice day!" and so on until it runs through all the arguments that were passed through at the command line. Windows PowerShell: A First Look 2010 Charlotte McGary 12

13 FOR LOOP Another type of loop is called a For Loop, which executes until the specified condition is true. You initialize the counter, set the limit, and define the increment value, all in one statement. for (initialization; limit; increment) # Do stuff here The following example initializes a variable called $i, displays the value of $i as long as the value of $i is less than 5. Create the file ForLoop.ps1 in your MyScripts directory and add the following code: # File: ForLoop.ps1 for ($i = 0; $i lt 5; $i++) $i Execute the script by typing.\forloop.ps1. Your output should look like this: Now create the file called ForLoopArray.ps1 and enter the following code. You will need to pass in six command line arguments to the script, which will display every other one. (Note that the line and the one following it should all be typed on a single line.) # File: ForLoopArrays.ps1 for ($i = 0; $i -lt 5; $i+=2) $passorder = $i + 1 Command line argument number $passorder = args[$i] = $args[$i] Execute the script by typing in.\forlooparrays.ps Your output should look like this: 13 Windows PowerShell: A First Look 2010 Charlotte McGary

14 WHILE LOOP Another type of loop is called a While Loop, which executes only as long as the condition specified within the parentheses is true. In the following example, we initialize a counter then set up a while loop to continue executing as long as the counter is less than or equal to five. Each time we go through the loop, we increment the counter by one. Create a file called WhileLoop.ps1 in your MyScripts directory. Enter the following code into the file: # File: WhileLoop.ps1 $counter = 0 while ($counter -le 5) $counter $counter++ # Increment counter by one Your output should look like this: DO WHILE LOOP The Do While loop works just like the While loop except that the Do While loop will always execute at least once. To change the above example to a Do While loop, modify the code as follows. By starting the counter at 6, if this were a While loop, the loop would never execute. In this example, however, the Do causes it to execute at least once, then checks to see if the While condition is true or false. Create the file DoWhileLoop.ps1 in your MyScripts directory and modify the code as shown below: Windows PowerShell: A First Look 2010 Charlotte McGary 14

15 # File: DoWhileLoop.ps1 $counter = 6 do $counter $counter++ while ($counter -le 5) Your output will display the value of $counter as 6 then jump out of the loop. DO UNTIL LOOP Just like the Do While loop, the Do Until loop will execute at least once. Then it continues executing until the condition is true (unlike the While and Do While loops which execute while a condition is true). Another way to put it is a Do Until loop continues executing as long as the condition is false. To change the previous While loop to a Do Until loop, create the file DoUntilLoop.ps1 in your MyScripts directory and enter the following code: # File: DoUntilLoop.ps1 $counter = 0 Do $counter $counter++ until ($counter -eq 6) Your output should look like this: Now it's time to get a little more hands-on experience with PowerShell scripting. Go to the Practice section at the end of this document and write the script described in Lab #1. 15 Windows PowerShell: A First Look 2010 Charlotte McGary

16 STRING SEARCHES AND PIPING Searching for strings within text files can be a bit tricky in PowerShell as there is no simple FIND command like there is in DOS/Windows. On the other hand, once you create a script to find a string, there is a multitude of ways you can sort, group, and display the results. Let's start by creating a simple script called "FindText1.ps1" in your MyScripts directory. Enter the following code into the file: # file: FindText1.ps1 # Variable Name Stores # $target string to search for # $files all text files # $matches all files in $files with target string $target $target = "orange" "`nsearching for 'orange' in current dir and all subdirectories" # The search for matches can be broken down into two steps as # shown below, or in one step as follows: # $matches = get-childitem. -include *.txt -recurse select-string $target $files = get-childitem. -include *.txt -recurse $matches = $files select-string $target # $null is a special variable representing the null (nothing) character if ($matches -eq $null) 'No matches found' $matches Before you run this script you will need to create three text files in MyScripts: fruits.txt, trees.txt and colors.txt in your MyScripts directory. Then make a subdirectory of MyScripts called SubFolder (C:\PowerShell\MyScripts\SubFolder) and create desserts.txt in that folder. Contents of fruits.txt: oranges blueberries mangos cherries apples Contents of trees.txt: apple orange cherry oak walnut Contents of colors.txt: purple green orange red blue Contents of desserts.txt apple crisp blueberry pie cherry pie pecan pie orange sherbert Let's examine some particularly interesting lines of code from the above script. $files = get-childitem. -include *.txt -recurse The above line executes a directory listing (get-childitem) of the current directory (.), including in the listing only those files with the extension *.txt (-include *.txt) and also looks for those files in all subdirectories (-recurse). It stores the file names found in the variable $files. Windows PowerShell: A First Look 2010 Charlotte McGary 16

17 $matches = $files select-string $target The above line searches all files whose names are stored in $files for the string stored in the variable named $target (select-string $target). The symbol is a "pipe" through which the data in $files is input to the select-string cmdlet. if ($matches -eq $null) The above line checks to see whether or not any matches were found. If not, the value stored in $matches will be the null character, which is stored in a special variable called $null. So the line can be read as "if the value stored in $matches equals the null character)." The operator for "equals" is -eq. An IF statement must always be followed by some action within curly braces. Now run the script by typing.\findtext1.ps1 at the PS command line. Your output should look similar to this: Not very readable is it? Let's change the code slightly by substituting the line $matches with write-output $matches in your file FindText1.ps1. Your output should look like this: Write-Host versus Write-Output The cmdlet sends objects to the command line (Out-Host), which, by default, displays objects on the screen (host window) with no formatting applied. It also allows for customization of the window (i.e., text and background colors with foregroundcolor and backgroundcolor, respectively). Objects displayed with cannot be piped to other cmdlets. Although the write-output cmdlet does not allow customization of the host window, it's more versatile than. The write-output cmdlet writes objects to a "pipeline", 17 Windows PowerShell: A First Look 2010 Charlotte McGary

18 sending them to a default formatter and to the default output cmdlet (Out-Default). (It is this default formatter which accounts for the difference in how the output is displayed in the above two screen shots.) From the pipeline, an object is available to be piped to other cmdlets which can then perform additional operations on the object, e.g., writing it to a file. Let's created a second script that uses both and write-output. We'll also pipe the object from a write-output cmdlet to the sort-object cmdlet to list files in alphabetical order. Copy the file FindText1.ps1 to FindText1a.ps1 then edit FindText1a.ps1 to read as follows: # file: FindText1a.ps1 # Variable Name Stores # $target string to search for # $files all text files # $matches all files in $files with target string # $result matches sorted in alphabetical order $target = "orange" "`nsearching for $target in current dir and all subdirectories" # The search for matches can be broken down into two steps as shown below, # or in one step as follows: # $matches = get-childitem. -include *.txt -recurse select-string $target $files = get-childitem. -include *.txt -recurse $matches = $files select-string $target # null is a special variable representing the null character if ($matches -eq $null) 'No matches found' "*** COMPARISON OF AND write-output ***" "Matches displayed using :`n" $matches foregroundcolor blue backgroundcolor white "Matches displayed using write-output:`n" write-output $matches "*** END COMPARISON ***`n`n" "Results sorted alphabetically..." $result = $matches write-output $result sort-object Run the script by typing.\findtext1a.ps1 in the PS window. Notice the line displaying $matches has a different text and background color than the rest of the window. This is the result of adding the parameters and values foregroundcolor blue backgroundcolor white For more information about changing output colors, type get-help detailed. Windows PowerShell: A First Look 2010 Charlotte McGary 18

19 Your output should look like this: Right now we are constrained to search only for the string "orange" in our script. Let's give the script more functionality by changing it to accept the search string from the command line. Copy FindText1.ps1 to FindText1b.ps1 and edit FindText1b.ps1 to read as follows: # file: FindText1b.ps1 # Variable Name Stores # $args command line input (an array) # $target string to search for # $files all text files # $matches all files in $files with target string # # Enter search string at command line by typing #.\FindText1b.ps1 string # where string is apple, orange, or whatever string you're searching for. # You must use quotes around the string if it contains spaces. # Define the target string as whatever is passed through at the command line $target = $args[0] "`nsearching for" $target "in current dir and all subdirectories" # The search for matches can be broken down into two steps as shown below, # or in one step as follows: # $matches = get-childitem. -include *.txt -recurse select-string $target $files = get-childitem. -include *.txt -recurse $matches = $files select-string $target # null is a special variable representing the null character if ($matches -eq $null) 'No matches found' # The group cmdlet below groups the files by the filename property # (i.e., it will show how many matches were in each file name without # displaying the found text itself) write-output $matches group -property filename 19 Windows PowerShell: A First Look 2010 Charlotte McGary

20 Run the script by typing.\findtext1b.ps1 orange at the PS command line. Your output should look like this: Notice that the data held in the variable $matches was piped to the group cmdlet and displayed by filename property (-property filename); i.e., only file names are displayed with the number of occurrences of the search string found in each. Replace "orange" with "blue" at the command line and you should see this result: At this point, you're ready to try Lab #2 in the Practice section. Windows PowerShell: A First Look 2010 Charlotte McGary 20

21 GETTING INPUT User Inputs Until now, the only way a user could send data to any of our scripts was through the command line at the time the script was executed. But what if you want to ask the user to input additional data while the script is running? For that you need to use the Read-Host cmdlet. Create the file WhatIsYourName.ps1 in your MyScripts directory. Input the following code: # File: WhatIsYourName.ps1 $firstname = read-host prompt "Enter your first name" $lastname = read-host prompt "Enter your last name" "Your name is" $firstname $lastname When you run the script, your output should look similar to this: File Inputs Another way to get data after a script has begun executing is by reading that data from a file. Suppose you have a file called listing.txt that contains the names of all text files in a directory (you will create that list in the next example). You want read in the names of those files from the list and display the contents of each file in the PS command window. With the use of redirection (>) and Get-Contents, this is a fairly simple process. Create a file called ReadFiles.ps1 in your MyScripts directory and enter the following lines of code: # File: ReadFile.ps1 # List only the names of.txt files in the current # directory and redirect the output to a file # called listing.txt # get-childitem -name *.txt > listing.txt # Retrieve the contents of the file listing.txt and # store in the variable $filenames 21 Windows PowerShell: A First Look 2010 Charlotte McGary

22 # $filenames = get-content listing.txt # Read the name of each file from listing.txt and # display its contents on in the PS command window. # foreach ($file in $filenames) $file -foregroundcolor yellow get-content $file Examine the code get-childitem -name *.txt > listing.txt. You're already familiar with the Get-ChildItem cmdlet; get-childitem *.txt by itself would produce a directory listing of all.txt files in the current directory. The name parameter specifies that only the file names will be listed (without additional information). The redirection operator (>) specifies that the output from the Get- ChildItem command will be redirected to a text file called listing.txt instead of displaying in the PS command window. In the line $filenames = get-content listing.txt, the Get-Content cmdlet retrieves all data from the file, line-by-line and, in this example, stores that content in a variable named $filenames. Then, within a foreach loop, each file is read in turn, and each line of the current file is displayed in the PS command window. When you run the script, your output should look similar to the screen shot on the right. Windows PowerShell: A First Look 2010 Charlotte McGary 22

23 CONDITIONAL STATEMENTS A conditional statement performs some kind of test, then performs a specific action based on the results of that test (i.e., the resulting of the test is either true or false). An example of one type of test is to see if two strings are equal. Another test would be to evaluate two numbers and determine if one is less than the other. To conduct such tests, we use what are called comparison operators, usually with some form of IF statement (more on that later). Comparison Operators Unlike the equal sign (=), which is an assignment operator that takes the value to the right of the equal sign and assigns it to the variable to the left of the operator, comparison operators do not change the values on either side of the operator. Rather, they compare the two values to see if they meet the specified condition. To understand the difference, review the example below. Assignment Operator $myname = "Charlotte" Comparison Operator eq if ($myname eq "Spock") The example on the left assigns the string "Charlotte" to the variable $myname. Whatever was stored in $myname has now been replaced with "Charlotte". The variable will contain that string until replaced with something else or the script finishes executing. The example on the right checks to see if whatever is stored in $myname is equal to the string "Spock". Whether it is or is not (i.e., whether the condition is true or false), the value held in $myname is not changed. In PowerShell, comparison operators always start with a dash ( ) character. COMPARISON OPERATORS PowerShell Operator Description -eq Equal to -lt Less than -gt Greater than -ge Greater than or equal to -le Less than or equal to -ne Not equal to Of important note is string comparisons are not case-sensitive. You need to add a "c" just before the operator name in order to force case-sensitive comparisons (e.g., -ceq). Copy your file WhatIsYourName.ps1 in your MyScripts directory to a file called CompareNames.ps1. Change the code as follows, but use your first and last names in the IF statements. # File: CompareNames.ps1 $firstname = read-host prompt "Enter your first name" $lastname = read-host prompt "Enter your last name" if ($firstname -eq "Charlotte") 23 Windows PowerShell: A First Look 2010 Charlotte McGary

24 "Your first name is" $firstname if ($lastname -eq "McGary") "Your last name is" $lastname "Your name is" $firstname $lastname Run the script three times, the first time using your correct first and last names, the second time using only your correct first name, and the third time using only your correct last name. Your output should look similar to the screen shot to the right. Now edit the script to force the first name comparison to be case-sensitive and rerun the script with the same inputs, adding a test case with your first name in lowercase. Compare the new results with the old. If/ElseIf/Else. So far, we've compared two objects by checking to see if they're equal by using a single IF statement. We then executed a line of code only if that comparison was true. Sometimes, however, you want to perform different actions based on multiple conditions. That's where a series of IF's, ELSEIF's, and finally, an ELSE, comes in handy. The if/elseif/else combination works like this: it executes the first conditional statement (IF), and if the result is true, skips the other two conditions. Only if the first condition is false does it execute the next conditional statement (ElseIf). Only if that statement is false does it finally execute the Else statement. Basically the Else statement handles all conditions not specified by the IF and IfElse statements. Note that there can be more than one ElseIf statement, but only one Else, and it must be the last in the series. Create the file CompareColors.ps1 in your MyScripts directory. Enter the following code: # File: CompareColors.ps1 $color1 = read-host prompt "Guess the first color" $color2 = read-host prompt "Guess the second color" if ($color1 -ne "purple") "You should have entered purple for your first color. You lose." elseif ($color2 -eq "green") "You chose" $color1 "and" $color2 "in the correct order. YOU WIN!" Windows PowerShell: A First Look 2010 Charlotte McGary 24

25 else "You entered the colors" $color1 "and" $color2". You lose." Run the program three times, the first time entering Yellow and Blue, the second time entering Purple and Blue, and the third time entering Purple and Green. Your output should look like this: Let's analyze what this script does with our series of inputs. The first time through, we entered Yellow for $color1 and Blue for $color2. Since Yellow is not equal to Purple, the condition if ($color1 -ne "purple") is true, so we get the message "You should have entered Purple for your first color. You lose." and the ElseIf and Else statements are ignored. The second time we executed the script, we entered Purple and Blue for our two colors. Since Purple is obviously equal to Purple, the condition if ($color1 -ne "purple") is false, so the ElseIf is then executed. Since Blue is not equal to Green, the condition ($color2 -eq "green") is false, so it executes the Else statement. 25 Windows PowerShell: A First Look 2010 Charlotte McGary

26 CASTING STRINGS VS. NUMBERS If you were to create a variable and assign it a value in your code or pass the value through at the command line then perform some type of arithmetical operation on it, PowerShell would assume the value is a number not a string, as in the following example. Create the file AddNumbers.ps1 in your MyScripts directory and enter the following lines of code: # File: AddNumbers.ps1 $x = $args[0] $y = 2 $sum = $x + $y `n"x + y =" $sum `n Run the script by typing.\addnumbers.ps1 3 at the command line. Your output should look like this: Read-Host, however, accepts input as a string value, not a numerical value. In other words, if you type in 100, it sees the value as the string "100" not the number 100. With strings, addition is in reality something called concatenation. Therefore, if you add the string "1" to the string "100", you get "1001" not "101". To use input from Read-Host as a number and perform actual arithmetical operations on it, you must tell PowerShell to interpret it that way. For example, if you were to enter our two strings in the example above ("100" and "1") into $x and $y when prompted by Read-Host, you would represent them as integers by casting them as such. You do this by prefacing the variable name with [int], such as [int]$x Create a file called Conditions.ps1 in your MyScripts directory and enter the following code: # File: Conditions.ps1 $x = read-host -prompt "Enter a value for x" $y = read-host -prompt "Enter a value for y" $stringcat = $x + $y "The value of x + y as a concatenated string is" $stringcat # Read-Host retrieves input as strings, which are concatenated # rather than 'added' so that $x + $y = $stringcat # # To use them as numbers, we have to 'cast' them as integers # by prefacing the variables with [int] $x = [int]$x $y = [int]$y $sum = $x + $y Windows PowerShell: A First Look 2010 Charlotte McGary 26

27 $difference = $x - $y $product = $x * $y "x = " $x ", y =" $y $x "+" $y "=" $sum $x "-" $y "=" $difference $x "*" $y "=" $product if ($sum -eq $product) "Two is special because 2+2 = 2*2." elseif ($sum -gt $product) "One is special because 1 + a number is > 1 * that number." else "Nothing special about these numbers." "`ndone!" Run the script three times. The first time you should enter 2 and 3 for x and y, respectively. The second time, enter 1 and 2. The third time 2 and 2. Your output should look like this: How does this script work? The if ($sum -eq $product) statement compares the values of $sum and $product to see if they are equal. If they are, the message about the number two is displayed. 27 Windows PowerShell: A First Look 2010 Charlotte McGary

28 If the if comparison is false, the elseif ($sum -gt $product) statement compares the values of $sum and $product to see if $sum is greater than $product. If true, the message about the number one is displayed. If both the if and elseif comparisons are false (meaning all conditions are true except $sum equals $product or $sum greater than $product), the else statement displays the nothing-special message. Now you're ready to try Practice Lab #3. Windows PowerShell: A First Look 2010 Charlotte McGary 28

29 ARRAYS Arrays are just variables which hold an indexed list of values. You've already seen one example of an array variable ($args) in previous examples which used command line arguments. The first element of an array always has an index of 0, the second index is 1, the third is 2, etc. You access the value stored in an array element by referencing the array variable name and that element's position in the array. The index number is always enclosed by square brackets []. For example, to retrieve the value stored in the first element of an array named $myarray, you access it as follows: $myarray[0] Defining Arrays There are two ways to define an array. You can either create an empty array then add the values later, or you can populate the array at the time you create it. We'll do both in the next example. Create a script called Arrays.ps1 in your MyScripts directory and enter the following code: # File: Arrays.ps1 # Create an empty string array # then populate with three characters $sarray $sarray = $sarray + "a" $sarray = $sarray + "b" $sarray = $sarray + "c" `nsarray[0,1,2] = $sarray #Create an integer array with three numbers $intarray intarray[0,1,2] = $intarray `n Your output should look like this: 29 Windows PowerShell: A First Look 2010 Charlotte McGary

30 Combining Arrays PowerShell allows you to create a new array by combining two or more existing arrays. You use the "+" operator just like when you concatenate strings. If you want to find out how many elements the new array holds, you can use the length property as in the following example. Create a script called CombineNames.ps1 in your MyScripts directory. Enter the following code: # File: CombineNames.ps1 $list1 "Spock", "McCoy") $list2 "Scotty", "Sulu", "Checkov") $crew = $list1 + $list2 Write-host `nand the crew is... Write-host $crew Number of elements in list1: $list1.length Number of elements in list2: $list2.length Number of elements in crew: $crew.length Your output should look like this: Windows PowerShell: A First Look 2010 Charlotte McGary 30

31 COMMAND REFERENCE Command/Symbol(s) DOS/Batch Equivalent -eq -ne -lt, -gt, -le, -ge = = NOT = = Description Comparison Operators: Equal to Not equal to Less than, Greater than, Less than or equal to, Greater than or equal to Case-sensitive comparison -coperator if /i # rem Comment $ set var=string Defines a variable name and access what's stored %var% in that variable $args[] %1 - %9 Special array that holds command-line input(s). May contain more than 9 inputs..\ Path to.ps1 file in current directory Clear-Host cls Clears the screen Copy-Item copy Copies a file do while Executes a loop once, then continues as long as a condition is true for Executes a loop a set number of times foreach for Command that loops through items in an array Get-ChildItem dir Lists files and folders within a directory Get-ChildItem -name dir /b Gets listing of names only Get-Content type Retrieves the content from a file and processes one line at a time Get-ExecutionPolicy Retrieves current policy on allowing PowerShell scripts to execute Get-Help help Help cmdlet Get-Help command command /? Gets help related to a cmdlet If/ElseIf/Else if Conditional statements that perform comparisons and execute in series (or are skipped) based on the results of the previous comparison(s) Move-Item move Moves a file or directory New-Item md Creates a directory or a file Read-Host set /p Gets user input after script has begun execution Remove-Item del, rd, rd/s Deletes a file or directory Rename-Item ren Renames a file or directory Select-String find Identifies a string pattern Set-ExecutionPolicy Resets executionpolicy Set-Location cd Changes to a different directory Sort-Object sort Sorts objects (default is alphabetical) while Executes a loop while a condition is true Write-Host Displays object on the screen Write-Output echo Writes objects to default formatter and default output for display 31 Windows PowerShell: A First Look 2010 Charlotte McGary

32 PRACTICE PowerShell Lab #1 Requirements 1. Create a PowerShell script named Lab1.ps1 in your MyScripts directory. 2. The first five lines should be comments indicating the name of the file, your name, this course (CSNT xxx), the above lab number, and what you must type at the command line to run the program. For example, if Hello6.ps1 were the lab, the first five lines of that file would be # file: Hello6.ps1 # author: Charlotte # course: CSNT xxx # lab: 1 # execution:.\hello6.ps1 "Capt. Kirk" "Mr. Spock" "Dr. McCoy" 3. Although PowerShell recognizes most DOS and Unix commands, your script MUST use the appropriate PowerShell commands. 4. When you run the script, you will enter three command-line inputs. These three inputs will be the paths to three different directories on your hard drive, one of which must be the path to your MyScripts directory. 5. Store your name in a variable inside the script. 6. Display the contents of the above variable on the screen followed by the text "wrote this script." 7. You will then use a foreach loop to display a directory listing of each of the three directory names you passed through. 8. Initialize a counter, then increment the counter by one each time the foreach loop executes. 9. End your script with the End Script comment like we did in the examples. 10. After getting your foreach loop to work, add code to your script to perform the same function with these additional loop structures: a. FOR b. WHILE c. DO WHILE d. DO UNTIL Windows PowerShell: A First Look 2010 Charlotte McGary 32

33 PowerShell Lab #2 Requirements 1. Create a PowerShell script named Lab2.ps1 in your MyScripts directory. 2. The first five lines should be comments indicating the name of the file, your name, this course, the above lab number, and what you must type at the command line to run the program. 3. Create a subdirectory under your MyScripts directory if you don't already have one. Place copies of at least two.ps1 files in that subdirectory. 4. Write your script to find all.ps1 files in your MyScripts directory and all subdirectories which contain a string you will pass through at the command line. 5. Just in case you missed it direction in Step 4, the string you're searching for must be entered at the command line. 6. You will display the results of the search in four ways (the fourth way is explained in Step 8): a. Sorted alphabetically by file name b. Sorted in reverse alphabetical order (HINT: get-help is your friend) c. Grouped by the filename property 7. Test your script by searching for the string write-output. 8. Now change your script so that your search is case-sensitive (HINT: get-help is still your friend). 9. Test your script by running it once, searching for the string write-output, and again searching for the string Write-Output. 33 Windows PowerShell: A First Look 2010 Charlotte McGary

34 PowerShell Lab #3 Requirements 1. Create a PowerShell script named Lab3.ps1 in your MyScripts directory. 2. The first five lines should be comments indicating the name of the file, your name, this course, the above lab number, and what you must type at the command line to run the program. 3. Enter two numbers $n1 and $n2: one at the command line and one through a Read-Host command (make sure you prompt the user for input). 4. Multiply the two numbers and assign them to a variable named $product. 5. Square each number by multiplying it by itself. The results should be stored in the variables $n1sq and $n2sq. 6. Add the two squares and assign to a variable named $sumsq. 7. Now subtract the variable $product from the variable $sumsq and store in a variable named $result. 8. Check to see if the values stored in $result and $product are equal. a. If they are equal, output the text "You entered the same value for both numbers." and display one of the values. b. Otherwise, just display what's stored in both $n1 and $n2. 9. Finally, you will output three lines of text: a. The value of $product b. The value of $sumsq c. The value of $result 10. Test your script by entering two different numbers, then by entering the same value for both numbers. Sample Output: Windows PowerShell: A First Look 2010 Charlotte McGary 34

35 PowerShell Lab #4 Requirements 1. Create a PowerShell script named Lab4.ps1 in your MyScripts directory. 2. The first five lines should be comments indicating the name of the file, your name, this course, the above lab number, and what you must type at the command line to run the program. 3. When you run this script you will need to enter at least two values at the command line 4. Create an empty array called $userarray. a. Using a foreach loop, populate $userarray with the command line arguments you entered. b. Display the number of elements in the filled array using the length property. c. Display the values in the array. 5. Create an array called $myarray with at least two elements in it (define these values at the time of creation). a. Display the number of elements in the array using the length property. b. Display the values in the array. 6. Combine the two arrays into an array called $comboarray. a. Display the number of elements in the array using the length property. b. Display the values in the array. 7. Initialize a counter variable. 8. Using a while loop, which increments the counter, display each value of each element of $comboarray using the value of the counter as the index (HINT: The length property will be very helpful here). Sample output (your array data may vary): 35 Windows PowerShell: A First Look 2010 Charlotte McGary

Microsoft. Jump Start. M3: Managing Windows Server 2012 by Using Windows PowerShell 3.0

Microsoft. Jump Start. M3: Managing Windows Server 2012 by Using Windows PowerShell 3.0 Microsoft Jump Start M3: Managing Windows Server 2012 by Using Windows PowerShell 3.0 Rick Claus Technical Evangelist Microsoft Ed Liberman Technical Trainer Train Signal Jump Start Target Agenda Day One

More information

Hands-On UNIX Exercise:

Hands-On UNIX Exercise: Hands-On UNIX Exercise: This exercise takes you around some of the features of the shell. Even if you don't need to use them all straight away, it's very useful to be aware of them and to know how to deal

More information

Unix Shell Scripts. Contents. 1 Introduction. Norman Matloff. July 30, 2008. 1 Introduction 1. 2 Invoking Shell Scripts 2

Unix Shell Scripts. Contents. 1 Introduction. Norman Matloff. July 30, 2008. 1 Introduction 1. 2 Invoking Shell Scripts 2 Unix Shell Scripts Norman Matloff July 30, 2008 Contents 1 Introduction 1 2 Invoking Shell Scripts 2 2.1 Direct Interpretation....................................... 2 2.2 Indirect Interpretation......................................

More information

Unix Scripts and Job Scheduling

Unix Scripts and Job Scheduling Unix Scripts and Job Scheduling Michael B. Spring Department of Information Science and Telecommunications University of Pittsburgh spring@imap.pitt.edu http://www.sis.pitt.edu/~spring Overview Shell Scripts

More information

POWERSHELL (& SHAREPOINT) This ain t your momma s command line!

POWERSHELL (& SHAREPOINT) This ain t your momma s command line! POWERSHELL (& SHAREPOINT) This ain t your momma s command line! JAMYE FEW SENIOR CONSULTANT 12+ years as IT Professional ( IT PRO duck DEV ) A little IT PRO, little more DEV and a lot of ducking. Certifiable

More information

6. Control Structures

6. Control Structures - 35 - Control Structures: 6. Control Structures A program is usually not limited to a linear sequence of instructions. During its process it may bifurcate, repeat code or take decisions. For that purpose,

More information

PHP Tutorial From beginner to master

PHP Tutorial From beginner to master PHP Tutorial From beginner to master PHP is a powerful tool for making dynamic and interactive Web pages. PHP is the widely-used, free, and efficient alternative to competitors such as Microsoft's ASP.

More information

Exercise 1: Python Language Basics

Exercise 1: Python Language Basics Exercise 1: Python Language Basics In this exercise we will cover the basic principles of the Python language. All languages have a standard set of functionality including the ability to comment code,

More information

BASH Scripting. A bash script may consist of nothing but a series of command lines, e.g. The following helloworld.sh script simply does an echo.

BASH Scripting. A bash script may consist of nothing but a series of command lines, e.g. The following helloworld.sh script simply does an echo. BASH Scripting bash is great for simple scripts that automate things you would otherwise by typing on the command line. Your command line skills will carry over to bash scripting and vice versa. bash comments

More information

PowerShell for Exchange Admins

PowerShell for Exchange Admins PowerShell for Exchange Admins Get-Speaker FL Name : Kamal Abburi Title : Premier Field Engineer Expertise : Exchange Email : Kamal.Abburi@Microsoft.com Blog : mrproactive.com Note: Inspired by my fellow

More information

Computer Programming In QBasic

Computer Programming In QBasic Computer Programming In QBasic Name: Class ID. Computer# Introduction You've probably used computers to play games, and to write reports for school. It's a lot more fun to create your own games to play

More information

You Should Be Using PowerShell Aaron Kaiser Senior Technology Support Specialist Parkway School District

You Should Be Using PowerShell Aaron Kaiser Senior Technology Support Specialist Parkway School District You Should Be Using PowerShell Aaron Kaiser Senior Technology Support Specialist Parkway School District Why PowerShell? Most modern Microsoft GUI s are built upon PowerShell A number of third party applications

More information

Windows PowerShell Essentials

Windows PowerShell Essentials Windows PowerShell Essentials Windows PowerShell Essentials Edition 1.0. This ebook is provided for personal use only. Unauthorized use, reproduction and/or distribution strictly prohibited. All rights

More information

Lab 9 Access PreLab Copy the prelab folder, Lab09 PreLab9_Access_intro

Lab 9 Access PreLab Copy the prelab folder, Lab09 PreLab9_Access_intro Lab 9 Access PreLab Copy the prelab folder, Lab09 PreLab9_Access_intro, to your M: drive. To do the second part of the prelab, you will need to have available a database from that folder. Creating a new

More information

CS2043 - Unix Tools & Scripting Lecture 9 Shell Scripting

CS2043 - Unix Tools & Scripting Lecture 9 Shell Scripting CS2043 - Unix Tools & Scripting Lecture 9 Shell Scripting Spring 2015 1 February 9, 2015 1 based on slides by Hussam Abu-Libdeh, Bruno Abrahao and David Slater over the years Announcements Coursework adjustments

More information

Forefront Management Shell PowerShell Management of Forefront Server Products

Forefront Management Shell PowerShell Management of Forefront Server Products Forefront Management Shell PowerShell Management of Forefront Server Products Published: October, 2009 Software version: Forefront Protection 2010 for Exchange Server Mitchell Hall Contents Introduction...

More information

Things I wish I d known when I started using PowerShell

Things I wish I d known when I started using PowerShell PowerShell Day 1 Things I wish I d known when I started using PowerShell John D. Cook http://www.johndcook.com First released 9 April 2009, last updated 1 February 2010 Introduction This booklet captures

More information

grep, awk and sed three VERY useful command-line utilities Matt Probert, Uni of York grep = global regular expression print

grep, awk and sed three VERY useful command-line utilities Matt Probert, Uni of York grep = global regular expression print grep, awk and sed three VERY useful command-line utilities Matt Probert, Uni of York grep = global regular expression print In the simplest terms, grep (global regular expression print) will search input

More information

Published. Technical Bulletin: Use and Configuration of Quanterix Database Backup Scripts 1. PURPOSE 2. REFERENCES 3.

Published. Technical Bulletin: Use and Configuration of Quanterix Database Backup Scripts 1. PURPOSE 2. REFERENCES 3. Technical Bulletin: Use and Configuration of Quanterix Database Document No: Page 1 of 11 1. PURPOSE Quanterix can provide a set of scripts that can be used to perform full database backups, partial database

More information

Shell Scripts (1) For example: #!/bin/sh If they do not, the user's current shell will be used. Any Unix command can go in a shell script

Shell Scripts (1) For example: #!/bin/sh If they do not, the user's current shell will be used. Any Unix command can go in a shell script Shell Programming Shell Scripts (1) Basically, a shell script is a text file with Unix commands in it. Shell scripts usually begin with a #! and a shell name For example: #!/bin/sh If they do not, the

More information

Bash shell programming Part II Control statements

Bash shell programming Part II Control statements Bash shell programming Part II Control statements Deniz Savas and Michael Griffiths 2005-2011 Corporate Information and Computing Services The University of Sheffield Email M.Griffiths@sheffield.ac.uk

More information

Exercise 4 Learning Python language fundamentals

Exercise 4 Learning Python language fundamentals Exercise 4 Learning Python language fundamentals Work with numbers Python can be used as a powerful calculator. Practicing math calculations in Python will help you not only perform these tasks, but also

More information

ImageJ Macro Language Quick-notes.

ImageJ Macro Language Quick-notes. ImageJ Macro Language Quick-notes. This is a very simplified version of the ImageJ macro language manual. It should be enough to get you started. For more information visit http://rsb.info.nih.gov/ij/developer/macro/macros.html.

More information

Systems Programming & Scripting

Systems Programming & Scripting Systems Programming & Scripting Lecture 14 - Shell Scripting: Control Structures, Functions Syst Prog & Scripting - Heriot Watt University 1 Control Structures Shell scripting supports creating more complex

More information

WolfTech Active Directory: PowerShell

WolfTech Active Directory: PowerShell WolfTech Active Directory: PowerShell March 7th, 2012 2-4pm Daniels 201 http://activedirectory.ncsu.edu What we are going to cover... Powershell Basics Listing Properties and Methods of Commandlets.Net

More information

A Crash Course on UNIX

A Crash Course on UNIX A Crash Course on UNIX UNIX is an "operating system". Interface between user and data stored on computer. A Windows-style interface is not required. Many flavors of UNIX (and windows interfaces). Solaris,

More information

Understanding Files and Folders

Understanding Files and Folders Windows Files and Folders Overview Before I get into Windows XP's method of file management, let's spend a little space on a files and folder refresher course. (Just in case you forgot, of course.) The

More information

Microsoft Access 3: Understanding and Creating Queries

Microsoft Access 3: Understanding and Creating Queries Microsoft Access 3: Understanding and Creating Queries In Access Level 2, we learned how to perform basic data retrievals by using Search & Replace functions and Sort & Filter functions. For more complex

More information

Acknowledgments Finding Your Way Around Windows PowerShell p. 1 Getting Started with Windows PowerShell p. 3 Installing Windows PowerShell p.

Acknowledgments Finding Your Way Around Windows PowerShell p. 1 Getting Started with Windows PowerShell p. 3 Installing Windows PowerShell p. Introduction p. xv Acknowledgments p. xx Finding Your Way Around Windows PowerShell p. 1 Getting Started with Windows PowerShell p. 3 Installing Windows PowerShell p. 3 Installing.NET Framework 2.0 p.

More information

Python Lists and Loops

Python Lists and Loops WEEK THREE Python Lists and Loops You ve made it to Week 3, well done! Most programs need to keep track of a list (or collection) of things (e.g. names) at one time or another, and this week we ll show

More information

Command Line - Part 1

Command Line - Part 1 Command Line - Part 1 STAT 133 Gaston Sanchez Department of Statistics, UC Berkeley gastonsanchez.com github.com/gastonstat Course web: gastonsanchez.com/teaching/stat133 GUIs 2 Graphical User Interfaces

More information

WA2099 Introduction to Java using RAD 8.0 EVALUATION ONLY. Student Labs. Web Age Solutions Inc.

WA2099 Introduction to Java using RAD 8.0 EVALUATION ONLY. Student Labs. Web Age Solutions Inc. WA2099 Introduction to Java using RAD 8.0 Student Labs Web Age Solutions Inc. 1 Table of Contents Lab 1 - The HelloWorld Class...3 Lab 2 - Refining The HelloWorld Class...20 Lab 3 - The Arithmetic Class...25

More information

Introduction to Shell Programming

Introduction to Shell Programming Introduction to Shell Programming what is shell programming? about cygwin review of basic UNIX TM pipelines of commands about shell scripts some new commands variables parameters and shift command substitution

More information

Code::Blocks Student Manual

Code::Blocks Student Manual Code::Blocks Student Manual Lawrence Goetz, Network Administrator Yedidyah Langsam, Professor and Theodore Raphan, Distinguished Professor Dept. of Computer and Information Science Brooklyn College of

More information

Microsoft Windows PowerShell v2 For Administrators

Microsoft Windows PowerShell v2 For Administrators Course 50414B: Microsoft Windows PowerShell v2 For Administrators Course Details Course Outline Module 1: Introduction to PowerShell the Basics This module explains how to install and configure PowerShell.

More information

Thirty Useful Unix Commands

Thirty Useful Unix Commands Leaflet U5 Thirty Useful Unix Commands Last revised April 1997 This leaflet contains basic information on thirty of the most frequently used Unix Commands. It is intended for Unix beginners who need a

More information

Note: The scripts in this article should work for XenApp 6 and XenApp 5 for Windows Server 2008 and XenApp 5 for Windows Server 2003.

Note: The scripts in this article should work for XenApp 6 and XenApp 5 for Windows Server 2008 and XenApp 5 for Windows Server 2003. Recently I was asked how to use PowerShell to get a list of offline Citrix XenApp servers. Being new to PowerShell, this gave me an opportunity to use some of my new knowledge. At the time this article

More information

Hands-On Lab. Lab 01: Getting Started with SharePoint 2010. Lab version: 1.0.0 Last updated: 2/23/2011

Hands-On Lab. Lab 01: Getting Started with SharePoint 2010. Lab version: 1.0.0 Last updated: 2/23/2011 Hands-On Lab Lab 01: Getting Started with SharePoint 2010 Lab version: 1.0.0 Last updated: 2/23/2011 CONTENTS OVERVIEW... 3 EXERCISE 1: CREATING A SITE COLLECTION IN SHAREPOINT CENTRAL ADMINISTRATION...

More information

Jeffrey Snover Distinguished Engineer & Lead Architect Jason Helmick Senior Technologist, Concentrated Technology

Jeffrey Snover Distinguished Engineer & Lead Architect Jason Helmick Senior Technologist, Concentrated Technology Jeffrey Snover Distinguished Engineer & Lead Architect Jason Helmick Senior Technologist, Concentrated Technology Meet Jeffrey Snover @jsnover Distinguished Engineer & Lead Architect for Windows Server

More information

File Management Where did it go? Teachers College Summer Workshop

File Management Where did it go? Teachers College Summer Workshop File Management Where did it go? Teachers College Summer Workshop Barbara Wills University Computing Services Summer 2003 To Think About The Beginning of Wisdom is to Call Things by the Right Names --

More information

An Introduction to Using the Command Line Interface (CLI) to Work with Files and Directories

An Introduction to Using the Command Line Interface (CLI) to Work with Files and Directories An Introduction to Using the Command Line Interface (CLI) to Work with Files and Directories Windows by bertram lyons senior consultant avpreserve AVPreserve Media Archiving & Data Management Consultants

More information

Retrieving Data Using the SQL SELECT Statement. Copyright 2006, Oracle. All rights reserved.

Retrieving Data Using the SQL SELECT Statement. Copyright 2006, Oracle. All rights reserved. Retrieving Data Using the SQL SELECT Statement Objectives After completing this lesson, you should be able to do the following: List the capabilities of SQL SELECT statements Execute a basic SELECT statement

More information

How to Back Up and Restore a Dynamics NAV 2015 Database Using SQL and PowerShell:

How to Back Up and Restore a Dynamics NAV 2015 Database Using SQL and PowerShell: How to Back Up and Restore a Dynamics NAV 2015 Database Using SQL and PowerShell: Prerequisite: NAV Server Instance: In these instructions, I do not cover how to configure a NAV Server Instances. However,

More information

VISUAL GUIDE to. RX Scripting. for Roulette Xtreme - System Designer 2.0

VISUAL GUIDE to. RX Scripting. for Roulette Xtreme - System Designer 2.0 VISUAL GUIDE to RX Scripting for Roulette Xtreme - System Designer 2.0 UX Software - 2009 TABLE OF CONTENTS INTRODUCTION... ii What is this book about?... iii How to use this book... iii Time to start...

More information

a high-level language that translate a set of instructions into! )!<24<=.'8'.!.)$4#)4'!,<),!,&)$*.),'!)!*',!->!2$*,&#?,2-$*!2$,-!5)?<2$'!

a high-level language that translate a set of instructions into! )!<24<=.'8'.!.)$4#)4'!,<),!,&)$*.),'!)!*',!->!2$*,&#?,2-$*!2$,-!5)?<2$'! Python!"#$%&!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"#$%!"&''%!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!()*+!,-!.')&$/!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!&')0!)$0!1&2,'%

More information

PIC 10A. Lecture 7: Graphics II and intro to the if statement

PIC 10A. Lecture 7: Graphics II and intro to the if statement PIC 10A Lecture 7: Graphics II and intro to the if statement Setting up a coordinate system By default the viewing window has a coordinate system already set up for you 10-10 10-10 The origin is in the

More information

BIGPOND ONLINE STORAGE USER GUIDE Issue 1.1.0-18 August 2005

BIGPOND ONLINE STORAGE USER GUIDE Issue 1.1.0-18 August 2005 BIGPOND ONLINE STORAGE USER GUIDE Issue 1.1.0-18 August 2005 PLEASE NOTE: The contents of this publication, and any associated documentation provided to you, must not be disclosed to any third party without

More information

We will learn the Python programming language. Why? Because it is easy to learn and many people write programs in Python so we can share.

We will learn the Python programming language. Why? Because it is easy to learn and many people write programs in Python so we can share. LING115 Lecture Note Session #4 Python (1) 1. Introduction As we have seen in previous sessions, we can use Linux shell commands to do simple text processing. We now know, for example, how to count words.

More information

VERITAS NetBackup Microsoft Windows User s Guide

VERITAS NetBackup Microsoft Windows User s Guide VERITAS NetBackup Microsoft Windows User s Guide Release 3.2 Windows NT/95/98 May, 1999 P/N 100-001004 1994-1999 VERITAS Software Corporation. All rights reserved. Portions of this software are derived

More information

1 Description of The Simpletron

1 Description of The Simpletron Simulating The Simpletron Computer 50 points 1 Description of The Simpletron In this assignment you will write a program to simulate a fictional computer that we will call the Simpletron. As its name implies

More information

File by OCR Manual. Updated December 9, 2008

File by OCR Manual. Updated December 9, 2008 File by OCR Manual Updated December 9, 2008 edocfile, Inc. 2709 Willow Oaks Drive Valrico, FL 33594 Phone 813-413-5599 Email sales@edocfile.com www.edocfile.com File by OCR Please note: This program is

More information

Web Editing Tutorial. Copyright 1995-2010 Esri All rights reserved.

Web Editing Tutorial. Copyright 1995-2010 Esri All rights reserved. Copyright 1995-2010 Esri All rights reserved. Table of Contents Tutorial: Creating a Web editing application........................ 3 Copyright 1995-2010 Esri. All rights reserved. 2 Tutorial: Creating

More information

Creating Database Tables in Microsoft SQL Server

Creating Database Tables in Microsoft SQL Server Creating Database Tables in Microsoft SQL Server Microsoft SQL Server is a relational database server that stores and retrieves data for multi-user network-based applications. SQL Server databases are

More information

Excel: Introduction to Formulas

Excel: Introduction to Formulas Excel: Introduction to Formulas Table of Contents Formulas Arithmetic & Comparison Operators... 2 Text Concatenation... 2 Operator Precedence... 2 UPPER, LOWER, PROPER and TRIM... 3 & (Ampersand)... 4

More information

HP-UX Essentials and Shell Programming Course Summary

HP-UX Essentials and Shell Programming Course Summary Contact Us: (616) 875-4060 HP-UX Essentials and Shell Programming Course Summary Length: 5 Days Prerequisite: Basic computer skills Recommendation Statement: Student should be able to use a computer monitor,

More information

Chapter 8 Selection 8-1

Chapter 8 Selection 8-1 Chapter 8 Selection 8-1 Selection (Decision) The second control logic structure is selection: Selection Choosing between two or more alternative actions. Selection statements alter the sequential flow

More information

Hands-on Exercise 1: VBA Coding Basics

Hands-on Exercise 1: VBA Coding Basics Hands-on Exercise 1: VBA Coding Basics This exercise introduces the basics of coding in Access VBA. The concepts you will practise in this exercise are essential for successfully completing subsequent

More information

An Introduction to Number Theory Prime Numbers and Their Applications.

An Introduction to Number Theory Prime Numbers and Their Applications. East Tennessee State University Digital Commons @ East Tennessee State University Electronic Theses and Dissertations 8-2006 An Introduction to Number Theory Prime Numbers and Their Applications. Crystal

More information

VHDL Test Bench Tutorial

VHDL Test Bench Tutorial University of Pennsylvania Department of Electrical and Systems Engineering ESE171 - Digital Design Laboratory VHDL Test Bench Tutorial Purpose The goal of this tutorial is to demonstrate how to automate

More information

Working with forms in PHP

Working with forms in PHP 2002-6-29 Synopsis In this tutorial, you will learn how to use forms with PHP. Page 1 Forms and PHP One of the most popular ways to make a web site interactive is the use of forms. With forms you can have

More information

DOS Command Reference

DOS Command Reference DOS Command Reference Introduction Some course material on the Teaching Network may still use the command line operating system called DOS (Disk Operating System). This requires the user to type specific

More information

AN INTRODUCTION TO UNIX

AN INTRODUCTION TO UNIX AN INTRODUCTION TO UNIX Paul Johnson School of Mathematics September 24, 2010 OUTLINE 1 SHELL SCRIPTS Shells 2 COMMAND LINE Command Line Input/Output 3 JOBS Processes Job Control 4 NETWORKING Working From

More information

Lecture 4: Writing shell scripts

Lecture 4: Writing shell scripts Handout 5 06/03/03 1 Your rst shell script Lecture 4: Writing shell scripts Shell scripts are nothing other than les that contain shell commands that are run when you type the le at the command line. That

More information

Creating a Simple Macro

Creating a Simple Macro 28 Creating a Simple Macro What Is a Macro?, 28-2 Terminology: three types of macros The Structure of a Simple Macro, 28-2 GMACRO and ENDMACRO, Template, Body of the macro Example of a Simple Macro, 28-4

More information

Using Microsoft SyncToy to Automate Backups

Using Microsoft SyncToy to Automate Backups Using Microsoft SyncToy to Automate Backups Downloading and Installing Microsoft SyncToy SyncToy is one of the many PowerToys offered by Microsoft for Windows XP. You can find a list of these utilities

More information

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program. Name: Class: Date: Exam #1 - Prep True/False Indicate whether the statement is true or false. 1. Programming is the process of writing a computer program in a language that the computer can respond to

More information

Powershell Management for Defender

Powershell Management for Defender Powershell Management for Defender 2012 Quest Software, Inc. ALL RIGHTS RESERVED. This guide contains proprietary information protected by copyright. The software described in this guide is furnished under

More information

Cluster to Cluster Failover Using Double-Take

Cluster to Cluster Failover Using Double-Take Cluster to Cluster Failover Using Double-Take Cluster to Cluster Failover Using Double-Take published August 2001 NSI and Double-Take are registered trademarks of Network Specialists, Inc. GeoCluster is

More information

What is a Loop? Pretest Loops in C++ Types of Loop Testing. Count-controlled loops. Loops can be...

What is a Loop? Pretest Loops in C++ Types of Loop Testing. Count-controlled loops. Loops can be... What is a Loop? CSC Intermediate Programming Looping A loop is a repetition control structure It causes a single statement or a group of statements to be executed repeatedly It uses a condition to control

More information

CPSC2800: Linux Hands-on Lab #3 Explore Linux file system and file security. Project 3-1

CPSC2800: Linux Hands-on Lab #3 Explore Linux file system and file security. Project 3-1 CPSC2800: Linux Hands-on Lab #3 Explore Linux file system and file security Project 3-1 Linux support many different file systems that can be mounted using the mount command. In this project, you use the

More information

1. a procedure that you perform frequently. 2. Create a command. 3. Create a new. 4. Create custom for Excel.

1. a procedure that you perform frequently. 2. Create a command. 3. Create a new. 4. Create custom for Excel. Topics 1 Visual Basic Application Macro Language What You Can Do with VBA macro Types of VBA macro Recording VBA macros Example: MyName () If-Then statement Example: CheckCell () For-Next Loops Example:

More information

Opening a Command Shell

Opening a Command Shell Opening a Command Shell Win Cmd Line 1 In WinXP, go to the Programs Menu, select Accessories and then Command Prompt. In Win7, go to the All Programs, select Accessories and then Command Prompt. Note you

More information

The Center for Teaching, Learning, & Technology

The Center for Teaching, Learning, & Technology The Center for Teaching, Learning, & Technology Instructional Technology Workshops Microsoft Excel 2010 Formulas and Charts Albert Robinson / Delwar Sayeed Faculty and Staff Development Programs Colston

More information

Perl in a nutshell. First CGI Script and Perl. Creating a Link to a Script. print Function. Parsing Data 4/27/2009. First CGI Script and Perl

Perl in a nutshell. First CGI Script and Perl. Creating a Link to a Script. print Function. Parsing Data 4/27/2009. First CGI Script and Perl First CGI Script and Perl Perl in a nutshell Prof. Rasley shebang line tells the operating system where the Perl interpreter is located necessary on UNIX comment line ignored by the Perl interpreter End

More information

NØGSG DMR Contact Manager

NØGSG DMR Contact Manager NØGSG DMR Contact Manager Radio Configuration Management Software for Connect Systems CS700 and CS701 DMR Transceivers End-User Documentation Version 1.24 2015-2016 Tom A. Wheeler tom.n0gsg@gmail.com Terms

More information

Learn Perl by Example - Perl Handbook for Beginners - Basics of Perl Scripting Language

Learn Perl by Example - Perl Handbook for Beginners - Basics of Perl Scripting Language Learn Perl by Example - Perl Handbook for Beginners - Basics of Perl Scripting Language www.freebsdonline.com Copyright 2006-2008 www.freebsdonline.com 2008/01/29 This course is about Perl Programming

More information

This loop prints out the numbers from 1 through 10 on separate lines. How does it work? Output: 1 2 3 4 5 6 7 8 9 10

This loop prints out the numbers from 1 through 10 on separate lines. How does it work? Output: 1 2 3 4 5 6 7 8 9 10 Java Loops & Methods The while loop Syntax: while ( condition is true ) { do these statements Just as it says, the statements execute while the condition is true. Once the condition becomes false, execution

More information

9 Control Statements. 9.1 Introduction. 9.2 Objectives. 9.3 Statements

9 Control Statements. 9.1 Introduction. 9.2 Objectives. 9.3 Statements 9 Control Statements 9.1 Introduction The normal flow of execution in a high level language is sequential, i.e., each statement is executed in the order of its appearance in the program. However, depending

More information

CS170 Lab 11 Abstract Data Types & Objects

CS170 Lab 11 Abstract Data Types & Objects CS170 Lab 11 Abstract Data Types & Objects Introduction: Abstract Data Type (ADT) An abstract data type is commonly known as a class of objects An abstract data type in a program is used to represent (the

More information

Creating Basic Excel Formulas

Creating Basic Excel Formulas Creating Basic Excel Formulas Formulas are equations that perform calculations on values in your worksheet. Depending on how you build a formula in Excel will determine if the answer to your formula automatically

More information

A Guide To. File Butler. By Denver Tax Software, Inc.

A Guide To. File Butler. By Denver Tax Software, Inc. A Guide To File Butler By Denver Tax Software, Inc. Copyright 2003 Denver Tax Software, Inc. Denver Tax Software, Inc. P.O. Box 5308 Denver, CO 80217-5308 Telephone (voice): Toll-Free: 1(800)326-6686 Denver

More information

MATLAB Programming. Problem 1: Sequential

MATLAB Programming. Problem 1: Sequential Division of Engineering Fundamentals, Copyright 1999 by J.C. Malzahn Kampe 1 / 21 MATLAB Programming When we use the phrase computer solution, it should be understood that a computer will only follow directions;

More information

Xylophone. What You ll Build

Xylophone. What You ll Build Chapter 9 Xylophone It s hard to believe that using technology to record and play back music only dates back to 1878, when Edison patented the phonograph. We ve come so far since then with music synthesizers,

More information

Getting started with the Stata

Getting started with the Stata Getting started with the Stata 1. Begin by going to a Columbia Computer Labs. 2. Getting started Your first Stata session. Begin by starting Stata on your computer. Using a PC: 1. Click on start menu 2.

More information

Introduction to Shell Scripting

Introduction to Shell Scripting Introduction to Shell Scripting Lecture 1. Shell scripts are small programs. They let you automate multi-step processes, and give you the capability to use decision-making logic and repetitive loops. 2.

More information

Setting Up Database Security with Access 97

Setting Up Database Security with Access 97 Setting Up Database Security with Access 97 The most flexible and extensive method of securing a database is called user-level security. This form of security is similar to methods used in most network

More information

warpct.com Basic Computer Skills MS Windows XP Workbook courseware by WARP! Computer Training

warpct.com Basic Computer Skills MS Windows XP Workbook courseware by WARP! Computer Training warpct.com courseware by WARP! Computer Training Basic Computer Skills MS Windows XP Workbook Welcome! Thank you for evaluating a portion of this workbook. If you have any questions or comments regarding

More information

ESCI 386 IDL Programming for Advanced Earth Science Applications Lesson 6 Program Control

ESCI 386 IDL Programming for Advanced Earth Science Applications Lesson 6 Program Control ESCI 386 IDL Programming for Advanced Earth Science Applications Lesson 6 Program Control Reading: Bowman, Chapters 16 CODE BLOCKS A code block consists of several lines of code contained between a BEGIN

More information

Installing Java 5.0 and Eclipse on Mac OS X

Installing Java 5.0 and Eclipse on Mac OS X Installing Java 5.0 and Eclipse on Mac OS X This page tells you how to download Java 5.0 and Eclipse for Mac OS X. If you need help, Blitz cs5help@cs.dartmouth.edu. You must be running Mac OS 10.4 or later

More information

Chapter 1: Getting Started

Chapter 1: Getting Started Chapter 1: Getting Started Every journey begins with a single step, and in ours it's getting to the point where you can compile, link, run, and debug C++ programs. This depends on what operating system

More information

Visual Logic Instructions and Assignments

Visual Logic Instructions and Assignments Visual Logic Instructions and Assignments Visual Logic can be installed from the CD that accompanies our textbook. It is a nifty tool for creating program flowcharts, but that is only half of the story.

More information

First Java Programs. V. Paúl Pauca. CSC 111D Fall, 2015. Department of Computer Science Wake Forest University. Introduction to Computer Science

First Java Programs. V. Paúl Pauca. CSC 111D Fall, 2015. Department of Computer Science Wake Forest University. Introduction to Computer Science First Java Programs V. Paúl Pauca Department of Computer Science Wake Forest University CSC 111D Fall, 2015 Hello World revisited / 8/23/15 The f i r s t o b l i g a t o r y Java program @author Paul Pauca

More information

Creating and Using Master Documents

Creating and Using Master Documents Creating and Using Master Documents Title: Creating and Using Master Documents Version: 0.3 First edition: 09/04 Contents Overview...2 Acknowledgments...2 Modifications and updates... 2 Why use a master

More information

Using Casio Graphics Calculators

Using Casio Graphics Calculators Using Casio Graphics Calculators (Some of this document is based on papers prepared by Donald Stover in January 2004.) This document summarizes calculation and programming operations with many contemporary

More information

Lecture 2 Notes: Flow of Control

Lecture 2 Notes: Flow of Control 6.096 Introduction to C++ January, 2011 Massachusetts Institute of Technology John Marrero Lecture 2 Notes: Flow of Control 1 Motivation Normally, a program executes statements from first to last. The

More information

Example of a Java program

Example of a Java program Example of a Java program class SomeNumbers static int square (int x) return x*x; public static void main (String[] args) int n=20; if (args.length > 0) // change default n = Integer.parseInt(args[0]);

More information

Welcome to GAMS 1. Jesper Jensen TECA TRAINING ApS jensen@tecatraining.dk. This version: September 2006

Welcome to GAMS 1. Jesper Jensen TECA TRAINING ApS jensen@tecatraining.dk. This version: September 2006 Welcome to GAMS 1 Jesper Jensen TECA TRAINING ApS jensen@tecatraining.dk This version: September 2006 1 This material is the copyrighted intellectual property of Jesper Jensen. Written permission must

More information

Running Wordstar 6 on Windows 7 Using vdos

Running Wordstar 6 on Windows 7 Using vdos Running Wordstar 6 on Windows 7 Using vdos Version 2.0 Bruce Hartford Thanks to Dennis McCunney and Robert J. Sawyer for helping me learn how to set vdos up. Contents: Phase 1: Setting up vdos on page

More information

Importing Xerox LAN Fax Phonebook Data from Microsoft Outlook

Importing Xerox LAN Fax Phonebook Data from Microsoft Outlook Xerox Multifunction Devices September 4, 2003 for the user Importing Xerox LAN Fax Phonebook Data from Microsoft Outlook Purpose This document provides instructions for importing the Name, Company, Business

More information

MS Visual C++ Introduction. Quick Introduction. A1 Visual C++

MS Visual C++ Introduction. Quick Introduction. A1 Visual C++ MS Visual C++ Introduction 1 Quick Introduction The following pages provide a quick tutorial on using Microsoft Visual C++ 6.0 to produce a small project. There should be no major differences if you are

More information