powershell PowerShell中-WhatIf和-Confirm的示例

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了powershell PowerShell中-WhatIf和-Confirm的示例相关的知识,希望对你有一定的参考价值。

# Usage examples
#   .\whatif.ps1 "Hello, World!"
#   .\whatif.ps1 "Hello, World!" -WhatIf
#   .\whatif.ps1 "Hello, World!" -Confirm
#   .\whatif.ps1 "Hello, World!" -Confirm:$False

# This is an example on how to use SupportsShouldProcess to implement
# the -WhatIf and -Confirm flags for your script

# Try setting the ConfirmImpact to "High" to enforce a confirmation from the
# user. This confirmation can be supressed by using the -Confirm:$False flag

[CmdletBinding(
    SupportsShouldProcess = $true,
    ConfirmImpact = "Medium"
)]

param (
    [string] $Greetings = "Hello, User"
)

$ErrorActionPreference = "Stop"

Write-Verbose ("Using greeting " -f $Greetings)

if($PSCmdlet.ShouldProcess($Greetings, "Greet user")){
    Write-Verbose "greeting the user..."
    Write-Output $Greetings
}

以上是关于powershell PowerShell中-WhatIf和-Confirm的示例的主要内容,如果未能解决你的问题,请参考以下文章

lduan office 365 Windows PowerShell管理O365平台 六

Powershell 3.0:保存工作脚本后,如果我关闭然后重新打开脚本,当我尝试运行它时会收到一条错误消息

powershell 使用powershell #powershell从zip文件中删除文件

powershell怎么运行

powershell PowerShell:在PowerShell控制台中更改错误,警告,调试颜色

Powershell:在 PowerShell 中重新加载路径