Hi,
I have this snippet of code within the PROCESS block of my script:
if ($PSCmdlet.ShouldProcess( "\n$sasexe \n-sysin ""$saspgm"" \n-config ""$sasconfig"" \n-log ""$saslogfull"" \n-print ""$sasprintfull"" \n$sasoptions","Invoke SAS" )) { $local:ConfirmPreference="Low" Try { Invoke-SAS if (! $quiet) { Print-SASResultMsg $script:sasrc Print-SASErrorsOrWarnings $script:sasrc } Set-SASReturnCode $script:sasrc # add the return code to the array of return codes $rtncodes+=$script:sasrc } Catch { Write-Error "$_" } }
(Note: Â the "\n"s are really "<backtick>n"s. Â The crayon code chokes on the `n’s, and IMO is a bug in the forum software.)
The Invoke-SAS function uses Start-Process to invoke SAS. Â The Print* functions just echo information to the console.
If the user invokes the script like so:
dir *.sas | myscript -confirm, or myscript *.sas -confirm
They’ll get something like this in the console:
Confirm Are you sure you want to perform this action? Performing operation "Invoke SAS" on Target " D:\Program Files\SASHome\SASFoundation\9.3\sas.exe -sysin "R:\Jams\Jobs\Lev9\_Abort.sas" -config "E:\SAS\Config\Lev9\SASApp\sasv9_JAMS_default_batch.cfg" -log "R:\JAMS\Logs\Lev9\_Abort.log" -print "R:\JAMS\Print\Lev9\_Abort.lst" -metaautoresources "SASApp"". [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"):
I thought the -confirm “checking” was done in the $PSCmdlet.ShouldProcess statement, but that doesn’t appear to be the case.  I think the -confirm “checking” is done in the Start-Process cmdlet.
The behaviour I’m seeing is, even if the user selects “[L] No to All”, the Print* functions are called for all the invocations that never get executed.
What I want is for the entire $PSCmdlet.ShouldProcess() block be skipped if the user has answered N or L to the -confirm question.
Is there a way to make this happen? Â Is this a bug in the -confirm processing (even if it’s just a design bug?)