{"id":9081,"date":"2006-12-14T23:01:00","date_gmt":"2006-12-14T23:01:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/powershell\/2006\/12\/14\/confirmpreference\/"},"modified":"2019-02-18T13:21:02","modified_gmt":"2019-02-18T20:21:02","slug":"confirmpreference","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/powershell\/confirmpreference\/","title":{"rendered":"ConfirmPreference"},"content":{"rendered":"<p>With Windows PowerShell you can specify -CONFIRM on commands that have a side-effect on the system and it will ask you whether to perfmon the action or not.&nbsp; e.g.<\/p>\n<p>PS&gt; Stop-Process 7004 -Confirm<\/p>\n<p>Confirm<br \/>Are you sure you want to perform this action?<br \/>Performing operation &#8220;Stop-Process&#8221; on Target &#8220;calc (7004)&#8221;.<br \/>[Y] Yes&nbsp; [A] Yes to All&nbsp; [N] No&nbsp; [L] No to All&nbsp; [S] Suspend&nbsp; [?] Help (default is &#8220;Y&#8221;): y<br \/>PS&gt;<\/p>\n<p>But you can also configure the system to automatically confirm operations based upon their impact on the system.&nbsp; When developers write their cmdlets, they can declare the impact of their commands on the system: &#8220;HIGH&#8221;, &#8220;MEDIUM&#8221;, &#8220;LOW&#8221;.&nbsp; For instance, the Exchange command for Removing a Mailbox is declared to have a HIGH impact.&nbsp; Stop-Process is defined as &#8220;MEDIUM&#8221;.&nbsp; You can then set the variable: $ConfirmPreference to be the level that you want Automatic confirmation turned on.&nbsp; In the example below, we try to stop CALC with $ConfirmPreference set at LOW, MEDIUM, and HIGH.&nbsp; Notice that autoconfirmation kicks in when it is set to LOW or MEDIUM but not when it is set to HIGH.<\/p>\n<p>PS&gt; Calc<br \/>PS&gt; $ConfirmPreference=&#8221;low&#8221;<br \/>PS&gt; Stop-Process -ProcessName calc<\/p>\n<p>Confirm<br \/>Are you sure you want to perform this action?<br \/>Performing operation &#8220;Stop-Process&#8221; on Target &#8220;calc (5852)&#8221;.<br \/>[Y] Yes&nbsp; [A] Yes to All&nbsp; [N] No&nbsp; [L] No to All&nbsp; [S] Suspend&nbsp; [?] Help (default is &#8220;Y&#8221;): n<br \/>PS&gt; $ConfirmPreference=&#8221;Medium&#8221;<br \/>PS&gt; Stop-Process -ProcessName calc<\/p>\n<p>Confirm<br \/>Are you sure you want to perform this action?<br \/>Performing operation &#8220;Stop-Process&#8221; on Target &#8220;calc (5852)&#8221;.<br \/>[Y] Yes&nbsp; [A] Yes to All&nbsp; [N] No&nbsp; [L] No to All&nbsp; [S] Suspend&nbsp; [?] Help (default is &#8220;Y&#8221;): n<br \/>PS&gt; $ConfirmPreference=&#8221;High&#8221;<br \/>PS&gt; Stop-Process -ProcessName calc<br \/>PS&gt;<\/p>\n<p>The default value of $ConfirmPreference is &#8220;High&#8221;.<\/p>\n<p>Enjoy<\/p>\n<p>Jeffrey Snover [MSFT]<br \/>Windows PowerShell\/MMC Architect<\/p>\n<p>&nbsp;<\/p>\n<blockquote>\n<p>When confirmation is turned on by $ConfirmPreference, you can turn it off for any individual cmdlet invocation using &#8220;-Confirm:$false&#8221;.&nbsp;&nbsp;You can also use &#8220;-Confirm:$false&#8221; to turn off default confirmation for high impact cmdlets such as Removing a Mailbox.&nbsp; Another way to turn off confirmation is by setting $ConfirmPreference to &#8220;None&#8221;; you can limit the effect by setting $script:ConfirmPreference etc, see &#8220;get-help about_scope&#8221; for more details.<\/p>\n<p>PS&gt; $ConfirmPreference=&#8221;Medium&#8221;<br \/>PS&gt; stop-process -ProcessName calc -Confirm:$false<br \/>PS&gt; $ConfirmPreference = &#8220;None&#8221;<br \/>PS&gt; stop-process -ProcessName calc<br \/>PS&gt;<\/p>\n<p>Confirmation may cause your script to fail if it is running in a non-interactive environment, so it is important to know how to turn confirmation off when necessary.<\/p>\n<p>Jon Newman [MSFT]<br \/>Windows PowerShell team<\/p>\n<\/blockquote>\n<p>&nbsp;<\/p>\n<p>Visit the Windows PowerShell Team blog at:&nbsp;&nbsp;&nbsp; <a href=\"http:\/\/blogs.msdn.com\/PowerShell\">http:\/\/blogs.msdn.com\/PowerShell<\/a><br \/>Visit the Windows PowerShell ScriptCenter at:&nbsp; <a href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/hubs\/msh.mspx\">http:\/\/www.microsoft.com\/technet\/scriptcenter\/hubs\/msh.mspx<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>With Windows PowerShell you can specify -CONFIRM on commands that have a side-effect on the system and it will ask you whether to perfmon the action or not.&nbsp; e.g. PS&gt; Stop-Process 7004 -Confirm ConfirmAre you sure you want to perform this action?Performing operation &#8220;Stop-Process&#8221; on Target &#8220;calc (7004)&#8221;.[Y] Yes&nbsp; [A] Yes to All&nbsp; [N] No&nbsp; [&hellip;]<\/p>\n","protected":false},"author":600,"featured_media":13641,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-9081","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powershell"],"acf":[],"blog_post_summary":"<p>With Windows PowerShell you can specify -CONFIRM on commands that have a side-effect on the system and it will ask you whether to perfmon the action or not.&nbsp; e.g. PS&gt; Stop-Process 7004 -Confirm ConfirmAre you sure you want to perform this action?Performing operation &#8220;Stop-Process&#8221; on Target &#8220;calc (7004)&#8221;.[Y] Yes&nbsp; [A] Yes to All&nbsp; [N] No&nbsp; [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/9081","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/users\/600"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/comments?post=9081"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/9081\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media\/13641"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media?parent=9081"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/categories?post=9081"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/tags?post=9081"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}