{"id":12152,"date":"2026-04-14T19:26:00","date_gmt":"2026-04-15T00:26:00","guid":{"rendered":"https:\/\/www.rushworth.us\/lisa\/?p=12152"},"modified":"2026-04-20T15:32:58","modified_gmt":"2026-04-20T20:32:58","slug":"signing-powershell-scripts","status":"publish","type":"post","link":"https:\/\/www.rushworth.us\/lisa\/?p=12152","title":{"rendered":"Signing PowerShell Scripts"},"content":{"rendered":"\n<p>A quick PowerShell script to report on its own signature data:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\n$scriptPath = $PSCommandPath\n\nif (-not $scriptPath) {\n    throw &#039;This script must be run from a .ps1 file so $PSCommandPath is available.&#039;\n}\n\n$sig = Get-AuthenticodeSignature -FilePath $scriptPath\n\nWrite-Host &quot;Script path: $scriptPath`n&quot; -ForegroundColor Cyan\n\n&#x5B;PSCustomObject]@{\n    Status                  = $sig.Status\n    StatusMessage           = $sig.StatusMessage\n    SignatureType           = $sig.SignatureType\n    IsOSBinary              = $sig.IsOSBinary\n    SignerSubject           = $sig.SignerCertificate.Subject\n    SignerThumbprint        = $sig.SignerCertificate.Thumbprint\n    SignerNotBefore         = $sig.SignerCertificate.NotBefore\n    SignerNotAfter          = $sig.SignerCertificate.NotAfter\n    TimeStamperSubject      = $sig.TimeStamperCertificate.Subject\n    TimeStamperThumbprint   = $sig.TimeStamperCertificate.Thumbprint\n} | Format-List\n<\/pre><\/div>\n\n\n<p>To sign the script:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\n$thumb = &#039;87E4C1F40D1DB8486F1E9093A76626AB1DFDEA30&#039;\n$scriptPath = &quot;$env:USERPROFILE\\git\\CyberSecurity\\misc\\CheckPSSignature.ps1&quot;\n\n$cert = Get-ChildItem Cert:\\CurrentUser\\My, Cert:\\LocalMachine\\My |\n    Where-Object {\n        $_.Thumbprint -eq $thumb -and\n        $_.HasPrivateKey -and\n        ($_.EnhancedKeyUsageList | Where-Object {\n            $_.ObjectId -eq &#039;1.3.6.1.5.5.7.3.3&#039; -or $_.FriendlyName -eq &#039;Code Signing&#039;\n        })\n    } |\n    Select-Object -First 1\n\nif (-not $cert) {\n    throw &quot;Code signing certificate $thumb not found.&quot;\n}\n\nSet-AuthenticodeSignature -FilePath $scriptPath -Certificate $cert\nGet-AuthenticodeSignature -FilePath $scriptPath | Format-List *\n<\/pre><\/div>\n\n\n<p>And now the script is signed:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2026\/04\/PSScriptSigned.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"257\" src=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2026\/04\/PSScriptSigned-1024x257.jpg\" alt=\"\" class=\"wp-image-12153\" srcset=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2026\/04\/PSScriptSigned-1024x257.jpg 1024w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2026\/04\/PSScriptSigned-300x75.jpg 300w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2026\/04\/PSScriptSigned-768x193.jpg 768w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2026\/04\/PSScriptSigned-750x188.jpg 750w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2026\/04\/PSScriptSigned.jpg 1037w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>A quick PowerShell script to report on its own signature data: To sign the script: And now the script is signed:<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[30],"tags":[2189],"class_list":["post-12152","post","type-post","status-publish","format-standard","hentry","category-system-administration","tag-code-signing"],"_links":{"self":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/12152","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=12152"}],"version-history":[{"count":1,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/12152\/revisions"}],"predecessor-version":[{"id":12154,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/12152\/revisions\/12154"}],"wp:attachment":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=12152"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=12152"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=12152"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}