forked from nightroman/PowerShellTraps
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest-1-command-and-script.ps1
More file actions
26 lines (20 loc) · 922 Bytes
/
Test-1-command-and-script.ps1
File metadata and controls
26 lines (20 loc) · 922 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# results to be tested
$results = New-Object System.Collections.Specialized.OrderedDictionary
# Q: What happens if PowerShell invokes this command?
# A: It exits with code 1.
$results.text1 = Invoke-PowerShell -NoProfile -Command "'Hello'; Write-Error Oops"
$results.code1 = $LASTEXITCODE
# Q: What happens if PowerShell invokes the same command as a script?
# A: It exits with code 0.
$results.text2 = Invoke-PowerShell -NoProfile -Command .\Script1.ps1
$results.code2 = $LASTEXITCODE
# Q: What if the same script is dot-sourced as if its code is placed here?
# A: It exits with code 0.
$results.text3 = Invoke-PowerShell -NoProfile -Command . .\Script1.ps1
$results.code3 = $LASTEXITCODE
# Q: What if the command last statement has no error?
# A: It exits with code 0.
$results.text4 = Invoke-PowerShell -NoProfile -Command "Write-Error Oops; 'Hello'"
$results.code4 = $LASTEXITCODE
# results for testing
$results