Created
March 30, 2018 00:42
-
-
Save tostka/bbe9bed3d6852b0f7c96b29e7fa5b5d0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# This is a code block that uses a splat to run an updating cmdlet | |
It uses a splat for the params, echo's the pre & post values, and the splat for the changes, | |
and supports whatif etc. | |
USAGE: | |
1. Update the TARGCMDLET with the real cmdlet ("set-exoOwaMailboxPolicy") | |
2. Update the $splat with target params for updating | |
3. Update the $props with an array ("PROP1","PROP2")of the prop names to be reported back (freq they match the $splat values) | |
4. Replace the GET-CMDLET with the real cmdlet's get-XXX variant. | |
5. Use $whatif=$true/$false to test and live-fire. | |
#> | |
#-=-=-=-=-=-=-=-= | |
$whatif=$true ; | |
$tCmdlet="TARGCMDLET" ; | |
$splat=[ordered]@{ | |
Identity="TARGETOBJECT" ; | |
PROP1=$TRUE ; | |
PROP2=$TRUE ; | |
whatif=$($whatif) ; | |
} ; | |
$props="identity","PROP1","PROP2" ; | |
write-host -foregroundcolor yellow "`n$((get-date).ToString('HH:mm:ss')):#*======v UPDATING $($tcmdlet.split("-")[1]) v======`n" ; | |
write-host "$((get-date).ToString('HH:mm:ss')):==EXISTING $($tcmdlet.split("-")[1]) values for target properties:" ; | |
GET-CMDLET -identity $splat.identity| format-list $props ; | |
write-host "$((get-date).ToString('HH:mm:ss')):==$($tCmdlet) w settings:`n$(($splat|out-string).trim())`n" ; | |
if(!$whatif){write-host -foregroundcolor yellow "`$whatif:$($whatif):EXECUTING $($tCmdlet)..."} else {write-host -foregroundcolor yellow "`$whatif:$($whatif):Running WHATIF"} ; | |
TARGCMDLET @splat ; | |
write-host "`n$((get-date).ToString('HH:mm:ss')):==UPDATED $($tcmdlet.split("-")[1]) values for target properties:" ; | |
GET-CMDLET -identity $splat.identity| format-list $props ; | |
write-host -foregroundcolor yellow "$((get-date).ToString('HH:mm:ss')):#*======^ UPDATING $($tcmdlet.split("-")[1]) ^======`n" ; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment