Part 1: CHANGENAMES.BAT
Create a batch file CHANGENAMES.BAT that does the following (note that %1, %2, and %3 refer to command line arguments passed to the batch file when executed):
Creates a set of %1 empty files with randomly generated names, with filename extension %2.
Uses the dir command to display a list of the file names.
Uses the pause command to pause execution until the user strikes a key.
Changes the filename extension of these files from %2 to %3.
Uses the dir command to display a list of the modified file names.
Pause
Uses the del /p to delete the files with extension %3. The /p option will cause the command to prompt for a confirmation before the deletion of each file.
Part 2: changenames.ps1 and pspause.ps1
Write a PowerShell script changenames.ps1 to repeat the task of the CHANGENAMES.BAT batch file. Note that there is no "pause" command in PowerShell, so you should write your own, with help from Google. Organize this as a separate script file pspause.ps1 and call this script file from the changenames.ps1 script file.
NOTE: you may not call any .bat file from either .ps1 file. (You must solve the pause problem another way.)
Part 3: calc.ps1
Write a PowerShell script named calc.ps1 that performs simple arithmetic calculations of the form
> calc 3 + 4
7
> calc 8 * 3
24
...
You need only support +, -, *, and / operations.
PowerShell Basics
Script Structure
param($p1,$p2,...) ç list of params at the top
function f($a,$b,$c) { ç some function
$result = ...
...
Write-output $result
}
...
function g(...) { ç another function
...
}
... main program ... ç the actual script starts here
Comments
# this is a one liner
<# this
spans multiple lines #>
Comparisons
-eq -ne -lt -le -gt -ge
Boolean Operations
-and -or -not
Boolean Constants
$true $false
Loops
$i = 1
while ($i -le 10) {
Write-output $i
$i++
}
If-Else
if (...) {
...
}
elseif (...) {
...
}
elseif (...) {
...
}
Calling a Function
function f($a, $b, $c) {
...
return ...
}
$x = f 1 2 3 ç don't write f(1,2,3)