Author Posts

March 19, 2018 at 1:45 am

I have a function that includes a parameter to delete an object if it already exists. If the object does not exist or the user does not specify the parameter to delete the object, the function has no need to be confirmed. Only if the user specifies the parameter AND the object exists should the user be prompted to confirm. In that case, I would like the user to be able to specify the common -Confirm:$false parameter to avoid the prompt. From what I've read, it seems that Confirm along with ConfirmPreference only works at the function level. Is that really the case? If so, I have some not-so-elegant ideas about how to deal with it, but I'm up for other ideas. Thanks.

May 24, 2018 at 5:17 am

I would separate the tasks out into separate functions. One to get and one to remove. You can then pipe the get to the remove and have the ConfirmImpact in the cmdlet doing the change.

The remove one should include this at the top of the function.


May 30, 2018 at 12:12 am

Thanks, that's what I ended up doing.