Title: PowerShell use different logic, when converting passed value to parameter type, for compiled and script cmdlets · Issue #3348 · PowerShell/PowerShell · GitHub
Open Graph Title: PowerShell use different logic, when converting passed value to parameter type, for compiled and script cmdlets · Issue #3348 · PowerShell/PowerShell
X Title: PowerShell use different logic, when converting passed value to parameter type, for compiled and script cmdlets · Issue #3348 · PowerShell/PowerShell
Description: Steps to reproduce PS> Add-Type -TypeDefinition @' using System; using System.Management.Automation; [Cmdlet("Test", "Compiled")] public class TestCompiled : PSCmdlet { [Parameter(Position = 0)] public DateTime DT; protected override voi...
Open Graph Description: Steps to reproduce PS> Add-Type -TypeDefinition @' using System; using System.Management.Automation; [Cmdlet("Test", "Compiled")] public class TestCompiled : PSCmdlet { [Parameter(Position = 0)] pu...
X Description: Steps to reproduce PS> Add-Type -TypeDefinition @' using System; using System.Management.Automation; [Cmdlet("Test", "Compiled")] public class TestCompiled : PSCmdlet { [...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/3348
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"PowerShell use different logic, when converting passed value to parameter type, for compiled and script cmdlets","articleBody":"Steps to reproduce\r\n------------------\r\n```powershell\r\nPS> Add-Type -TypeDefinition @'\r\n using System;\r\n using System.Management.Automation;\r\n [Cmdlet(\"Test\", \"Compiled\")]\r\n public class TestCompiled : PSCmdlet {\r\n [Parameter(Position = 0)]\r\n public DateTime DT;\r\n protected override void EndProcessing() {\r\n WriteObject(DT);\r\n }\r\n }\r\n'@ -PassThru | Select-Object -First 1 -ExpandProperty Assembly | Import-Module\r\nPS> function Test-Script {\r\n param(\r\n [DateTime]$DT\r\n )\r\n $DT\r\n }\r\nPS> @(\r\n [CultureInfo]::CurrentCulture = 'ru-RU'\r\n Test-Compiled 1/11/1111\r\n Test-Script 1/11/1111\r\n [CultureInfo]::CurrentCulture = 'en-US'\r\n )\r\n\r\nWednesday, November 1, 1111 12:00:00 AM\r\nWednesday, January 11, 1111 12:00:00 AM\r\n```\r\n\r\nExpected behavior\r\n-----------------\r\nSame dates in both cases.\r\n\r\nActual behavior\r\n---------------\r\nStrings get parsed with different culture in mind.\r\n\r\nEnvironment data\r\n----------------\r\n```powershell\r\n> $PSVersionTable\r\n\r\nName Value\r\n---- -----\r\nGitCommitId v6.0.0-alpha.17-18-gedecf7e04d65f7183cd1d278daa5ebed2970813f\r\nPSRemotingProtocolVersion 2.3\r\nPSEdition Core\r\nWSManStackVersion 3.0\r\nCLRVersion\r\nBuildVersion 3.0.0.0\r\nPSVersion 6.0.0-alpha\r\nPSCompatibleVersions {1.0, 2.0, 3.0, 4.0, 5.0, 5.1.10032.0, 6.0.0}\r\nSerializationVersion 1.1.0.1\r\n```\r\n\r\nMy thoughts about the problem\r\n----------------\r\nI think the problem happens due to PowerShell automatically adds `ArgumentTypeConverterAttribute` to typed parameters for script cmdlets:\r\n```powershell\r\nPS> (Get-Command Test-Script).Parameters.DT.Attributes | % GetType | % FullName\r\nSystem.Management.Automation.ParameterAttribute\r\nSystem.Management.Automation.ArgumentTypeConverterAttribute\r\n```\r\nbut not doing the same for compiled cmdlets:\r\n```powershell\r\nPS> (Get-Command Test-Compiled).Parameters.DT.Attributes | % GetType | % FullName\r\nSystem.Management.Automation.ParameterAttribute\r\n```\r\nThat attribute make conversion use `InvariantCulture`, while compiled cmdlets use `CurrentCulture` for conversion.","author":{"url":"https://github.com/PetSerAl","@type":"Person","name":"PetSerAl"},"datePublished":"2017-03-16T22:12:15Z","url":"https://github.com/PowerShell/PowerShell/issues/3348"}
| 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:2797a567-dc24-659c-f2ab-d7238d2c75f1 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 801A:2743C8:147BE4:1C3D81:6AFD5DFE |
| html-safe-nonce | f36735b24fdabbca054811ea547719f8d22f33924e0298cce2551ee1659bfdec |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MDFBOjI3NDNDODoxNDdCRTQ6MUMzRDgxOjZBRkQ1REZFIiwidmlzaXRvcl9pZCI6IjIzOTY0OTcwNjYxMTM5ODE5NTAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 89bdf353588c254bd1f0f219316ccac885df20d72911f99e0c1ab7800558680a |
| hovercard-subject-tag | issue:214853599 |
| 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/3348/issue_layout |
| twitter:image | https://opengraph.githubassets.com/5fbe47eb2f17fb048be69794f95cab289e657fbab36312bed83676329f0e1cdd/PowerShell/PowerShell/issues/3348 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/5fbe47eb2f17fb048be69794f95cab289e657fbab36312bed83676329f0e1cdd/PowerShell/PowerShell/issues/3348 |
| og:image:alt | Steps to reproduce PS> Add-Type -TypeDefinition @' using System; using System.Management.Automation; [Cmdlet("Test", "Compiled")] public class TestCompiled : PSCmdlet { [Parameter(Position = 0)] pu... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | PetSerAl |
| hostname | github.com |
| expected-hostname | github.com |
| None | 66653c2e55a6fff2930be1bdf07ee4f8aa137e3956d056c822563be6f878755e |
| 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 | b6f01f7cb9f35f8c09949773241a3d49dd04b340 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width