Hash Tables In Powershell

Adam Bertram explains what hash tables are and why they’re useful:

Notice that each of the keys is unique. This is required in a hash table. It’s not possible to add two keys with the same name. Below I’ve defined the SomeKey2 key twice.

We’ve just talked about creating a hash table and adding key/value pairs at creation time. It’s also possible to add keys to an already created hash table in a number of different ways, either through dot notation, enclosing the key in brackets, or by using the Add() method. Each approach has the same effect.

Hash tables are quite useful in Powershell for storing key-value pairs, like if you’re building a dictionary of configuration settings.

Related Posts

Scoping And Powershell Script Blocks

Shane O’Neill looks at variable scope within script blocks in Powershell: Now what happens if we don’t want to use switch? What happens if we tried to do this with script blocks instead? I’ve created 3 different script blocks here just for ease of use. If you want to create a single script block to […]

Read More

Concatenating Multiple SQL Files

Steve Stedman has a quick Powershell one-liner to concatenate multiple files: I come across the need occasionally to deploy a set of sql files that are all checked into source control in different files with a file hierarchy like this: Database Name Type of object (proc, table, view, etc) Name of object When I go […]

Read More

Categories

June 2017
MTWTFSS
« May Jul »
 1234
567891011
12131415161718
19202122232425
2627282930