question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:closed
  • Created 3 years ago
  • Comments:7

github_iconTop GitHub Comments

2reactions
iSazonovcommented, Nov 17, 2020

You could run ([datetime]::now.GetDateTimeFormats()).count and compare - it is a question for .Net Rumtime repository if you want in depth explanations.

0reactions
msftbot[bot]commented, Nov 19, 2020

This issue has been marked as answered and has not had any activity for 1 day. It has been closed for housekeeping purposes.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found