How To Use Hash Tables With PowerShell

How To Use Hash Tables With PowerShell

https://ift.tt/30elnn1

In this blog post, I will show you how to use Hash Tables with PowerShell and explain why they are so useful.

About Hash Tables

Microsoft PowerShell Hash Tables are dictionaries or arrays that allow us to store data in a structured way using key pair values.

Create an Hash Table

Let’s go ahead and create a simple Hash Table that stores a hostname and an IP address, as shown below.

$computers = @{  localhost = "127.0.0.1"; windows10 = "10.0.1.4"}

To access the Hash Table and use it with a PowerShell cmdlet, I can use the Test-Connection cmdlet as shown below.

test-connection -TargetName $computers.windows10au

To view the content of an Hash Table you just type the name of the Hash Table as a variable.

$computers

To view the values or keys use the following options.

$computers .values
$computer.keys

The above example is very simple however in cases where there is a need to use key values pairs Hash Tables are very useful compared to using variables.

Processing…

Success! You’re on the list.

Whoops! There was an error and we couldn’t process your subscription. Please reload the page and try again.

Related

office365,Azure

via The IT And PowerShell Blog https://ift.tt/33GXxQZ

September 29, 2020 at 07:50AM
NTW – Content Network