I referenced this question: how to use 'dry-run' in powershell in my search and I get what it is saying already.
My question though is:
Can I have a Powershell script that invokes a -whatif, then comes back with a confirmation prompt to run the real command(s)?
An example:
#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
I would like the above to include a -WhatIf and then a prompt to confirm whether to run the real command(s) or not.
I figure I can do it somewhat sloppily by using:
#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
But I was curious if there's a better way, especially since the above is a simple single line command versus a foreach,etc.