Question

Instructions PowerShell Assignment #1 Objective: Learn basic Powershell scripting in Windows Setup: A Windows computer with...

Instructions

PowerShell Assignment #1

Objective:

  • Learn basic Powershell scripting in Windows

Setup:

  • A Windows computer with the latest Powershell environment installed

Script #1 – Hello World!

Description:  The classical introductory exercise: Just say "Hello, World!".

Purpose: A "Hello, World!" program is traditionally used to introduce novice programmers to a programming language. It is also to make sure that the interpreter is installed correctly, and that the user understands how to use it.

Instructions:  Complete this assignment to make sure that you know how to start PowerShell and create a new script.

  • Write a script that displays the string "Hello, World!"
  • Test the script to make sure it operates correctly.
  • Save the script in a .ps1 file, this will be one of the files that you submit to D2L
  • Take a print screen to show that the script is working correctly
  • Submit the script and print screen files.

Script #2 – Leap Year

Description:  Given a year, report if it is a leap year.

Purpose: Learn the use of if statements.

Instructions:  Complete this assignment to make sure that you know how to use if statements in Powershell.

A leap year in the Gregorian calendar occurs:

  • on every year that is evenly divisible by 4
  • except every year that is evenly divisible by 100
  • unless the year is also evenly divisible by 400
  • Write a script that prompts a user for a year. After the users enters the year, inform the user if the year is a leap year.
  • Test the script to make sure it operates correctly.
  • Save the script in a .ps1 file, this will be one of the files that you submit to D2L
  • Take a print screen to show that the script is working correctly
  • Submit the script and print screen files.

Script #3 – Temp Folder

Description: Find the Windows temp folder and get information about the folder.

Purpose: Learn how to use Environmental variables.

Instructions: Discover the TEMP folder on the local system and basic information about the folder.

  • Write a script that finds the temp folder for the system and gets information basic information about the folder.
  • Test the script to make sure it operates correctly.
  • Save the script in a .ps1 file, this will be one of the files that you submit to D2L
  • Take a print screen to show that the script is working correctly
  • Submit the script and print screen files.

Homework Answers

Answer #1

Script #1 – Hello World!

Following are the Hello World! Power shell script and output

-------------------------------------------------------------

$str1 = "Hello World!"
write-host $str1

--------------------------------------------------------

First line assigns the value Hello World to str1 and the command write-host prints the str1 value to the console

Script #2 – Leap Year

Following is the Power shell script and output to check a given year is leap year or not

---------------------------------------------------------------------------------

$year=Read-Host -Prompt 'Please enter a year'

foreach ($yr in $Year) {
            if ($yr / 400 -is [int]) {
                Write-Host "$yr is a leap year"
            }

            elseif ($yr / 100 -is [int]) {
                Write-Host "$yr is not a leap year"
            }
            elseif ($yr / 4 -is [int]) {
                Write-Host "$yr is a leap year"
            }
            else {
                Write-Host "$yr is not a leap year"
            }
}

-------------------------------------------------------------------------------

The above script checks that the entered year is divisible by 400,100 and 4. If it is divisible by 400 script prints that it is a leap year.Else it check that given year is divisible by 100 , if yes script prints it is not a leap year. Else check by dividing the year by 4 and if yes prints that the year is a leap year. If all the above conditons are false, script will print that it is not a leap year

Script #3 – Temp Folder

Following are the script and output for display information about the TEMP folder

----------------------------------

get-childitem $Env:TEMP

------------------------------------

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Script #2 – Leap Year Description:  Given a year, report if it is a leap year. Purpose:...
Script #2 – Leap Year Description:  Given a year, report if it is a leap year. Purpose: Learn the use of if statements. Instructions:  Complete this assignment to make sure that you know how to use if statements in Powershell. A leap year in the Gregorian calendar occurs: on every year that is evenly divisible by 4 except every year that is evenly divisible by 100 unless the year is also evenly divisible by 400 Write a script that prompts a user...
You will write a program that loops until the user selects 0 to exit. In the...
You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an...
Challenge 5 Read ALL of the instructions carefully before starting the exercise! Dear Colleague, Earlier today...
Challenge 5 Read ALL of the instructions carefully before starting the exercise! Dear Colleague, Earlier today I built my fourth website using HTML5 and CSS3. This time I wanted to try using CSS float layout options on a website dedicated to my favorite topic: robotics. I wanted my website to look like what is shown in Figure 1 (see below). However, after giving it my best effort, things once again didn’t turn out the way I wanted (see the code...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT