# Hash table export in csv/xml

**URL:** <https://forums.powershell.org/t/hash-table-export-in-csv-xml/23535>\
**Category:** PowerShell Help\
**Created:** [February 5, 2024, 7:23am UTC](https://forums.powershell.org/t/hash-table-export-in-csv-xml/23535 "2024-02-05T07:23:09Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![GeorgyT](https://avatars.discourse-cdn.com/v4/letter/g/f08c70/32.png) [@GeorgyT](https://forums.powershell.org/u/GeorgyT)\
**Post date:** [February 5, 2024, 7:23am UTC](https://forums.powershell.org/t/hash-table-export-in-csv-xml/23535/1 "2024-02-05T07:23:09Z")

</div>

I have a simple hash table with keys and values, like this:

```auto
Name Value
-----------
Key1 Value1
Key2 Value2
Key3 Value3

```

And I just need to export in file only keys and values. How can I do that?

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [February 5, 2024, 7:44am UTC](https://forums.powershell.org/t/hash-table-export-in-csv-xml/23535/2 "2024-02-05T07:44:23Z")

</div>

GeorgyT,  
Welcome to the forum. 👋🏼

In the vast majority of the cases you’re not the very first one with a given task. So it is recommended and surprisingly often successful to search online if there is already a solution out there. Have you tried this?

Regardless of that sinse your output does not seem to be a proper hashtable … the output of hastable in PowerShell looks like this:

```auto
Name Value 
---- ----- 
Key2 Value2
Key1 Value1
Key3 Value3

```

… it is even unclear what exactly you are looking for. Would you expect something like this as result?

```auto
Key2 Key1 Key3
---- ---- ----
Value2 Value1 Value3

```

---

<div class="post-metadata">

**Author:** ![GeorgyT](https://avatars.discourse-cdn.com/v4/letter/g/f08c70/32.png) [@GeorgyT](https://forums.powershell.org/u/GeorgyT)\
**Post date:** [February 6, 2024, 2:46am UTC](https://forums.powershell.org/t/hash-table-export-in-csv-xml/23535/3 "2024-02-06T02:46:00Z")

</div>

I tried, but PS documentation is truly bad (in compare with another languages).  
I just want to save information from hash table in file. And yes, it must be looks like:

```auto
Name Value 
---- ----- 
Key2 Value2
Key1 Value1
Key3 Value3

```

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [February 6, 2024, 4:15am UTC](https://forums.powershell.org/t/hash-table-export-in-csv-xml/23535/4 "2024-02-06T04:15:18Z")

</div>

What kind of file? Lots of guides/docs out there.

```powershell
$HashTable = @{
    Key1 = 'Value1'
    Key2 = 'Value2'
    Key3 = 'Value3'
}

$HashTable.GetEnumerator() |
Select-Object -Property Key, Value |
Export-Csv -NoTypeInformation -Path .\test.csv

```

Quick example of how to get it into a CSV file with Key/Value headers. You can rename ‘column headers’ using calculated properties if you desire:

```powershell
$HashTable.GetEnumerator() |
Select-Object -Property @{Name = 'Property'; Expression = { $_.Key } }, Value |
Export-Csv -NoTypeInformation -Path .\test.csv

```

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [February 6, 2024, 7:33am UTC](https://forums.powershell.org/t/hash-table-export-in-csv-xml/23535/5 "2024-02-06T07:33:53Z")

</div>

> [@GeorgyT](#):
>
> I tried, but PS documentation is truly bad

Have you tried any other source of information?

> [@GeorgyT](#):
>
> I just want to save information from hash table in file.

You could have mentioned that in your initial post.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [March 7, 2024, 7:34am UTC](https://forums.powershell.org/t/hash-table-export-in-csv-xml/23535/6 "2024-03-07T07:34:41Z")

</div>

Closed on March 7, 2024, 7:34am UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
