gpt4 book ai didi

powershell - 如何更改 PowerShell Cmdlet 的默认确认选项?

转载 作者:行者123 更新时间:2023-12-01 18:22:35 25 4
gpt4 key购买 nike

有没有办法更改 High Impact PowerShell 脚本的默认确认选项?

当我实现 Cmdlet 并运行它时要求确认,例如

MyPS

Confirm
Are you sure you want to perform this action?
Performing operation "XYZ" on Target "123".
[Y] Yes [A] Yes to All [N] No [L] No to all [S] Suspend [?] Help (default is "Y"):

如何更改默认值?我想将默认值从“Y”更改为“N”。

最佳答案

有点不清楚你想问什么。您是否想知道如何设置全局默认值(对于给定的 PowerShell session )以抑制默认情况下提示确认的 cmdlet 的确认提示,这样您就不必继续指定 -Confirm:$false 每次运行它们时?设置默认变量:

$ConfirmPreference = $false

或者您想知道如何更改特定 cmdlet 的确认影响?在脚本开头声明 [CmdletBinding(ConfirmImpact = 'high')]。请注意,如果您声明 CmdletBinding,则需要 param() block ,即使它为空。

关于powershell - 如何更改 PowerShell Cmdlet 的默认确认选项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20061003/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com