Unexpected behaviour while populating values in an ordered hash table
See original GitHub issuePrerequisites
- Write a descriptive title.
- Make sure you are able to repro it on the latest released version
- Search the existing issues.
- Refer to the FAQ.
- Refer to Differences between Windows PowerShell 5.1 and PowerShell.
Steps to reproduce
Create an ordered hash table and populate some of its properties with values previously defined in the hash table. Sometimes the values get populated, sometimes not.
$Api = [ordered]@{
apiToken = ""
validUntil = $(Get-Date)
baseUrl = "https://someUrl.com"
apiEndPoint = "api/config/v1"
vaultEndpoint = "$($Api.baseUrl)/$($Api.apiEndPoint)/vault/account"
tokenEndpoint = "$($Api.baseUrl)/oauth2/token"
clientId = ""
clientSecret = ""
}
Expected behavior
PS> Write-Host $Api.tokenEndpoint
https://someUrl.com/oauth2/token
Actual behavior
PS> Write-Host $Api.tokenEndpoint
oauth2/token
Error details
No response
Environment data
Name Value
---- -----
PSVersion 7.2.6
PSEdition Core
GitCommitId 7.2.6
OS Microsoft Windows 10.0.19044
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Visuals
No response
Issue Analytics
- State:
- Created a year ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Allow HashTable to reference itself · Issue #13782
Allow HashTable to reference itself #13782 ... Unexpected behaviour while populating values in an ordered hash table #17971.
Read more >Unexpected hash's behavior - ruby
First, some comments: Your code is not indented in a way that most others do it, which makes it hard for others to...
Read more >Everything you wanted to know about hashtables
Hashtables are really important in PowerShell so it's good to have a solid understanding of them.
Read more >An unexpected PowerShell HashTable feature
The cause of this unexpected behaviour is the second hashtable entry we inserted: Keys. This hashtable entry hides the PowerShell hashtable built-in Keys ......
Read more >Build a Hash Table in Python With TDD
In this step-by-step tutorial, you'll implement the classic hash table data structure using Python. Along the way, you'll learn how to cope with...
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
IIRC If you run the code with no pre-existing hash table , $hashtable.key will be null. If you run it to recreate an existing hash table, it will use the pre-existing value, not the value you are putting into the new version.
A simpler and more robust workaround, as also shown in the linked issue, is to use aux. variables: