If you use a param on your script, then you can just .\Script.ps1 -DebugLog
[CmdletBinding()]
param(
[switch]$DebugLog
)
if ($DebugLog) {
Start-Transcript "D:\_Debug.log"
}
function Test-Reg {
Write-Host "Adding test registry keys..."
reg.exe add HKCU\test /f $nul
reg.exe query HKCU\test $nul
if ($LASTEXITCODE -eq 0) {
Write-Host "Done."
}
else {
Write-Host "Failed."
}
Write-Host "Deleting test registry keys..."
reg.exe delete HKCU\test /f $nul
reg.exe query HKCU\test $nul
if ($LASTEXITCODE -eq 0) {
Write-Host "Failed."
}
else {
Write-Host "Done."
}
}
Test-Reg
if ($DebugLog) {
Stop-Transcript
}