Ken Maglio
Automation Solution Engineer My License Plate says it all "I-AU2M8"
Functions are your Friends
get-command -CommandType functioncd function:dir function: or ls function:Find variables that change or prompt users for input; move first
Find all hard-coded variables; move second
Work with variables follows
Output final result
Example
$a = 4
$b = 5
$c = $a + $b
Write-Host $cExample + User Input
[int]$a = Read-Host -Prompt "A"
[int]$b = Read-Host -Prompt "B"
$message = "Your Result:"
$c = $a + $b
Write-Host $message $cConvert to 'Basic' Function
function Add([int]$a, [int]$b) {
$message = "Your Result:"
$c = $a + $b
Write-Host $message $c
}[int]$a = Read-Host -Prompt "A"
[int]$b = Read-Host -Prompt "B"
$message = "Your Result:"
$c = $a + $b
Write-Host $message $cBut nothing happens!!!
function Add([int]$a, [int]$b) {
$message = "Your Result:"
$c = $a + $b
Write-Host $message $c
}[int]$a = Read-Host -prompt "A"
[int]$b = Read-Host -prompt "B"
Add $a $bBy Ken Maglio
Functions are your Friends
Automation Solution Engineer My License Plate says it all "I-AU2M8"