Lab moving from script to function to module scenario.
You have written a script that performs an administrative task in your environment.
You have to package that script as a Windows PowerShell script module so that it can be more easily
used by other administrators in your environment.
Exercise one.
Convert the script to a function.
Task one.
Add the function declaration.
Note These instructions provide a starting point that does not require you to have completed any prior
lab tasks.
The starting point includes all tasks up to this one.
If you are working on your own script, you can compare it to the starting point before you attempt
this task.
One.
Close.
All open files in the ISC.
Two on the file menu.
Click open.
Three.
Navigate to the scripts, location and open exercise one.
Task 1.1.
Four.
Press Control Plus eight.
To Select all the content.
Five.
Press tab to indent the content.
Six.
Online one.
Add the following function.
Get this info.
Seven online 28 Add the following eight on the file menu.
Click Save as nine in the file name box type C colon backslash tools dot PS1 and then press enter if
you are prompted in the confirmed save as dialog box click yes.
Task to execute the function note.
These instructions provide a starting point that does not require you to have completed any prior lab
tasks.
The starting point includes all tasks up to this one.
If you are working on your own script, you can compare it to the starting point before you attempt
this task.
One close all open files in the IAC on the file menu.
Click open to navigate to the scripts location and open exercise one Task 2.1.
Three Online 30 Add the following get disk info comp local host for on the file menu click save as five
in the file name box type C colon backslash tools dot PS1 and then press enter six in the confirm save
as dialog box click yes.
Task three test the script.
Note These instructions provide a starting point that does not require you to have completed any prior
lab tasks.
The starting point includes all tasks up to this one.
If you are working on your own script, you can compare it to the starting point before you attempt
this task.
One close all open files in the ISC on the file menu select open to navigate to your scripts, location
and open exercise one Task 3.13 on the file menu Select Save as four in the file name box type C colon
backslash tools dot PS1 and then press enter.
Five in the confirm save as dialog box click.
Yes.
Six.
Press f five.
Exercise to save the script as a script module.
Task one Remove the function call.
Note These instructions provide a starting point that does not require you to have completed any prior
lab tasks.
The starting point includes all tasks up to this one.
If you are working on your own script, you can compare it to the starting point before you attempt
this task.
One close all open files in the ISC on the file menu.
Click open to navigate to our scripts, location and open exercise two Task 1.13 on the file menu Click
Save as four in the file name box type C colon backslash tools dot one and then press enter.
Five in the confirmed save as dialog box click.
Yes.
Six.
Delete line 37.
Press Control Plus s task to save the script as a script module.
Note These instructions provide a starting point that does not require you to have completed any prior
lab tasks.
The starting point includes all tasks up to this one.
If you are working on your own script, you can compare it to the starting point before you attempt
this task.
One on the taskbar.
Click the file Explorer icon to open a new file Explorer Window two in the Left Tree View.
Click the documents library.
Three.
Expand the documents library and click documents four on the ribbon click new folder.
Five.
Type Windows PowerShell and Press Enter six.
Double click the Windows PowerShell folder seven on the ribbon.
Click the new folder button.
Eight type modules and press enter.
Nine Double click the modules folder.
Ten on the ribbon click new folder.
11 Type my tools and press enter.
12 Closed the file Explorer Window.
13 Click the Windows PowerShell IAC Window.
14 On the file menu.
Click Open.
15 Navigate to your scripts, location and open exercise.
Two Task 2.1.
16 On the file menu.
Click Save Errors.
17 In the file name box type.
C Colon Backslash Users Backslash User Single Quote.
S Home Directory Backslash Documents Backslash Windows PowerShell backslash modules backslash my tools
backslash my tools dot PSM one and then press enter.
Task three Test the script module.
Note Ensure that you complete the prior task before you attempt this task.
One in the Windows PowerShell ISC Press Control plus d to type the following and press enter get disk
info comp local host three Type the following and press enter because the module may not be loaded.
This command may produce an error that you may ignore.
Remove module my tools.
Exercise three and debugging breakpoints.
Task one at a break point.
Note These instructions provide a starting point that does not require you to have completed any prior
lab tasks.
The starting point includes all tasks up to this one.
If you are working on your own script, you can compare it to the starting point before you attempt
this task.
One close all open files in the IAC on the file menu.
Click open to navigate to to your scripts location and open exercise 3.13 on the file menu click save
as.
Forward in the file name box type C colon backslash users backslash your user's home directory backslash
documents backslash windows PowerShell backslash module's backslash my tool's backslash my tools dot
psm one and then press enter.
Five in the confirmed save as dialog box click.
Yes.
Six online 23.
Add the following write debug about to query dollar computer name seven.
Press Control plus s to save the file.
Eight Close the file task to test the script module.
Note These instructions provide a starting point that does not require you to have completed any prior
lab tasks.
The starting point includes all tasks up to this one.
If you are working on your own script, you can compare it to the starting point before you attempt
this task.
One on the file menu.
Click open to navigate to your scripts, location and open exercise.
Three Task 2.13 on the file menu.
Click Save As.
Forward in the file name box type C colon backslash users backslash your user's home directory backslash
documents backslash windows PowerShell backslash module's backslash my tool's backslash my tool's dot
PSM one and then press enter.
Five in the confirms save as dialog box click.
Yes.
Six.
Press control plus D seven.
Type the following and press enter.
Get Disc Info comp local host eight.
Type the following and press enter.
Get disk info.
Comp local.
Host debug nine.
Press s to suspend the operation.
Ten.
Type the following and press enter dollar computer.
Name 11.
Type the following and press enter exit.
12.
Press y 13.
Type the following and press enter.
Remove module my tools.