运行 PS 带参数的脚本

running PS script with arguments

我知道如何 运行 使用 script.ps1 -arcive=true 等参数编写脚本 但我正在尝试使用 script.ps1 -archive 等参数 运行 我的脚本。 这可能吗?

您正在寻找一个开关。和参数是同一个概念,因为都是参数。

 param (
    [string] $randomParameter,
    [switch] $archive = $false
 )

$archive 将是 false,除非你调用:script.ps1 -archive,然后它将是 true