EncodedCommand対策した$PROFILE ついでにPromptForChoiceの簡単な使い方を覚えたので、実行確認に使ってみる
function Show-PromptForChoice {
[CmdletBinding()]
param(
[parameter(Mandatory,Position=0)]
[string] $Title,
[parameter(Mandatory,Position=1)]
[string] $Info,
[parameter(Mandatory,Position=2)]
[string[]] $Options,
[parameter(Mandatory=$false)]
[int] $DefaultChoice = 0
)
$opts = [System.Management.Automation.Host.ChoiceDescription[]] $Options
return $host.UI.PromptForChoice($Title , $Info , $opts, $DefaultChoice)
}
if ([System.Environment]::CommandLine -match '-EncodedCommand')
{
Write-Warning "EncodedCommandが使われています!"
$ret = Show-PromptForChoice '<EncodedCommand>' '安全でないコマンドが実行されようとしています、続けますか?' @('いいえ(&N)', 'はい(&Y)')
if ($ret -ne 1)
{
# 続行しない場合は止める
kill $PID
}
}