Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powershell hashtable keys with special characters

Tags:

powershell

I'm having trouble trying to access a hashtable with a / in the key. In my case the keys are mime types, and a simple example of the hashtable looks like:

PS H:\> $h

Name                           Value                                                                                                                         
----                           -----                                                                                                                         
application/pdf                {application/pdf, application/pdf}

When I try to do access by the Key name, I am not getting any results:

   PS H:\> $h."application/pdf"

   _______________________________________
   PS H:\> $h["application/pdf"]

   _____________________________________________
   PS H:\>

What is going on here, and how to I use this key?

like image 403
slipsec Avatar asked Oct 04 '22 13:10

slipsec


1 Answers

In my opinion the Key is not a string but an object? I have no problems getting the value both ways:

PS> $h=@{'application/pdf'='application/pdf'}
PS> $h["application/pdf"]    
application/pdf

PS> $h."application/pdf"
application/pdf
like image 117
Shay Levy Avatar answered Oct 10 '22 02:10

Shay Levy