Created
January 10, 2019 10:11
-
-
Save OCram85/08cb2d3b5b9f8d19009d30de59ed4f4b to your computer and use it in GitHub Desktop.
PowerShell Confirm Mode Test
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
function Invoke-MainFunc { | |
[CmdletBinding(SupportsShouldProcess = $true)] | |
param ( | |
[string]$message | |
) | |
Write-Verbose -Message ('Confirm is: {0}' -f $Confirm) -Verbose | |
Write-Verbose -Message ('Confirm is present: {0}' -f $PSBoundParameters.ContainsKey('Confirm')) -Verbose | |
Write-Verbose -Message ('PSBound is: {0}' -f $PSBoundParameters['Confirm']) -Verbose | |
Write-Verbose -Message ('Invoke.PSBound is present: {0}' -f $MyInvocation.BoundParameters.ContainsKey('Confirm')) -Verbose | |
Write-Verbose -Message ('Invoke.PSBound is: {0}' -f $MyInvocation.BoundParameters['Confirm']) -Verbose | |
Invoke-SubFunc -Message $Message | |
} | |
function Invoke-SubFunc { | |
[CmdletBinding(SupportsShouldProcess = $true)] | |
param ( | |
[string]$message | |
) | |
Write-Verbose -Message ('Sub Confirm is: {0}' -f $Confirm) -Verbose | |
Write-Verbose -Message ('Sub Confirm is present: {0}' -f $PSBoundParameters.ContainsKey('Confirm')) -Verbose | |
Write-Verbose -Message ('Sub PSBound is: {0}' -f $PSBoundParameters['Confirm']) -Verbose | |
Write-Verbose -Message ('Sub Invoke.PSBound is present: {0}' -f $MyInvocation.BoundParameters.ContainsKey('Confirm')) -Verbose | |
Write-Verbose -Message ('Sub Invoke.PSBound is: {0}' -f $MyInvocation.BoundParameters['Confirm']) -Verbose | |
$message | Out-File -FilePath (Join-Path -Path $PWD -ChildPath '/foobartest.txt') -Encoding utf8 -Append | |
Remove-Item -Path (Join-Path -Path $PWD -ChildPath '/foobartest.txt') | |
} |
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
Import-Module .\ConfirmMod.psm1 -Verbose -Force | |
"============== $('Invoke-Mainfunc -message ''foo'' ') ==================`r`n" | |
Invoke-Mainfunc -message 'foo' | |
"`r`n----------- $('Invoke-Mainfunc -message ''foo'' -Confirm') --------------------`r`n" | |
Invoke-Mainfunc -message 'foo' -Confirm | |
"`r`n----------- $('Invoke-Mainfunc -message ''foo'' -Confirm:$false') --------------------`r`n" | |
Invoke-Mainfunc -message 'foo' -Confirm:$false | |
"`r`n----------- $('Invoke-Mainfunc -message ''foo'' -Confirm:$true') --------------------`r`n" | |
Invoke-Mainfunc -message 'foo' -Confirm:$true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment