From 414f4782fbb617632b596bb94db4622d55ef7ee3 Mon Sep 17 00:00:00 2001 From: OscarFalck17 <217069342+OscarFalck17@users.noreply.github.com> Date: Wed, 22 Oct 2025 14:10:20 +0200 Subject: [PATCH 1/3] Update hashtable documentation with cloning note Added note about cloning hashtables with a single key and provided an example using PowerShell. --- .../learn/deep-dives/everything-about-hashtable.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/reference/docs-conceptual/learn/deep-dives/everything-about-hashtable.md b/reference/docs-conceptual/learn/deep-dives/everything-about-hashtable.md index 756aeaf39f30..778ba3895bdc 100644 --- a/reference/docs-conceptual/learn/deep-dives/everything-about-hashtable.md +++ b/reference/docs-conceptual/learn/deep-dives/everything-about-hashtable.md @@ -269,6 +269,14 @@ $environments.Keys.Clone() | ForEach-Object { } ``` +Do note, you can not clone a hashtable containing a single key, that will throw an error. In such case where you want to clone the keys its better to cast the key(s) to an array instead and iterate over them. + +```powershell +@($environments.Keys) | ForEach-Object { + $environments[$_] = 'SrvDev03' +} +``` + ## Hashtable as a collection of properties So far the type of objects we placed in our hashtable were all the same type of object. I used ages From e6f7ec7d2bc5d3cce17d79ce6461ff93bb0c7375 Mon Sep 17 00:00:00 2001 From: OscarFalck17 <217069342+OscarFalck17@users.noreply.github.com> Date: Wed, 22 Oct 2025 14:15:43 +0200 Subject: [PATCH 2/3] Update reference/docs-conceptual/learn/deep-dives/everything-about-hashtable.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .../learn/deep-dives/everything-about-hashtable.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reference/docs-conceptual/learn/deep-dives/everything-about-hashtable.md b/reference/docs-conceptual/learn/deep-dives/everything-about-hashtable.md index 778ba3895bdc..84798eda35b1 100644 --- a/reference/docs-conceptual/learn/deep-dives/everything-about-hashtable.md +++ b/reference/docs-conceptual/learn/deep-dives/everything-about-hashtable.md @@ -269,7 +269,7 @@ $environments.Keys.Clone() | ForEach-Object { } ``` -Do note, you can not clone a hashtable containing a single key, that will throw an error. In such case where you want to clone the keys its better to cast the key(s) to an array instead and iterate over them. +Do note, you cannot clone a hashtable containing a single key, that will throw an error. In such case where you want to clone the keys its better to cast the key(s) to an array instead and iterate over them. ```powershell @($environments.Keys) | ForEach-Object { From 2b674165f5a0b0cf1210084c0bb588eb116d7a8a Mon Sep 17 00:00:00 2001 From: Sean Wheeler Date: Wed, 22 Oct 2025 09:42:04 -0500 Subject: [PATCH 3/3] Editorial changes --- .../learn/deep-dives/everything-about-hashtable.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/reference/docs-conceptual/learn/deep-dives/everything-about-hashtable.md b/reference/docs-conceptual/learn/deep-dives/everything-about-hashtable.md index 84798eda35b1..e4ddf78701b8 100644 --- a/reference/docs-conceptual/learn/deep-dives/everything-about-hashtable.md +++ b/reference/docs-conceptual/learn/deep-dives/everything-about-hashtable.md @@ -1,7 +1,7 @@ --- description: Hashtables are really important in PowerShell so it's good to have a solid understanding of them. ms.custom: contributor-KevinMarquette -ms.date: 06/25/2023 +ms.date: 10/22/2025 title: Everything you wanted to know about hashtables --- # Everything you wanted to know about hashtables @@ -269,7 +269,9 @@ $environments.Keys.Clone() | ForEach-Object { } ``` -Do note, you cannot clone a hashtable containing a single key, that will throw an error. In such case where you want to clone the keys its better to cast the key(s) to an array instead and iterate over them. +> [!NOTE] +> You can't clone a hashtable containing a single key. PowerShell throws an error. Instead, you +> convert the **Keys** property to an array, then iterate over the array. ```powershell @($environments.Keys) | ForEach-Object {