【发布时间】:2016-02-05 05:11:26
【问题描述】:
我在搜索中引用了这个问题:how to use 'dry-run' in powershell,我已经明白了它在说什么。
我的问题是:
我能否拥有一个调用 -whatif 的 Powershell 脚本,然后返回确认提示以运行真正的命令?
一个例子:
#Disable Exchange access
set-casmailbox $1.samaccountname -ewsallowentourage $false -ecpenabled $false -ewsallowoutlook $false -ewsallowmacoutlook $false -activesyncenabled $false -owaenabled $false -OWAforDevicesEnabled $false -mapihttpenabled $false -ewsenabled $false -mapienabled $false
我希望上面包含一个 -WhatIf,然后是一个提示以确认是否运行真正的命令。
我认为我可以通过以下方式稍微草率地做到这一点:
#Check what happens if I disable Exchange Access
set-casmailbox $1.samaccountname -ewsallowentourage $false -ecpenabled $false -ewsallowoutlook $false -ewsallowmacoutlook $false -activesyncenabled $false -owaenabled $false -OWAforDevicesEnabled $false -mapihttpenabled $false -ewsenabled $false -mapienabled $false -whatif
#Prompt for Confirmation to actually disable Exchange Access
set-casmailbox $1.samaccountname -ewsallowentourage $false -ecpenabled $false -ewsallowoutlook $false -ewsallowmacoutlook $false -activesyncenabled $false -owaenabled $false -OWAforDevicesEnabled $false -mapihttpenabled $false -ewsenabled $false -mapienabled $false -confirm
但我很好奇是否有更好的方法,特别是因为上面是一个简单的单行命令而不是 foreach 等。
【问题讨论】:
标签: powershell