Title: Startup: the AppLocker probe costs about 40 ms on every pwsh start, also when no AppLocker policy exists · Issue #28372 · PowerShell/PowerShell · GitHub
Open Graph Title: Startup: the AppLocker probe costs about 40 ms on every pwsh start, also when no AppLocker policy exists · Issue #28372 · PowerShell/PowerShell
X Title: Startup: the AppLocker probe costs about 40 ms on every pwsh start, also when no AppLocker policy exists · Issue #28372 · PowerShell/PowerShell
Description: Summary of the new feature / enhancement On every start, SystemPolicy.GetSystemLockdownPolicy() goes through GetAppLockerPolicy with no path. That writes two files (__PSScriptPolicyTest_*.ps1 and .psm1) to %TEMP%, runs SaferIdentifyLevel...
Open Graph Description: Summary of the new feature / enhancement On every start, SystemPolicy.GetSystemLockdownPolicy() goes through GetAppLockerPolicy with no path. That writes two files (__PSScriptPolicyTest_*.ps1 and ....
X Description: Summary of the new feature / enhancement On every start, SystemPolicy.GetSystemLockdownPolicy() goes through GetAppLockerPolicy with no path. That writes two files (__PSScriptPolicyTest_*.ps1 and ....
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/28372
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Startup: the AppLocker probe costs about 40 ms on every pwsh start, also when no AppLocker policy exists","articleBody":"### Summary of the new feature / enhancement\n\nOn every start, `SystemPolicy.GetSystemLockdownPolicy()` goes through `GetAppLockerPolicy` with no path. That writes two files (`__PSScriptPolicyTest_*.ps1` and `.psm1`) to %TEMP%, runs `SaferIdentifyLevel` (hash and Authenticode criteria) and `SaferComputeTokenFromLevel` on them, then deletes them. On a machine with no AppLocker policy at all (no SrpV2 policy, AppIDSvc stopped) this takes about 40 ms of every `pwsh -Command ...` run. Tools and agents that start pwsh for each command pay it every time.\n\nMeasurements: PowerShell 7.6.9 x64 (zip), Windows 11 26100, i9-10900K, 30 interleaved runs per variant, median of the paired differences with 95% confidence interval. To isolate the probe I used a startup hook that sets `s_cachedSaferSystemPolicy` to `Allowed` before `Main`, so the cached branch is taken and nothing else changes.\n\n| `pwsh -NoProfile -NonInteractive -Command ...` | as is | probe skipped | difference |\n|---|---:|---:|---:|\n| `exit` | 354 ms | 313 ms | -39.5 ms (37.6 to 44.2) |\n| `Get-ChildItem -Name src \\| Select-Object -First 5` | 624 ms | 583 ms | -42.7 ms (32.0 to 48.2) |\n\nLoaded images go from 133 to 126 (pwrshsip, msisip, appxsip, opcservices and others). The same sequence in a small C program costs 56 ms over an empty process; writing and deleting the two files is 3 ms of that and the SAFER call on the .ps1 39 ms. I also found 83 leftover `__PSScriptPolicyTest_*` files in %TEMP% on this machine.\n\nRelated: #11074 (AppLocker start-up discussion, closed) and #24217 (asks for a way to turn off the test files).\n\n### Proposed technical implementation details (optional)\n\nI understand from #11074 that AppLocker has no API that says whether a script policy is in effect. Some options:\n\n1. Skip the probe when there is no AppLocker script policy on the machine: no rules under `HKLM\\SOFTWARE\\Policies\\Microsoft\\Windows\\SrpV2\\Script` and no `%windir%\\System32\\AppLocker\\Script.AppLocker`. Both are writable by admins only. Keep the probe otherwise.\n2. Cache the result per user and boot, and invalidate it when the AppLocker policy files change.\n3. Keep the probe but reuse one test file with fixed content instead of creating and deleting two on every start. This saves little time (about 3 ms) but avoids the leftovers.\n\nI can measure any of these with the same setup.\r\n","author":{"url":"https://github.com/azchohfi","@type":"Person","name":"azchohfi"},"datePublished":"2026-11-06T18:43:55Z","url":"https://github.com/PowerShell/PowerShell/issues/28372"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:0a3d1383-75a7-c77b-8c25-2f6ae98c5e55 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B3EC:342F2C:347294:4588B6:6AFCE610 |
| html-safe-nonce | f4c06973e3d71caa18577c376d3dfbb06cb2d6c9a843e88cd06b165589029944 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCM0VDOjM0MkYyQzozNDcyOTQ6NDU4OEI2OjZBRkNFNjEwIiwidmlzaXRvcl9pZCI6IjEyMDg1MTgxOTU4OTYxODIyODgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 7a683a1b3d48fbe7c34e605e7fb84bcb83eddeb36c188e3979669b53536db66a |
| hovercard-subject-tag | issue:6248602418 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/PowerShell/PowerShell/28372/issue_layout |
| twitter:image | https://opengraph.githubassets.com/1c46c7c9626b24f9166f32846330026fd70744f1ad940e4760fc2911ad48cb64/PowerShell/PowerShell/issues/28372 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/1c46c7c9626b24f9166f32846330026fd70744f1ad940e4760fc2911ad48cb64/PowerShell/PowerShell/issues/28372 |
| og:image:alt | Summary of the new feature / enhancement On every start, SystemPolicy.GetSystemLockdownPolicy() goes through GetAppLockerPolicy with no path. That writes two files (__PSScriptPolicyTest_*.ps1 and .... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | azchohfi |
| hostname | github.com |
| expected-hostname | github.com |
| None | 99aede4c5f55ec5cf06666a8c9e03ebf9f85f7231223e7f1c38c16e5504835b3 |
| turbo-cache-control | no-preview |
| go-import | github.com/PowerShell/PowerShell git https://github.com/PowerShell/PowerShell.git |
| octolytics-dimension-user_id | 11524380 |
| octolytics-dimension-user_login | PowerShell |
| octolytics-dimension-repository_id | 49609581 |
| octolytics-dimension-repository_nwo | PowerShell/PowerShell |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 49609581 |
| octolytics-dimension-repository_network_root_nwo | PowerShell/PowerShell |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | ecfd63ca125ec74b42f74eeb158b3fa081c8c497 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width