Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pscustomobject] type accelerator does not work in 7.4.0 #20719

Closed
5 tasks done
shivtorov opened this issue Nov 18, 2023 · 9 comments
Closed
5 tasks done

[pscustomobject] type accelerator does not work in 7.4.0 #20719

shivtorov opened this issue Nov 18, 2023 · 9 comments

Comments

@shivtorov
Copy link

Prerequisites

Steps to reproduce

  1. Open PowerShell 7.4.0 tab in Windows Terminal
  2. cast a hashtable to pscustomobject type accelerator

Expected results: a new object created
Actual results: nothing = no new object, no errors, no hashtable

Expected behavior

PS> [pscustomobject]@{one=1; two=2}

one two
--- ---
  1   2

Actual behavior

PS> [pscustomobject]@{one=1; two=2}

Error details

No response

Environment data

PS> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.4.0
PSEdition                      Core
GitCommitId                    7.4.0
OS                             Microsoft Windows 10.0.22631
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0, 5.0, 5.1, 6.0, 7.0}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

image

@shivtorov shivtorov added the Needs-Triage The issue is new and needs to be triaged by a work group. label Nov 18, 2023
@trackd
Copy link

trackd commented Nov 18, 2023

that's pretty strange, your example works for me on 7.4.0.

Could you try and temporarily disable Constrained Language Audit Mode, and see if that makes a difference?
I'm not too familiar with it, but it's an obvious difference.

PS > [pscustomobject]@{one = 1; two = 2 }
one two
--- ---
  1   2

PS > ([pscustomobject]@{one = 1; two = 2 }).Gettype().Name
PSCustomObject

PS > ([pscustomobject]@{one = 1; two = 2 }).One.Gettype().Name
Int32

PS > $ht = @{}
PS > $ht.add('one',1)
PS > $ht.add('two',2)
PS > [PSCustomObject]$ht
two one
--- ---
  2   1

PS > $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.4.0
PSEdition                      Core
GitCommitId                    7.4.0
OS                             Microsoft Windows 10.0.22631
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

@B-Art
Copy link

B-Art commented Nov 18, 2023

It does just work for me:
The only remark I have is that PSCompatibleVersions is displayed trackd shows. {1.0, 2.0, 3.0, 4.0…}
Not showing like {1.0, 2.0, 3.0, 4.0, 5.0, 5.1, 6.0, 7.0}
But

$PSVersionTable.PSCompatibleVersions

Shows:

Major  Minor  Build  Revision
-----  -----  -----  --------
1      0      -1     -1
2      0      -1     -1
3      0      -1     -1
4      0      -1     -1
5      0      -1     -1
5      1      -1     -1
6      0      -1     -1
7      0      -1     -1

@B-Art
Copy link

B-Art commented Nov 18, 2023

Also check how (in what way) you did install pwsh 7.4:
https://learn.microsoft.com/en-us/powershell/scripting/install/installing-powershell-on-windows?view=powershell-7.4

Information about installing PowerShell on Windows

@HumanEquivalentUnit
Copy link
Contributor

It works for me as well; do you get anything if you run this, to see if there is an output and it's just being hidden on your terminal somehow:

PS> $x = [pscustomobject]@{one=1; two=2}
PS> $x | Get-Member

Or these, to check if the type accelerator is working?

PS C:\> [pscustomobject]

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     False    PSObject                                 System.Object

PS C:\> [pscustomobject].FullName
System.Management.Automation.PSObject

PS C:\> [System.Management.Automation.PSCustomObject]

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     False    PSCustomObject                           System.Object

@shivtorov
Copy link
Author

shivtorov commented Nov 19, 2023

yeah, that's a weird issue.
I checked the same on a different Windows 11 23h2 PC and everything works as expected there.
I uninstalled and manually reinstalled 7.4.0 version using MSI (x64) installer on the affected PC - issue is still there.

image

The OS on the affected PC is freshly installed from ISO a week ago.
The only thing that is different on this PC is that it is managed by company policies pushed via Microsoft Intune.
One of these policies enabled "Constrained Language Audit Mode" (whatever it means).
I guess that this "Constrained Language Audit Mode" is breaking [pscustomobject].

I downloaded x64 ZIP versions 7.4.0 and 7.3.10 to test without installation - results are:

image

I have a workaround for this problem for me - I will just use a different PC/VM for executing scripts using [pscustomobject] type accelerator.

@shivtorov
Copy link
Author

The issue is affecting all corporate laptops in our company.
It turned out that somehow corporate policies activate ConstrainedLanguage mode, but only v7.4.0
Strangely, the policies don't affect previous versions (such as 7.3.10)
My fix is to manually switch to FullLanguage mode.

image

@microsoft-github-policy-service microsoft-github-policy-service bot removed the Needs-Triage The issue is new and needs to be triaged by a work group. label Nov 20, 2023
@mcqueene
Copy link

The OS on the affected PC is freshly installed from ISO a week ago. The only thing that is different on this PC is that it is managed by company policies pushed via Microsoft Intune. One of these policies enabled "Constrained Language Audit Mode" (whatever it means). I guess that this "Constrained Language Audit Mode" is breaking [pscustomobject].

I can confirm the same issue with Constrained Language Audit Mode breaking [pscustomobject]

@mklement0
Copy link
Contributor

mklement0 commented Nov 22, 2023

Update: See next comment.


@shivtorov, note that [System.Management.Automation.PSCustomObject] @{ foo = 1 } never worked - only [pscustomobject] @{ foo = 1 } does, because - confusingly - these aren't the same types ([pscustomobject] is the same type as [psobject], i.e. [System.Management.Automation.PSObject], but the syntactic sugar only works with [pscustomobject]:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants