PowerShell_Scripts/base/Where-Ask.ps1

31 lines
860 B
PowerShell
Raw Normal View History

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