PowerShell-如何以编程方式确定是否设置了StrictMode



我知道我可以在脚本或函数中重写从更高范围继承的StrictMode设置。但是,我如何才能在脚本或函数中找到继承的设置?

也许一个小函数可以帮助:

function Get-StrictMode {
# returns the currently set StrictMode version 1, 2, 3
# or 0 if StrictMode is off.
try { $xyz = @(1); $null = ($null -eq $xyz[2])}
catch { return 3 }
try { "Not-a-Date".Year }
catch { return 2 }
try { $null = ($undefined -gt 1) }
catch { return 1 }
return 0
}
Get-StrictMode

最新更新