Fixed Variable returns different results for PowerShell V5.1 & V7.1
See original GitHub issue``
Steps to reproduce
Add-Type -TypeDefinition 'using System;
using System.Management.Automation;
public class FixedVariableNow : PSVariable
{public FixedVariableNow() : base("Now", 0, ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope)
{}
public override object Value
{get { return DateTime.Now; }}
}'
$ExecutionContext.SessionState.PSVariable.Set((New-Object -TypeName FixedVariableNow))
$Now.GetDateTimeFormats().count
Pause
$Now.GetDateTimeFormats()`
Run the code above on PowerShell V5.1 and PowerShell V7.1 and compare the output
Expected behavior
On Powershell V5.1 115 items are returned.
Actual behavior
on V7.1 only 30 items are returned.
Environment data
Name Value
---- -----
PSVersion 7.1.0
PSEdition Core
GitCommitId 7.1.0
OS Microsoft Windows 10.0.19042
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Name Value
---- -----
PSVersion 5.1.19041.610
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.19041.610
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
Issue Analytics
- State:
- Created 3 years ago
- Comments:7
Top Results From Across the Web
Differences between Windows PowerShell 5.1 and ...
This article summarizes the differences and breaking changes from Windows PowerShell 5.1 and the current version of PowerShell that is based ...
Read more >PowerShell v5 vs. PowerShell v7—Which to use and when
For this reason, I'll compare PowerShell v5.1 only with PowerShell 7 from now on. Here's the $PSVersionTable output on the same Windows Server ......
Read more >Powershell 5.1 if statement result is incorrect
I've created a script to return information from "net user query (username) /domain" that includes an If statement to return results if the...
Read more >Using PowerShell to split a string into an array
The above code splits the string based on the “-” character and saves the output in the $CharArray variable. Example 1. If you...
Read more >How to fix truncated PowerShell output, even when I've ...
Pipe output to Format-Table commandlet, e.g. as follows: Get-ChildItem 'E:\' -Force -Recurse | Select-Object FullName | Format-Table - ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

You could run
([datetime]::now.GetDateTimeFormats()).countand compare - it is a question for .Net Rumtime repository if you want in depth explanations.This issue has been marked as answered and has not had any activity for 1 day. It has been closed for housekeeping purposes.