{"id":368,"date":"2019-02-20T17:20:18","date_gmt":"2019-02-20T23:20:18","guid":{"rendered":"http:\/\/draith.com\/?p=368"},"modified":"2019-02-20T17:20:18","modified_gmt":"2019-02-20T23:20:18","slug":"powershell-security-in-your-profile","status":"publish","type":"post","link":"https:\/\/draith.com\/?p=368","title":{"rendered":"Powershell &#8211; Security in your profile"},"content":{"rendered":"\n\n\n<p>If you have done much with Invoke-webrequest, and if your endpoints have an inkling of security minded people watching them, then chances are you have run into a small issue:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p> <em>Invoke-WebRequest : The request was aborted: Could not create SSL\/TLS secure channel.<\/em> <\/p><p><\/p><\/blockquote>\n\n\n\n<p>What&#8217;s happening here?  Well, chances are that the end-point you are attempting to access has turned off TLS1.0 and 1.1, <a href=\"https:\/\/www.globalsign.com\/en\/blog\/disable-tls-10-and-all-ssl-versions\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"and for good reason! (opens in a new tab)\">and for good reason!<\/a> There is an easy fix, however.  Just simply place a single line of code in your script above the invoke-webrequest:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12<\/code><\/pre>\n\n\n\n<p>Great!  Post done, walk away.  <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">But&#8230;..I have about 10000 scripts&#8230;..<\/h2>\n\n\n\n<p>That one line works great if you have just a handful of scripts that you run, but what if you need to do this for a large company &#8211; maybe a large enterprise?  Well, it turns out that your profile can help.<\/p>\n\n\n\n<p>First off &#8211; there are multiple PowerShell profiles on a system, but for this instance, let&#8217;s focus on the All-Users\/All-Hosts profile (also sometimes referred to as the System profile).  Depending on the flavor of PowerShell you are running &#8211; Microsoft vs Windows &#8211; the System profile will be in different locations.  Not to fear, however, cause $PSHome will show you where the profile is located.  Create your profile (if you haven&#8217;t already) in the $PSHome directory.  The name of the file should be &#8220;profile.ps1&#8221;.<\/p>\n\n\n\n<p>Now &#8211; place the Net.ServicePointManager line you would normally place in a single script into your System profile and save it.  Whenever an invoke-webrequest is run from this system, it will automatically use the TLS1.2 protocol.  Updating a few systems that run your scripts is a lot easier than updating thousands of scripts, and this will save you a ton of time.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you have done much with Invoke-webrequest, and if your endpoints have an inkling of security minded people watching them, then chances are you have run into a small issue: Invoke-WebRequest : The request was aborted: Could not create SSL\/TLS secure channel. What&#8217;s happening here? Well, chances are that the end-point you are attempting to &hellip; <a href=\"https:\/\/draith.com\/?p=368\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Powershell &#8211; Security in your profile&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-368","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/draith.com\/index.php?rest_route=\/wp\/v2\/posts\/368","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/draith.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/draith.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/draith.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/draith.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=368"}],"version-history":[{"count":0,"href":"https:\/\/draith.com\/index.php?rest_route=\/wp\/v2\/posts\/368\/revisions"}],"wp:attachment":[{"href":"https:\/\/draith.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=368"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/draith.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=368"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/draith.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=368"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}