Introducing Where-Ask script
A pipeline filter that will ask for confirmation based on the parameters
This commit is contained in:
parent
a64d3c83af
commit
877f9adb4e
|
@ -0,0 +1,30 @@
|
||||||
|
[CmdletBinding()]param(
|
||||||
|
[Parameter(Position=1)]
|
||||||
|
[string]$Message,
|
||||||
|
[Parameter(ParameterSetName='Default',Mandatory,Position=0,ValueFromPipeline)]
|
||||||
|
[object[]]$InputObject,
|
||||||
|
[Parameter(ParameterSetName='Default')]
|
||||||
|
[Parameter(ParameterSetName='AssumeYes',Mandatory)]
|
||||||
|
[switch]$AssumeYes,
|
||||||
|
[Parameter(ParameterSetName='Default')]
|
||||||
|
[Parameter(ParameterSetName='AssumeNo',Mandatory)]
|
||||||
|
[switch]$AssumeNo
|
||||||
|
)
|
||||||
|
|
||||||
|
begin {
|
||||||
|
Write-Host -ForegroundColor Cyan "$Var"
|
||||||
|
$whereAskYesToAll = $AssumeYes
|
||||||
|
$whereAskNoToAll = $AssumeNo
|
||||||
|
}
|
||||||
|
process {
|
||||||
|
Write-Host -ForegroundColor Green "$Var"
|
||||||
|
foreach( $local:o in $InputObject ) {
|
||||||
|
if( $PSCmdlet.ShouldContinue(
|
||||||
|
$($o | Out-String),
|
||||||
|
$Message,
|
||||||
|
[ref]$whereAskYesToAll, [ref]$whereAskNoToAll)
|
||||||
|
) {
|
||||||
|
$o
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue