{"id":6261,"date":"2015-05-04T09:06:00","date_gmt":"2015-05-04T09:06:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2015\/05\/04\/cool-powershell-conversations-at-ignite\/"},"modified":"2019-02-18T10:29:40","modified_gmt":"2019-02-18T17:29:40","slug":"cool-powershell-conversations-at-ignite","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/cool-powershell-conversations-at-ignite\/","title":{"rendered":"Cool PowerShell Conversations at Ignite"},"content":{"rendered":"<p><strong>Summary<\/strong>: Ed Wilson talks about some Windows PowerShell conversations at the Scripting Guys booth.<\/p>\n<p>One of the cool things about getting together with a bunch of people at the Scripting Guys booth is that I learn stuff. The conversations are great. Here is a case in point: Windows PowerShell MVP, Steve Murawski, stopped by the booth this morning. At the same time Microsoft PFEs, Gary Siepser, Brian Wilhite, and Jason Walker were here. Here is a picture:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/steveBrianJasonGary_122B0437.jpg\"><img decoding=\"async\" title=\"Photo of Steve, Brian, Jason, and Gary\" style=\"padding-top:0px;padding-left:0px;padding-right:0px\" alt=\"Photo of Steve, Brian, Jason, and Gary\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/steveBrianJasonGary_thumb_60AB7E40.jpg\" width=\"244\" height=\"139\" \/><\/a><\/p>\n<p>Ayway, while I was talking to Steve, I mentioned a conversation I had yesterday with a guy at lunch. I was talking about the importance of using <strong>&ndash;Whatif<\/strong> on a regular basis. In fact, I mentioned a story about the time I deleted my RAS certificate accidently. It happened because I knew what the command would do, and then&#8230;oops, my RAS certificate went into the bit bucket.<\/p>\n<p>So, as I was talking to Steve, I had a great idea: Why don&rsquo;t I use <strong>A$PSDefaultParameterValues<\/strong> and set any cmdlet that uses <strong>&ndash;Whatif<\/strong> to $true. This means that any cmdlet that had <strong>&ndash;Whatif<\/strong> as a parameter would automatically prompt with &quot;What if.&quot; Here is an example:<\/p>\n<p style=\"margin-left:30px\">PS C:\\Users\\ed&gt; $PSDefaultParameterValues = @{&quot;*:whatif&quot;=$true}<br \/>PS C:\\Users\\ed&gt; New-Item c:\\fso -ItemType directory<br \/>What if: Performing the operation &quot;Create Directory&quot; on target &quot;Destination: C:\\fso&quot;.<br \/>PS C:\\Users\\ed&gt; New-Item c:\\fso -ItemType directory -WhatIf:$false<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp; Directory: C:\\<\/p>\n<p style=\"margin-left:30px\">Mode&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LastWriteTime&nbsp;&nbsp;&nbsp;&nbsp; Length Name<br \/>&#8212;-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;&#8212;&#8212;&#8212;-&nbsp;&nbsp;&nbsp;&nbsp; &#8212;&#8212; &#8212;-<br \/>d&#8212;-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 5\/4\/2015&nbsp; 11:23 AM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fso<\/p>\n<p><span style=\"font-size:12px\">I was like really excited, and I told Gary, Brian, and Jason to come over, and see what I had done. I said, &ldquo;Dude, this is cool!&quot;<\/span><\/p>\n<p>Gary looked at it for a few minutes, shook his head and said, &ldquo;Why didn&rsquo;t you just set the <strong>$WhatIfPreference<\/strong> variable to $true.<\/p>\n<p>I looked at him and said, &ldquo;Because I didn&rsquo;t know about it.&rdquo; It seems that the <strong>$WhatIfPreference<\/strong> variable has been in Windows PowerShell since at least version 2. Hmmmm&hellip;I must have missed that one. So here is how to set it:<\/p>\n<p style=\"margin-left:30px\">PS C:\\Users\\ed&gt; $WhatIfPreference<br \/>False<br \/>PS C:\\Users\\ed&gt; $WhatIfPreference = $true<br \/>PS C:\\Users\\ed&gt; $WhatIfPreference<br \/>True<\/p>\n<p>Now any cmdlet that has a <strong>&ndash;WhatIf<\/strong> parameter will prompt. This is shown here:<\/p>\n<p style=\"margin-left:30px\">S C:\\Users\\ed&gt; $WhatIfPreference = $true<br \/>S C:\\Users\\ed&gt; Remove-Item c:\\fso<br \/>hat if: Performing the operation &quot;Remove Directory&quot; on target &quot;C:\\fso&quot;.<br \/>S C:\\Users\\ed&gt;<\/p>\n<p>But if I want to override it, here is the code I would use:<\/p>\n<p style=\"margin-left:30px\">PS C:\\Users\\ed&gt; Remove-Item c:\\fso -WhatIf:$False<br \/>PS C:\\Users\\ed&gt;<\/p>\n<p>As it turns out, I might not want the prompt every time I use <strong>Set*<\/strong> or <strong>New*<\/strong>. It might become annoying. Maybe all I really want is protection from <strong>Remove<\/strong>* cmdlets. I can go back to my <strong>$DefaultParameterValues<\/strong>&nbsp;that I began this post with, and modify it as shown here:<\/p>\n<p style=\"margin-left:30px\">PS C:\\Users\\ed&gt; $PSDefaultParameterValues = @{&quot;Remove*:whatif&quot;=$true}<br \/>PS C:\\Users\\ed&gt; Remove-Item c:\\fso<br \/>What if: Performing the operation &quot;Remove Directory&quot; on target &quot;C:\\fso&quot;.<br \/>PS C:\\Users\\ed&gt; Remove-Item c:\\fso -WhatIf:$false<br \/>PS C:\\Users\\ed&gt; New-Item c:\\fso -ItemType directory<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp; Directory: C:\\<\/p>\n<p style=\"margin-left:30px\">Mode&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LastWriteTime&nbsp;&nbsp;&nbsp;&nbsp; Length Name<br \/>&#8212;-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;&#8212;&#8212;&#8212;-&nbsp;&nbsp;&nbsp;&nbsp; &#8212;&#8212; &#8212;-<br \/>d&#8212;-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 5\/4\/2015&nbsp; 12:02 PM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fso<\/p>\n<p>Cool! This is what happens when a bunch of Windows PowerShell people congregate.<\/p>\n<p>~Ed<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Ed Wilson talks about some Windows PowerShell conversations at the Scripting Guys booth. One of the cool things about getting together with a bunch of people at the Scripting Guys booth is that I learn stuff. The conversations are great. Here is a case in point: Windows PowerShell MVP, Steve Murawski, stopped by the [&hellip;]<\/p>\n","protected":false},"author":597,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[191,51,580,377,4],"class_list":["post-6261","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-community","tag-getting-started","tag-ignite","tag-powershell","tag-scripting-techniques"],"acf":[],"blog_post_summary":"<p>Summary: Ed Wilson talks about some Windows PowerShell conversations at the Scripting Guys booth. One of the cool things about getting together with a bunch of people at the Scripting Guys booth is that I learn stuff. The conversations are great. Here is a case in point: Windows PowerShell MVP, Steve Murawski, stopped by the [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/6261","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/597"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=6261"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/6261\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=6261"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=6261"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=6261"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}