From 699137a97cc7247c43b4e805d158897a5d146cea Mon Sep 17 00:00:00 2001 From: Christian Stein Date: Fri, 27 Mar 2020 16:36:25 +0100 Subject: [PATCH] Adds support to securely fetch elements from hashtables with default values --- lib/core/tools/Get-IcingaHashtableItem.psm1 | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 lib/core/tools/Get-IcingaHashtableItem.psm1 diff --git a/lib/core/tools/Get-IcingaHashtableItem.psm1 b/lib/core/tools/Get-IcingaHashtableItem.psm1 new file mode 100644 index 0000000..96f0eef --- /dev/null +++ b/lib/core/tools/Get-IcingaHashtableItem.psm1 @@ -0,0 +1,18 @@ +function Get-IcingaHashtableItem() +{ + param( + $Hashtable, + $Key, + $NullValue = $null + ); + + if ($null -eq $Hashtable) { + return $NullValue; + } + + if ($Hashtable.ContainsKey($Key) -eq $FALSE) { + return $NullValue; + } + + return $Hashtable[$Key]; +}