Introducing Where-Ask script

A pipeline filter that will ask for confirmation based on the
parameters
This commit is contained in:
lksz 2021-05-08 17:47:15 -04:00
parent a64d3c83af
commit 877f9adb4e
1 changed files with 30 additions and 0 deletions

30
base/Where-Ask.ps1 Normal file
View File

@ -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
}
}
}