Comments (6)
I tried to replicate using a minimal script
$workbooks = @{}
foreach ($workbookfile in 'foo', 'bar')
{
$workbooks.Add($workbookfile,($workbookfile+' value'))
}
$workbooks
When run as a script it gives
Name Value
---- -----
bar bar value
foo foo value
So that looks right.
Whn you say "it is not a hashtable" what does
$workbooks.GetType().Name
Also try using
$workbooks | Format-Table
to isolate the just the workbooks. Your output may include other objects
from powershell.
It looks like something is affecting the presentation of the output of the script, not the behaviour of the objects within the script.
from powershell.
I think there is something in your code that you are not showing
$workbooks['foo']
gave me
foo value
I suggest write an absolute minimal script like mine which shows the behaviour of the hashtable as expected, and add line by line until you get your script and see when the behaviour changes
It may simply be a typo somewhere.
from powershell.
When i run $workbooks.GetType() i get this:
IsCollectible : False
DeclaringMethod :
FullName : System.Collections.Hashtable
AssemblyQualifiedName : System.Collections.Hashtable, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
Namespace : System.Collections
GUID : 68000a59-efdd-3d2a-a34a-7996b712988b
IsEnum : False
GenericParameterAttributes :
IsSZArray : False
GenericParameterPosition :
ContainsGenericParameters : False
StructLayoutAttribute : System.Runtime.InteropServices.StructLayoutAttribute
Name : Hashtable
DeclaringType :
Assembly : System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
BaseType : System.Object
IsByRefLike : False
IsConstructedGenericType : False
IsGenericType : False
IsGenericTypeDefinition : False
IsGenericParameter : False
IsTypeDefinition : True
IsSecurityCritical : True
IsSecuritySafeCritical : False
IsSecurityTransparent : False
MemberType : TypeInfo
MetadataToken : 33556676
Module : System.Private.CoreLib.dll
ReflectedType :
TypeHandle : System.RuntimeTypeHandle
UnderlyingSystemType : System.Collections.Hashtable
GenericTypeParameters : {}
DeclaredConstructors : {Void .ctor(Boolean), Void .ctor(), Void .ctor(Int32), Void .ctor(Int32, Single)…}
DeclaredEvents : {}
DeclaredFields : {_buckets, _count, _occupancy, _loadsize…}
DeclaredMembers : {System.Collections.IHashCodeProvider get_hcp(), Void set_hcp(System.Collections.IHashCodeProvider), System.Collections.ICo
mparer get_comparer(), Void set_comparer(System.Collections.IComparer)…}
DeclaredMethods : {System.Collections.IHashCodeProvider get_hcp(), Void set_hcp(System.Collections.IHashCodeProvider), System.Collections.ICo
mparer get_comparer(), Void set_comparer(System.Collections.IComparer)…}
DeclaredNestedTypes : {System.Collections.Hashtable+Bucket, System.Collections.Hashtable+KeyCollection, System.Collections.Hashtable+ValueCollect
ion, System.Collections.Hashtable+SyncHashtable…}
DeclaredProperties : {System.Collections.IHashCodeProvider hcp, System.Collections.IComparer comparer, System.Collections.IEqualityComparer Equa
lityComparer, System.Object Item [System.Object]…}
ImplementedInterfaces : {System.Collections.IDictionary, System.Collections.ICollection, System.Collections.IEnumerable, System.Runtime.Serializati
on.ISerializable…}
IsInterface : False
IsNested : False
IsArray : False
IsByRef : False
IsPointer : False
IsGenericTypeParameter : False
IsGenericMethodParameter : False
IsVariableBoundArray : False
HasElementType : False
GenericTypeArguments : {}
Attributes : AutoLayout, AnsiClass, Class, Public, Serializable, BeforeFieldInit
IsAbstract : False
IsImport : False
IsSealed : False
IsSpecialName : False
IsClass : True
IsNestedAssembly : False
IsNestedFamANDAssem : False
IsNestedFamily : False
IsNestedFamORAssem : False
IsNestedPrivate : False
IsNestedPublic : False
IsNotPublic : False
IsPublic : True
IsAutoLayout : True
IsExplicitLayout : False
IsLayoutSequential : False
IsAnsiClass : True
IsAutoClass : False
IsUnicodeClass : False
IsCOMObject : False
IsContextful : False
IsMarshalByRef : False
IsPrimitive : False
IsValueType : False
IsSignatureType : False
TypeInitializer :
IsSerializable : True
IsVisible : True
CustomAttributes : {[System.SerializableAttribute()], [System.Runtime.CompilerServices.NullableContextAttribute((Byte)1)], [System.Runtime.Com
pilerServices.NullableAttribute((Byte)0)], [System.Reflection.DefaultMemberAttribute("Item")]…}
But when i run GetType on normal hashtable i get this:
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True Hashtable System.Object
The problem is also i cant do $workbooks["workbookName1"] because i get error that the index not exists.
from powershell.
Then why i cant access data via index?
from powershell.
📣 Hey @mcgiany, how did we do? We would love to hear your feedback with the link below! 🗣️
🔗 https://aka.ms/PSRepoFeedback
from powershell.
Related Issues (20)
- `Remove-Item` reports incorrect number of removed items in the progress bar HOT 1
- Bug - PowerShell displays an error when loading in Windows Terminal HOT 5
- Show payload being sent when using verbose with Invoke-RestMethod and Invoke-WebRequest HOT 2
- Encode spaces with %20 instead of + when using Invoke-RestMethod and Invoke-WebRequest. HOT 15
- "foreach" alias poorly named, does not reproduce functionality and use cases with ForEach-Object HOT 7
- PowerShell community Power BI dashboard - Colors of Linux and MacOS are the same in graphs HOT 4
- pwsh 7.4.2 no-input unhandled exception -> process exit HOT 4
- CreateOutOfProcessRunspace fails to Open HOT 1
- `exit` does not return ExitCode when using #Requires -Module <ScriptModule> HOT 1
- pwsh Exception not serializable anymore HOT 5
- `Using Script` directive HOT 8
- Write-Information outputting twice with jobs and is it really Write-Host in disguise. HOT 1
- Unable to attach Visual Studio debugger to pwsh.exe process HOT 7
- `+=` copies array many times HOT 16
- Expand -OutputFormat to include JSON output HOT 12
- Out-GridView filtering doesn't allow entering strings with embedded spaces HOT 1
- Add Delimiter or NewLine argument to Set-Content HOT 12
- Get-Content - Inconsistent handling of Delimiters HOT 5
- Better User Interface for Powershell ISE HOT 3
- UNexpected random message HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from powershell.