Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

I have no idea where to start my homework. Would you help me out, please?

$
0
0

Normal 0 false false false false EN-US X-NONE X-NONE

Hello, there. I have no idea where to start with this assignment (Exercise 2; Step 1 - 9).

 

I hope somebody please helped me. (I know it is not a good way to learn Powershell to

 

ask this kind of question. But, I cannot help myself. I feel so embassrassed.

 

And I would like to understand how it works.

 

Thank you. Good evening.

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

Exercise 2:  Creating the Win213 Repository – Using Conditional Control Structure

Commands

Purpose

Wk8

 
<#      #>

Multiline comment

Wk9

 
Clear-Host

Clears the console

Wk100

 
IF (condition) {script block}

Tests of a condition

Wk110

 
Get-Location

Gets the current working directory

Wk120

 
Set-Location

Sets the current working directory

Pause

Suspends a script. Prompts user “Press Enter to continue”

Test-Path

Tests if a path is true of false

Write-Host

Displays message on console

The commads used in this script are listed above.In this exercise, we will  use a conditional statement to check whether  the user is in the documents folder, and if not, give him/her the chance to exit the script or continue.

  1. Wk6

     

    Wk5

     

    Wk4

     

    Wk3

     

    Wk2

     

    Wk1

     
    Copy the script template to a new tab. Name the file LearnName_Lab5_Win213Rep.ps1
  2. Modify the Syntax to reflect that the user must be in the documents folder to run the script
  3. ##Create variables to store the documents, Win213,and Scripts folder path
    #############################################################################
    1. Name the variables DocumentsPath, Win213Path, and ScriptsPath
  4. ##Create variables to hold the collection of folder names for Win213 folder and Scripts folder
    ##############################################################################
    1. Separate each folder name with a comma (double quotes around each name)
  5. ##Test if user in Documents folder, if not display message giving the option to exit or ##continue,if  continue change to documents folder and make Win213 folder
    ##############################################################################
    1. This is a common scripting technique you need to learn.

                                                              i.     Create a variable to store the current prompt location

                                                            ii.     Use Test-Path cmdlet to see if the current location is the same as the document path variable you created in step 1.  If it is, then make the directory, if not display this message “"This script only runs in the documents directory. Change to the documents directory and continue? Press CTRL + C to exit or "

                                                           iii.     Add the pause command

                                                          iv.     Change to the documents folder and make the Win213 folder.

 

Wk7

 
Exercise 3: Challenge – Creating the Win213 Repository -  Using Iterative Control Structure

Commands

Purpose

Wk8

 
Foreach($dir in<collection>{…}

Cycles through a collection performing the commands in the script block on each item in the collection

Wk9

 
New-Item

Creates a new file or directory

Wk100

 
Get-ChildItem

Displays a directory listing of the current folder

Optional Step 8

Where-Object{…}

Sorts objects based on criteria

$_

Pipeline variable holds an item in the pipeline

Move-Item

Moves and renames files or directories

 

In this exercise you will create a foreach loop to cycle through the folder names collection, replacing the New-Item name parameter with the folder name on each loop.  This is an excellent technique to use to change the New-Item command, only the collection names in the variable at the beginning of the script need be changed, the rest of the script stays the same.

  1. ## Cycle through the Win213 folder names using a foreach loop
    #############################################################################
  2. ##Cycle through the Scripts folder using a foreach loop
    ##############################################################################
    See Optional 8 and 9 below and decide which option you want to do.
  3. ##Do a recursive search of the documents folder to find all files PS1 and CMD files
    #############################################################################
    1. Save the output to a variable called Files.
  4.  Now manually, copy and paste the files based on LastWriteTime to the correct week subfolder.  Scripts created in week 2 go to Wk2 folder, etc.

·         If LastWriteTime is between Jan 6 and Jan 12  move to Wk1

·        If LastWriteTime is between Jan 13 and Jan 19 move to Wk2

·        If LastWriteTime is between Jan 20 and Jan 26 move to Wk3

·        If LastWriteTime is between Jan 27 and Feb 2 move to Wk4

·        If LastWriteTime is greater than Feb 2 move to Wk5

 


Viewing all articles
Browse latest Browse all 6937

Trending Articles