{"id":17806135,"url":"https://github.com/janestreet/ps7compatibilityrules","last_synced_at":"2025-08-13T09:33:46.246Z","repository":{"id":259259612,"uuid":"877352863","full_name":"janestreet/PS7CompatibilityRules","owner":"janestreet","description":"PSScriptAnalyzer rules to help migrating PowerShell 5.1 scripts to PowerShell 7","archived":false,"fork":false,"pushed_at":"2024-10-23T15:31:41.000Z","size":8,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":6,"default_branch":"main","last_synced_at":"2024-12-14T21:11:41.948Z","etag":null,"topics":["powershell","psscriptanalyzer","pwsh"],"latest_commit_sha":null,"homepage":"","language":"PowerShell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/janestreet.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-23T14:02:24.000Z","updated_at":"2024-12-09T17:08:37.000Z","dependencies_parsed_at":"2024-10-23T23:47:23.971Z","dependency_job_id":"133ddeff-41ac-4263-b70b-83288c7436a1","html_url":"https://github.com/janestreet/PS7CompatibilityRules","commit_stats":null,"previous_names":["janestreet/ps7compatibilityrules"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/janestreet%2FPS7CompatibilityRules","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/janestreet%2FPS7CompatibilityRules/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/janestreet%2FPS7CompatibilityRules/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/janestreet%2FPS7CompatibilityRules/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/janestreet","download_url":"https://codeload.github.com/janestreet/PS7CompatibilityRules/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":229754931,"owners_count":18119134,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["powershell","psscriptanalyzer","pwsh"],"created_at":"2024-10-27T13:04:17.678Z","updated_at":"2025-08-13T09:33:46.220Z","avatar_url":"https://github.com/janestreet.png","language":"PowerShell","funding_links":[],"categories":[],"sub_categories":[],"readme":"A collection of [PSScriptAnalyzer](https://github.com/PowerShell/PSScriptAnalyzer) rules to highlight\r\npotential PowerShell 7 compatibility issues when migrating from PowerShell 5.1\r\n\r\n# Usage\r\n```powershell\r\ngit clone https://github.com/janestreet/PS7CompatibilityRules.git\r\nInvoke-ScriptAnalyzer -Path '\u003cyour_code_path\u003e' -Recurse -CustomRulePath .\\PS7CompatibilityRules\\*.psm1\r\n```\r\n\r\n\u003e [!NOTE]\r\n\u003e If instead of using `git clone` you've downloaded a zip file of this repo, you might need to run `Get-ChildItem .\\PS7CompatibilityRules | Unblock-File`\r\n\r\n\r\n# Included Rules\r\n| Rule                            | Description                                                                                         |\r\n| ------------------------------- | --------------------------------------------------------------------------------------------------- |\r\n| AvoidDeprecatedCommands         | Flag commands that are listed on Microsoft's website as incompatible with PS7                       |\r\n| AvoidDeprecatedTypes            | Flag references to deprecated types that are incompatible with PS7                                  |\r\n| AvoidGetSetAccessControl        | Flag GetAccessControl() or SetAccessControl() calls                                                 |\r\n| CommandRecommendations          | Recommendations for specific commands that have different behavior in PS7                           |\r\n| NoHtmlParsing                   | Flag code that relies on HTML parsing done in web cmdlets                                           |\r\n| SelectObjectMustSpecifyProperty | Select-Object ExcludeProperty is effective only when the command also includes a Property parameter |\r\n| EnsureProperUseOfDotNetMethods  | Flag some .NET method calls that have different behavior in PS7/.NET Core                           |\r\n\r\n\r\n# Example\r\nLet's examine `Demo.ps1` that has compatibility issues:\r\n```powershell\r\n$webClient = [System.Net.WebClient]::new()\r\n$webClient.DownloadString(\"https://example.com\") | Out-File -FilePath \"C:\\temp\\example.txt\"\r\n\r\n$acl = Get-Acl -Path \"C:\\temp\\example.txt\"\r\n$rule = New-Object System.Security.AccessControl.FileSystemAccessRule(\"Everyone\", \"ReadAndExecute\", \"Allow\")\r\n$acl.AddAccessRule($rule)\r\n$acl.SetAccessControl(\"C:\\temp\\example.txt\")\r\n\r\nGet-WmiObject -Class Win32_OperatingSystem | Select-Object Caption, Version | Format-Table -AutoSize\r\n\r\n'One,Two;Three Four'.Split(' ,;') | foreach { \"Processing: $_\" }\r\n```\r\n\r\nRules will report these findings:\r\n```shell\r\n\u003e Invoke-ScriptAnalyzer -Path .\\Demo.ps1 -CustomRulePath .\\PS7CompatibilityRules\\*.psm1\r\n\r\nRuleName                            Severity     ScriptName Line  Message\r\n--------                            --------     ---------- ----  -------\r\nAvoidDeprecatedCommands             Error        Demo.ps1   9     The command Get-WmiObject or one of its parameters or\r\n                                                                  parameter values is not compatible with both PS5 and PS7.\r\n                                                                  Consider using a different command.\r\nAvoidDeprecatedTypes                Error        Demo.ps1   1     Violation: Use System.Net.Http.HttpClient \u0026\r\n                                                                  System.Net.Http.HttpClientHandler to ensure compatibility\r\n                                                                  with PS7 and future versions\r\nAvoidGetSetAccessControl            Error        Demo.ps1   7     In PS7, GetAccessControl and SetAccessControl are not\r\n                                                                  available. Please use Get-Acl and Set-Acl\r\nCommandRecommendations              Information  Demo.ps1   2     Recommendation: Default encoding for \"Out-File\" has changed\r\n                                                                  from unicode to UTF-8NoBOM. Specify \"-Encoding Unicode\" to\r\n                                                                  ensure consistent behavior between PS versions.\r\nEnsureProperUseOfDotNetMethods      Warning      Demo.ps1   11    Recommendation: The Split method behaves differently\r\n                                                                  between PS5 and PS7 due to .NET changes. Use -split or\r\n                                                                  -csplit with regex instead.\r\n```\r\n\r\n# Using these rules in Visual Studio Code\r\n\r\n1. In your workspace create a PSScriptAnalyzer settings file (`.vscode\\PSScriptAnalyzerSettings.psd1`)\r\n    ```powershell\r\n    @{\r\n        CustomRulePath = @(\r\n            '\u003cpath_to\u003e\\PS7CompatibilityRules\\*.psm1'\r\n        )\r\n    }\r\n    ```\r\n2. Create or edit your workspace's settings file (`.vscode\\settings.json`) to include these settings\r\n    ```json\r\n    {\r\n        \"powershell.scriptAnalysis.settingsPath\": \".vscode\\\\PSScriptAnalyzerSettings.psd1\",\r\n        \"powershell.scriptAnalysis.enable\": true\r\n    }\r\n    ```\r\nRule violations should now be highlighted as you're editing code.\r\n\r\n\r\nFor more details, see\r\n  - [Settings Support in ScriptAnalyzer](https://learn.microsoft.com/en-us/powershell/utility-modules/psscriptanalyzer/using-scriptanalyzer?view=ps-modules#settings-support-in-scriptanalyzer)\r\n  - [Custom rules](https://learn.microsoft.com/en-us/powershell/utility-modules/psscriptanalyzer/using-scriptanalyzer?view=ps-modules#custom-rules)\r\n  - [Using custom rules in Visual Studio Code](https://learn.microsoft.com/en-us/powershell/utility-modules/psscriptanalyzer/using-scriptanalyzer?view=ps-modules#using-custom-rules-in-visual-studio-code)\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjanestreet%2Fps7compatibilityrules","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjanestreet%2Fps7compatibilityrules","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjanestreet%2Fps7compatibilityrules/lists"}