{"id":4000,"date":"2022-04-01T01:33:03","date_gmt":"2022-04-01T09:33:03","guid":{"rendered":"https:\/\/wonghoi.humgar.com\/blog\/?p=4000"},"modified":"2022-04-01T01:33:05","modified_gmt":"2022-04-01T09:33:05","slug":"ntlite-cannot-run-powershell-scripts-with-windows-10-21h2","status":"publish","type":"post","link":"https:\/\/wonghoi.humgar.com\/blog\/2022\/04\/01\/ntlite-cannot-run-powershell-scripts-with-windows-10-21h2\/","title":{"rendered":"NTLite cannot run Powershell scripts with Windows 10 21H2"},"content":{"rendered":"\n<p>Turns out Microsoft decided to not allow you to run Powershell scripts out of the box. The Execution-Policy is set to be disabled and you have to go to Powershell to run<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">Set-ExecutionPolicy unrestricted -force<\/pre>\n\n\n\n<p>The <code>-force<\/code> switch skips the prompt. However, this is a chick and egg problem with slipstreaming as you need to execute this first programmatically. I tried to use CMD files to do <code>powershell -command \"Set-ExecutionPolicy unrestricted -force\"<\/code> but it does not work and quite a few people reported ignoring execution policy with <code>-ExecutionPolicy Bypass<\/code> switch to <code>powershell.exe<\/code> does not work with NTLite either.<\/p>\n\n\n\n<p>It&#8217;s a colossal pain in the butt. Microsoft deciding to prevent Powershell scripts from running by default broke NTLite&#8217;s powershell scripting.<\/p>\n\n\n\n<p>I decided to take a look at registry values that can be changed and <a href=\"https:\/\/techdirectarchive.com\/2020\/02\/04\/how-to-set-the-powershell-execution-policy-via-the-registry-settings\/\">this website<\/a> suggested there is one. There&#8217;s a typo on the website. It&#8217;s not in HKCU but in HKLM (his screenshots says HKLM). The correct path is changing the string value <code>ExecutionPolicy<\/code> to <code>Unrestricted<\/code> in the key <code>HKLM\\SOFTWARE\\Microsoft\\PowerShell\\1\\ShellIds\\Microsoft.PowerShell<\/code> <\/p>\n\n\n\n<p>I cannot confirm when the registry files are loaded in NTLite. It could be too early or too late. (Looks like it&#8217;s too early to me since <a href=\"https:\/\/wonghoi.humgar.com\/blog\/2022\/04\/01\/ntlite-unattended-installation-will-mark-your-machine-as-managed-by-the-corporate-office\/\" data-type=\"post\" data-id=\"4001\">MDM fake enrollment registry<\/a> files do not take effect and I had to use <code>reg<\/code> command script later).<\/p>\n\n\n\n<p>So instead, I&#8217;ll do the registry change as a CMD script:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">reg add \"HKLM\\SOFTWARE\\Microsoft\\PowerShell\\1\\ShellIds\\Microsoft.PowerShell\" \/t REG_SZ  \/v ExecutionPolicy \/d \"Unrestricted\" \/f<\/pre>\n\n\n\n<div class=\"wp-block-file\"><a href=\"https:\/\/wonghoi.humgar.com\/blog\/wp-content\/uploads\/2022\/04\/RUN_ME_FIRST_Allow_PowershellScriptsToRun.cmd\">RUN_ME_FIRST_Allow_PowershellScriptsToRun<\/a><a href=\"https:\/\/wonghoi.humgar.com\/blog\/wp-content\/uploads\/2022\/04\/RUN_ME_FIRST_Allow_PowershellScriptsToRun.cmd\" class=\"wp-block-file__button\" download>Download<\/a><\/div>\n\n\n\n<p>Set it as the first script to run, or at least it has to run before the .ps1 (powershell) script<\/p>\n<div class=\"pvc_clear\"><\/div><p id=\"pvc_stats_4000\" class=\"pvc_stats all  \" data-element-id=\"4000\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/wonghoi.humgar.com\/blog\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p><div class=\"pvc_clear\"><\/div>","protected":false},"excerpt":{"rendered":"<p>Turns out Microsoft decided to not allow you to run Powershell scripts out of the box. The Execution-Policy is set to be disabled and you have to go to Powershell to run The -force switch skips the prompt. However, this &hellip; <a href=\"https:\/\/wonghoi.humgar.com\/blog\/2022\/04\/01\/ntlite-cannot-run-powershell-scripts-with-windows-10-21h2\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_4000\" class=\"pvc_stats all  \" data-element-id=\"4000\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/wonghoi.humgar.com\/blog\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-4000","post","type-post","status-publish","format-standard","hentry","category-windows"],"_links":{"self":[{"href":"https:\/\/wonghoi.humgar.com\/blog\/wp-json\/wp\/v2\/posts\/4000","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wonghoi.humgar.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wonghoi.humgar.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wonghoi.humgar.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wonghoi.humgar.com\/blog\/wp-json\/wp\/v2\/comments?post=4000"}],"version-history":[{"count":2,"href":"https:\/\/wonghoi.humgar.com\/blog\/wp-json\/wp\/v2\/posts\/4000\/revisions"}],"predecessor-version":[{"id":4006,"href":"https:\/\/wonghoi.humgar.com\/blog\/wp-json\/wp\/v2\/posts\/4000\/revisions\/4006"}],"wp:attachment":[{"href":"https:\/\/wonghoi.humgar.com\/blog\/wp-json\/wp\/v2\/media?parent=4000"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wonghoi.humgar.com\/blog\/wp-json\/wp\/v2\/categories?post=4000"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wonghoi.humgar.com\/blog\/wp-json\/wp\/v2\/tags?post=4000"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}