{"id":18041,"date":"2010-06-16T00:01:00","date_gmt":"2010-06-16T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2010\/06\/16\/hey-scripting-guy-how-can-i-sign-windows-powershell-scripts-with-an-enterprise-windows-pki-part-1-of-2\/"},"modified":"2010-06-16T00:01:00","modified_gmt":"2010-06-16T00:01:00","slug":"hey-scripting-guy-how-can-i-sign-windows-powershell-scripts-with-an-enterprise-windows-pki-part-1-of-2","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/hey-scripting-guy-how-can-i-sign-windows-powershell-scripts-with-an-enterprise-windows-pki-part-1-of-2\/","title":{"rendered":"Hey, Scripting Guy! How Can I Sign Windows PowerShell Scripts with an Enterprise Windows PKI? (Part 1 of 2)"},"content":{"rendered":"<p><a href=\"http:\/\/www.addthis.com\/bookmark.php?v=250&amp;pub=scriptingguys\">     <br \/><img decoding=\"async\" height=\"16\" width=\"125\" src=\"http:\/\/s7.addthis.com\/static\/btn\/v2\/lg-share-en.gif\" alt=\"Bookmark and Share\" border=\"0\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p><img decoding=\"async\" height=\"34\" width=\"34\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" align=\"left\" alt=\"Hey, Scripting Guy! Question\" border=\"0\" title=\"Hey, Scripting Guy! Question\" \/>Hey, Scripting Guy! Would you please write an article that is a step-by-step guide about how to use an existing Windows PKI installation to sign Windows PowerShell scripts?<\/p>\n<p>&#8212; HR<\/p>\n<p>&nbsp;<\/p>\n<p><img decoding=\"async\" height=\"34\" width=\"34\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" align=\"left\" alt=\"Hey, Scripting Guy! Answer\" border=\"0\" title=\"Hey, Scripting Guy! Answer\" \/><\/p>\n<p>Hello HR, <\/p>\n<p>Microsoft Scripting Guy Ed Wilson here. I am so glad you asked this because it gave me the opportunity to turn to one of our MVPs and let him share his knowledge:<\/p>\n<blockquote>\n<p>Ragnar Harper lives in Norway with his wife, daughters, and dog. Ragnar works as chief technology officer at Crayon AS. His focus is around Microsoft technologies, and he has deep passion for everything security related. He is also a strong believer in Windows PowerShell and loves to use it whenever he can. He was awarded IT Pro of the Year at Norwegian Heroes Happen Here in 2008. At the same event, he was also awarded &#8220;demo hero&#8221; for the best demo of Windows Server 2008&mdash;showing Windows PowerShell!<\/p>\n<p>You will find Ragnar at different conferences&mdash;often working at &#8220;ask-the-experts&#8221; booths helping find answers to people&rsquo;s questions. He is author of the Norwegian Windows PowerShell book,&nbsp; &#8220;Bli kjent med Windows PowerShell,&#8221; soon to be available and updated for Windows PowerShell 2.0.<\/p>\n<\/blockquote>\n<p>Therefore, without further ado I will turn the keyboard over to Ragnar Harper. <\/p>\n<p>&nbsp;<\/p>\n<p>I&#8217;ve been delivering Windows PowerShell training, and I often get asked how to use an enterprise Public Key Infrastructure (PKI) to sign Windows PowerShell scripts. It seems like almost all the articles out there show how to use a self-signed certificate created with tools such as makecert.exe from the .NET Framework SDK. <\/p>\n<p>In this article, I will show you how to make the code signing template available and how to use it. As a prerequisite, you need to have a certificate server available in your environment. My certificate server is Windows Server 2008, and my client for this article is running Windows 7. <\/p>\n<p>My PKI root is called <strong>pki.harper.labs<\/strong>, and it is already trusted by my domain members, as shown in the following image.<\/p>\n<p><a href=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2010\/june\/hey0616\/hsg-6-16-10-01.jpg\"><img decoding=\"async\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2010\/june\/hey0616\/hsg-6-16-10-01.jpg\" border=\"0\" style=\"max-width: 445px;max-height: 193px\" \/><\/a><\/p>\n<p>I will follow these steps:<\/p>\n<ol>\n<li>Make the code signing certificate template available on my issuing certificate server. <\/li>\n<li>Request a code signing certificate for my user. <\/li>\n<li>Sign my Windows PowerShell script and run it. <\/li>\n<li>Deploy the code signing certificate as a trusted publisher through Active Directory. <\/li>\n<\/ol>\n<h4>Step 1: Make the code signing certificate template available on my issuing certificate server<\/h4>\n<p>Let&rsquo;s start with making the code signing certificate available on the issuing certificate server so that our certificate server will issue code signing certificates. I do this at the issuing certificate server, and I start the Server Manager console and open the <strong>Active Directory Certificate Services<\/strong> node. <\/p>\n<p>We will start with a look at the code signing certificate template. Find the template in the <strong>Certificate Templates<\/strong> node right under the <strong>Enterprise PKI<\/strong> node. This is called the <strong>Certificate Templates<\/strong> snap-in (and if you want you can open it up as a standalone snap-in in the Microsoft Management Console [mmc.exe]). This is shown in the following image.<\/p>\n<p><a href=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2010\/june\/hey0616\/hsg-6-16-10-02.jpg\"><img decoding=\"async\" height=\"184\" width=\"543\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/5504.hsg61610021_58C4594F.jpg\" alt=\"Image of Certificate Templates snap-in\" border=\"0\" title=\"Image of Certificate Templates snap-in\" style=\"border-bottom: 0px;border-left: 0px;border-top: 0px;border-right: 0px\" \/> <\/a><\/p>\n<p>I will not discuss how to create copies of the template here, so I will just use the existing certificate template. If you double-click the code signing template, you will get a property sheet with a few tabs, as shown in the following image.<\/p>\n<p><a href=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2010\/june\/hey0616\/hsg-6-16-10-03.jpg\"><img decoding=\"async\" height=\"296\" width=\"269\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/8712.hsg61610031_45A32CA3.jpg\" alt=\"Image of Code Signing Properties dialog box\" border=\"0\" title=\"Image of Code Signing Properties dialog box\" style=\"border-bottom: 0px;border-left: 0px;border-top: 0px;border-right: 0px\" \/> <\/a><\/p>\n<p>Because we are not creating a duplicate copy, we cannot change any of the values on the <strong>General<\/strong> tab. If we created a duplicate, we could change those. For example, how long should the certificate be valid? The same goes for <strong>Request Handling<\/strong>, <strong>Subject Name<\/strong>, and <strong>Extensions<\/strong>. If we wanted to change those, we would have to create a duplicate. <\/p>\n<p>What we will look at is the <strong>Security<\/strong> tab. We are interested in the permission to enroll&mdash;who should be able to enroll for a code signing certificate? I create a group in Active Directory called <strong>Codesigners<\/strong>, and I grant the Read and Enroll permissions shown in the following image.<\/p>\n<p><a href=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2010\/june\/hey0616\/hsg-6-16-10-04.jpg\"><img decoding=\"async\" height=\"302\" width=\"271\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/8625.hsg61610041_4C563626.jpg\" alt=\"Image of granting Read and Enroll permissions\" border=\"0\" title=\"Image of granting Read and Enroll permissions\" style=\"border-bottom: 0px;border-left: 0px;border-top: 0px;border-right: 0px\" \/> <\/a><\/p>\n<p>Then I make members of this group the users who should be able to get a code signing certificate. I click <strong>OK<\/strong>, and continue to the make the certificate template available on my issuing certificate server.<\/p>\n<p>Next, I open the Certificate Authority console (the node is named <strong>pki.harper.labs<\/strong> in my environment, and is found under the <strong>Certificate Templates<\/strong> node in Server Manager, as shown in the next image). In the Certificate Authority console, you also see a <strong>Certificate Templates<\/strong> node. If you want to check if the code signing certificate template is available for enrollment, see if it is shown in the list. This is shown in the following image.<\/p>\n<p><a href=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2010\/june\/hey0616\/hsg-6-16-10-05.jpg\"><img decoding=\"async\" height=\"235\" width=\"517\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/8231.hsg61610051_6C050FEE.jpg\" alt=\"Image of checking to see if code signing certificate is available for enrollment\" border=\"0\" title=\"Image of checking to see if code signing certificate is available for enrollment\" style=\"border-bottom: 0px;border-left: 0px;border-top: 0px;border-right: 0px\" \/> <\/a><\/p>\n<p>If the code signing template is not shown, we will add it. Right-click the <strong>Certificate Templates<\/strong> node, point to <strong>New<\/strong>,<i> <\/i>and then click <strong>Certificate Template to Issue<\/strong>, as shown in the following image.<\/p>\n<p><a href=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2010\/june\/hey0616\/hsg-6-16-10-06.jpg\"><img decoding=\"async\" height=\"298\" width=\"465\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/5504.hsg61610061_0FBE3789.jpg\" alt=\"Image of adding code signing template\" border=\"0\" title=\"Image of adding code signing template\" style=\"border-bottom: 0px;border-left: 0px;border-top: 0px;border-right: 0px\" \/> <\/a><\/p>\n<p>From the list that appears, such as is shown in the following image, select the code signing template, and then click <strong>OK<\/strong>. This list is read from Active Directory, and if you just created the template, you might have to wait until it is replicated to all domain controllers.<\/p>\n<p><a href=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2010\/june\/hey0616\/hsg-6-16-10-07.jpg\"><img decoding=\"async\" height=\"208\" width=\"334\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/6574.hsg61610071_7656344E.jpg\" alt=\"Image of list of code signing templates\" border=\"0\" title=\"Image of list of code signing templates\" style=\"border-bottom: 0px;border-left: 0px;border-top: 0px;border-right: 0px\" \/> <\/a><\/p>\n<p>We are now able to request a code signing certificate, and enroll the users we gave Enroll permission on the template.<\/p>\n<h4>Step 2: Request a code signing certificate for my user<\/h4>\n<p>This step is done from my client computer, as a user that is member of the <strong>Codesigning<\/strong> group. I open the certificates snap-in through the Microsoft Management Console (mmc.exe). Then I add the <strong>Certificates<\/strong> snap-in by clicking <strong>File<\/strong>, and then clicking<strong> Add\/Remove Snap-in.<i> <\/i><\/strong>This is shown in the following image.<\/p>\n<p><a href=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2010\/june\/hey0616\/hsg-6-16-10-08.jpg\"><img decoding=\"async\" height=\"242\" width=\"230\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/8625.hsg61610081_16050E17.jpg\" alt=\"Image of adding the Certificates snap-in\" border=\"0\" title=\"Image of adding the Certificates snap-in\" style=\"border-bottom: 0px;border-left: 0px;border-top: 0px;border-right: 0px\" \/> <\/a><\/p>\n<p>Click <strong>Certificates<\/strong> in the left pane, as shown in the following image. Click <strong>Add<\/strong>, and then click <strong>OK<\/strong>.<\/p>\n<p><a href=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2010\/june\/hey0616\/hsg-6-16-10-09.jpg\"><img decoding=\"async\" height=\"222\" width=\"313\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/5008.hsg61610091_1CB8179A.jpg\" alt=\"Image of adding the Certificates snap-in\" border=\"0\" title=\"Image of adding the Certificates snap-in\" style=\"border-bottom: 0px;border-left: 0px;border-top: 0px;border-right: 0px\" \/> <\/a><\/p>\n<p>You want the snap-in to manage your user account, so click <strong>My user account<\/strong>. Now that you have loaded the snap-in, let&rsquo;s request a code signing certificate. Right-click <strong>Personal<\/strong>, point to <strong>All Tasks<\/strong>, and then click <strong>Request New Certificate<\/strong>.<\/p>\n<p><a href=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2010\/june\/hey0616\/hsg-6-16-10-11.jpg\"><img decoding=\"async\" height=\"223\" width=\"431\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/4034.hsg61610111_6A54441A.jpg\" alt=\"Image of requesting a new code signing certificate\" border=\"0\" title=\"Image of requesting a new code signing certificate\" style=\"border-bottom: 0px;border-left: 0px;border-top: 0px;border-right: 0px\" \/> <\/a><\/p>\n<p>Just click <strong>Next<\/strong> in the first dialog box. Because we are requesting a certificate from our enterprise PKI, in the next dialog box, select the <strong>Active Directory Enrollment Policy<\/strong>, and then click <strong>Next<\/strong>, as is shown in the following image.<\/p>\n<p><a href=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2010\/june\/hey0616\/hsg-6-16-10-13.jpg\"><img decoding=\"async\" height=\"183\" width=\"248\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/4527.hsg61610131_2E287872.jpg\" alt=\"Image of selecting Active Directory Enrollment Policy\" border=\"0\" title=\"Image of selecting Active Directory Enrollment Policy\" style=\"border-bottom: 0px;border-left: 0px;border-top: 0px;border-right: 0px\" \/> <\/a><\/p>\n<p>Because we made the code signing template available in step 1, you should see the template for code signing available for enrollment. You only see the certificates you have permissions for in the list, so if the code signing template does not show up, have a closer look at the permissions. Click the <strong>Code Signing<\/strong> certificate. If you look at the details, you will see the validity period of the certificate (the default template is one year or 365 days, as the details say).<\/p>\n<p><a href=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2010\/june\/hey0616\/hsg-6-16-10-15.jpg\"><img decoding=\"async\" height=\"83\" width=\"341\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/0207.hsg61610151_49CD0468.jpg\" alt=\"Image of Code Signing details\" border=\"0\" title=\"Image of Code Signing details\" style=\"border-bottom: 0px;border-left: 0px;border-top: 0px;border-right: 0px\" \/> <\/a><\/p>\n<p>All the information that is needed to create the certificate is automatically configured, but if you want, you can change some of it if you click <strong>Properties<\/strong>. For example, if you want to make the private key exportable so that you can export\/import the private keys to other computers, you can configure this by clicking <strong>Properties<\/strong>, and then clicking the <strong>Private Key<\/strong> tab, as shown in the following image. This is necessary if you want to use the same certificate on multiple computers. <\/p>\n<p><a href=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2010\/june\/hey0616\/hsg-6-16-10-16.jpg\"><img decoding=\"async\" height=\"242\" width=\"247\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/1781.hsg61610161_74A5687A.jpg\" alt=\"Image of making private key exportable\" border=\"0\" title=\"Image of making private key exportable\" style=\"border-bottom: 0px;border-left: 0px;border-top: 0px;border-right: 0px\" \/> <\/a><\/p>\n<p>When you are ready, click <strong>Enroll<\/strong>. Wait while the certificate is being generated and issued. Click <strong>Finish<\/strong>. You have now created a certificate for code signing!<\/p>\n<p><a href=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2010\/june\/hey0616\/hsg-6-16-10-19.jpg\"><img decoding=\"async\" height=\"130\" width=\"515\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/5008.hsg61610191_2945C4B6.jpg\" alt=\"Image of code signing certificate created\" border=\"0\" title=\"Image of code signing certificate created\" style=\"border-bottom: 0px;border-left: 0px;border-top: 0px;border-right: 0px\" \/> <\/a>    <\/p>\n<p>Tomorrow, we will continue with firing up Windows PowerShell, and signing our script! <\/p>\n<p>&nbsp;<\/p>\n<p>HR, this is the first of two parts in Ragnar Harper&rsquo;s step-by-step guide about how to use an existing Windows PKI installation to sign Windows PowerShell scripts. Join us for part two tomorrow as Guest Blogger Week continues. <\/p>\n<p>If you want, we would love for you to follow us on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\">Twitter<\/a> or <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\">Facebook<\/a>. If you have any questions, send email to us at <a href=\"mailto:scripter@microsoft.com\">scripter@microsoft.com<\/a>, or post your questions on the <a href=\"http:\/\/bit.ly\/scriptingforum\">Official Scripting Guys Forum<\/a>. See you tomorrow. Until then, peace.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Ed Wilson and Craig Liebendorfer, Scripting Guys<\/strong><\/p>\n<p><strong><br \/><\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; Hey, Scripting Guy! Would you please write an article that is a step-by-step guide about how to use an existing Windows PKI installation to sign Windows PowerShell scripts? &#8212; HR &nbsp; Hello HR, Microsoft Scripting Guy Ed Wilson here. I am so glad you asked this because it gave me the opportunity to turn [&hellip;]<\/p>\n","protected":false},"author":595,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[56,150,151,3,63,45],"class_list":["post-18041","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-guest-blogger","tag-ragnar-harper","tag-script-signing","tag-scripting-guy","tag-security","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>&nbsp; Hey, Scripting Guy! Would you please write an article that is a step-by-step guide about how to use an existing Windows PKI installation to sign Windows PowerShell scripts? &#8212; HR &nbsp; Hello HR, Microsoft Scripting Guy Ed Wilson here. I am so glad you asked this because it gave me the opportunity to turn [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/18041","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\/595"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=18041"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/18041\/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=18041"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=18041"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=18041"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}