PowerShell: convert array to html table
How would I convert simple array of hashes in PowerShell to HTML table?
$array = @{
"Name" = "My Name"
"Surname" = "My Surname"
"Address" = "My Address"
"DateOfBirth" = "My Date Of Birth"
"Hobby" = "My Hobby"
"Age" = "My Age"
}

And then just keep adding rows? Has anyone achieved this before? Below I will provide examples of that I've tried so far according to several online forums:
[System.Management.Automation.PSCustomObject]$array | ConvertTo-Html
-Fragment
Cannot convert the "System.Collections.Hashtable" value of type
"System.Collections.Hashtable" to type
"System.Management.Automation.PSCustomObject". At line:0 char:0
+ [System.Management.Automation.PSCustomObject]$array | ConvertTo-Html ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) , RuntimeException
+ FullyQualifiedErrorId : ConvertToFinalInvalidCastException
New-Object psobject -Property $array | ConvertTo-Html -Fragment
System.Collections.DictionaryEntry System.Collections.DictionaryEntry
System.Collections.DictionaryEntry System.Collections.DictionaryEntry
System.Collections.DictionaryEntry System.Collections.DictionaryEntry
$array | Select 'Name','Surname','Address','DateOfBirth','Hobby', 'Age' | ConvertTo-HTML -Fragment
System.Collections.DictionaryEntry System.Collections.DictionaryEntry
System.Collections.DictionaryEntry System.Collections.DictionaryEntry
System.Collections.DictionaryEntry System.Collections.DictionaryEntry
$array | Select 'Name','Surname','Address','DateOfBirth','Hobby', 'Age' | ConvertTo-HTML -as Table -Fragment
System.Collections.DictionaryEntry System.Collections.DictionaryEntry
System.Collections.DictionaryEntry System.Collections.DictionaryEntry
System.Collections.DictionaryEntry System.Collections.DictionaryEntry
$array | Select 'Name','Surname','Address','DateOfBirth','Hobby', 'Age' | ConvertTo-HTML -as Table -Fragment | Out-String
System.Collections.DictionaryEntry System.Collections.DictionaryEntry
System.Collections.DictionaryEntry System.Collections.DictionaryEntry
System.Collections.DictionaryEntry System.Collections.DictionaryEntry
$table = $array.GetEnumerator() | ConvertTo-Html -Fragment -As Table

$table = $array.GetEnumerator() | select "Name", "Surname", "Address", "DateOfBirth", "Hobby", "Age" | ConvertTo-Html -Fragment -As Table

As you can see, so many different approaches, and none of them led to success :-(
html powershell converters
add a comment |
How would I convert simple array of hashes in PowerShell to HTML table?
$array = @{
"Name" = "My Name"
"Surname" = "My Surname"
"Address" = "My Address"
"DateOfBirth" = "My Date Of Birth"
"Hobby" = "My Hobby"
"Age" = "My Age"
}

And then just keep adding rows? Has anyone achieved this before? Below I will provide examples of that I've tried so far according to several online forums:
[System.Management.Automation.PSCustomObject]$array | ConvertTo-Html
-Fragment
Cannot convert the "System.Collections.Hashtable" value of type
"System.Collections.Hashtable" to type
"System.Management.Automation.PSCustomObject". At line:0 char:0
+ [System.Management.Automation.PSCustomObject]$array | ConvertTo-Html ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) , RuntimeException
+ FullyQualifiedErrorId : ConvertToFinalInvalidCastException
New-Object psobject -Property $array | ConvertTo-Html -Fragment
System.Collections.DictionaryEntry System.Collections.DictionaryEntry
System.Collections.DictionaryEntry System.Collections.DictionaryEntry
System.Collections.DictionaryEntry System.Collections.DictionaryEntry
$array | Select 'Name','Surname','Address','DateOfBirth','Hobby', 'Age' | ConvertTo-HTML -Fragment
System.Collections.DictionaryEntry System.Collections.DictionaryEntry
System.Collections.DictionaryEntry System.Collections.DictionaryEntry
System.Collections.DictionaryEntry System.Collections.DictionaryEntry
$array | Select 'Name','Surname','Address','DateOfBirth','Hobby', 'Age' | ConvertTo-HTML -as Table -Fragment
System.Collections.DictionaryEntry System.Collections.DictionaryEntry
System.Collections.DictionaryEntry System.Collections.DictionaryEntry
System.Collections.DictionaryEntry System.Collections.DictionaryEntry
$array | Select 'Name','Surname','Address','DateOfBirth','Hobby', 'Age' | ConvertTo-HTML -as Table -Fragment | Out-String
System.Collections.DictionaryEntry System.Collections.DictionaryEntry
System.Collections.DictionaryEntry System.Collections.DictionaryEntry
System.Collections.DictionaryEntry System.Collections.DictionaryEntry
$table = $array.GetEnumerator() | ConvertTo-Html -Fragment -As Table

$table = $array.GetEnumerator() | select "Name", "Surname", "Address", "DateOfBirth", "Hobby", "Age" | ConvertTo-Html -Fragment -As Table

As you can see, so many different approaches, and none of them led to success :-(
html powershell converters
Your initialHow would I convert simple arrayand the error msgCannot convert the "System.Collections.Hashtable"should tell you, where you got it wrong:@{}creates a hashtable not a simple arry.
– LotPings
Nov 12 '18 at 19:00
@LotPings let me rephrase the question
– TiredOfProgramming
Nov 12 '18 at 19:03
add a comment |
How would I convert simple array of hashes in PowerShell to HTML table?
$array = @{
"Name" = "My Name"
"Surname" = "My Surname"
"Address" = "My Address"
"DateOfBirth" = "My Date Of Birth"
"Hobby" = "My Hobby"
"Age" = "My Age"
}

And then just keep adding rows? Has anyone achieved this before? Below I will provide examples of that I've tried so far according to several online forums:
[System.Management.Automation.PSCustomObject]$array | ConvertTo-Html
-Fragment
Cannot convert the "System.Collections.Hashtable" value of type
"System.Collections.Hashtable" to type
"System.Management.Automation.PSCustomObject". At line:0 char:0
+ [System.Management.Automation.PSCustomObject]$array | ConvertTo-Html ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) , RuntimeException
+ FullyQualifiedErrorId : ConvertToFinalInvalidCastException
New-Object psobject -Property $array | ConvertTo-Html -Fragment
System.Collections.DictionaryEntry System.Collections.DictionaryEntry
System.Collections.DictionaryEntry System.Collections.DictionaryEntry
System.Collections.DictionaryEntry System.Collections.DictionaryEntry
$array | Select 'Name','Surname','Address','DateOfBirth','Hobby', 'Age' | ConvertTo-HTML -Fragment
System.Collections.DictionaryEntry System.Collections.DictionaryEntry
System.Collections.DictionaryEntry System.Collections.DictionaryEntry
System.Collections.DictionaryEntry System.Collections.DictionaryEntry
$array | Select 'Name','Surname','Address','DateOfBirth','Hobby', 'Age' | ConvertTo-HTML -as Table -Fragment
System.Collections.DictionaryEntry System.Collections.DictionaryEntry
System.Collections.DictionaryEntry System.Collections.DictionaryEntry
System.Collections.DictionaryEntry System.Collections.DictionaryEntry
$array | Select 'Name','Surname','Address','DateOfBirth','Hobby', 'Age' | ConvertTo-HTML -as Table -Fragment | Out-String
System.Collections.DictionaryEntry System.Collections.DictionaryEntry
System.Collections.DictionaryEntry System.Collections.DictionaryEntry
System.Collections.DictionaryEntry System.Collections.DictionaryEntry
$table = $array.GetEnumerator() | ConvertTo-Html -Fragment -As Table

$table = $array.GetEnumerator() | select "Name", "Surname", "Address", "DateOfBirth", "Hobby", "Age" | ConvertTo-Html -Fragment -As Table

As you can see, so many different approaches, and none of them led to success :-(
html powershell converters
How would I convert simple array of hashes in PowerShell to HTML table?
$array = @{
"Name" = "My Name"
"Surname" = "My Surname"
"Address" = "My Address"
"DateOfBirth" = "My Date Of Birth"
"Hobby" = "My Hobby"
"Age" = "My Age"
}

And then just keep adding rows? Has anyone achieved this before? Below I will provide examples of that I've tried so far according to several online forums:
[System.Management.Automation.PSCustomObject]$array | ConvertTo-Html
-Fragment
Cannot convert the "System.Collections.Hashtable" value of type
"System.Collections.Hashtable" to type
"System.Management.Automation.PSCustomObject". At line:0 char:0
+ [System.Management.Automation.PSCustomObject]$array | ConvertTo-Html ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) , RuntimeException
+ FullyQualifiedErrorId : ConvertToFinalInvalidCastException
New-Object psobject -Property $array | ConvertTo-Html -Fragment
System.Collections.DictionaryEntry System.Collections.DictionaryEntry
System.Collections.DictionaryEntry System.Collections.DictionaryEntry
System.Collections.DictionaryEntry System.Collections.DictionaryEntry
$array | Select 'Name','Surname','Address','DateOfBirth','Hobby', 'Age' | ConvertTo-HTML -Fragment
System.Collections.DictionaryEntry System.Collections.DictionaryEntry
System.Collections.DictionaryEntry System.Collections.DictionaryEntry
System.Collections.DictionaryEntry System.Collections.DictionaryEntry
$array | Select 'Name','Surname','Address','DateOfBirth','Hobby', 'Age' | ConvertTo-HTML -as Table -Fragment
System.Collections.DictionaryEntry System.Collections.DictionaryEntry
System.Collections.DictionaryEntry System.Collections.DictionaryEntry
System.Collections.DictionaryEntry System.Collections.DictionaryEntry
$array | Select 'Name','Surname','Address','DateOfBirth','Hobby', 'Age' | ConvertTo-HTML -as Table -Fragment | Out-String
System.Collections.DictionaryEntry System.Collections.DictionaryEntry
System.Collections.DictionaryEntry System.Collections.DictionaryEntry
System.Collections.DictionaryEntry System.Collections.DictionaryEntry
$table = $array.GetEnumerator() | ConvertTo-Html -Fragment -As Table

$table = $array.GetEnumerator() | select "Name", "Surname", "Address", "DateOfBirth", "Hobby", "Age" | ConvertTo-Html -Fragment -As Table

As you can see, so many different approaches, and none of them led to success :-(
html powershell converters
html powershell converters
edited Nov 12 '18 at 19:23
asked Nov 12 '18 at 18:43
TiredOfProgramming
347214
347214
Your initialHow would I convert simple arrayand the error msgCannot convert the "System.Collections.Hashtable"should tell you, where you got it wrong:@{}creates a hashtable not a simple arry.
– LotPings
Nov 12 '18 at 19:00
@LotPings let me rephrase the question
– TiredOfProgramming
Nov 12 '18 at 19:03
add a comment |
Your initialHow would I convert simple arrayand the error msgCannot convert the "System.Collections.Hashtable"should tell you, where you got it wrong:@{}creates a hashtable not a simple arry.
– LotPings
Nov 12 '18 at 19:00
@LotPings let me rephrase the question
– TiredOfProgramming
Nov 12 '18 at 19:03
Your initial
How would I convert simple array and the error msg Cannot convert the "System.Collections.Hashtable" should tell you, where you got it wrong: @{} creates a hashtable not a simple arry.– LotPings
Nov 12 '18 at 19:00
Your initial
How would I convert simple array and the error msg Cannot convert the "System.Collections.Hashtable" should tell you, where you got it wrong: @{} creates a hashtable not a simple arry.– LotPings
Nov 12 '18 at 19:00
@LotPings let me rephrase the question
– TiredOfProgramming
Nov 12 '18 at 19:03
@LotPings let me rephrase the question
– TiredOfProgramming
Nov 12 '18 at 19:03
add a comment |
2 Answers
2
active
oldest
votes
You mean something like this?
$table = [PSCustomobject]$array| ConvertTo-Html -Fragment -As Table
$table
<table>
<colgroup><col/><col/><col/><col/><col/><col/></colgroup>
<tr><th>Name</th><th>Age</th><th>Surname</th><th>DateOfBirth</th><th>Hobby</th><th>Address</th></tr>
<tr><td>My Name</td><td>My Age</td><td>My Surname</td><td>My Date Of Birth</td><td>My Hobby</td><td>My Address</td></tr>
</table>
From what source do you want to add rows?
add a comment |
'11','22','33' | ForEach{[PSCustomObject]@{'My Column Name'=$_}} | ConvertTo-HTML -Fragment -Property 'My Column Name'
Your output would then be:
<table>
<colgroup><col/></colgroup>
<tr><th>My Column Name</th></tr>
<tr><td>11</td></tr>
<tr><td>22</td></tr>
<tr><td>33</td></tr>
</table>
This is not related to my question. I rather have more complex hash table. But thanks for taking time and answering the question
– TiredOfProgramming
Nov 12 '18 at 19:24
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53268257%2fpowershell-convert-array-to-html-table%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You mean something like this?
$table = [PSCustomobject]$array| ConvertTo-Html -Fragment -As Table
$table
<table>
<colgroup><col/><col/><col/><col/><col/><col/></colgroup>
<tr><th>Name</th><th>Age</th><th>Surname</th><th>DateOfBirth</th><th>Hobby</th><th>Address</th></tr>
<tr><td>My Name</td><td>My Age</td><td>My Surname</td><td>My Date Of Birth</td><td>My Hobby</td><td>My Address</td></tr>
</table>
From what source do you want to add rows?
add a comment |
You mean something like this?
$table = [PSCustomobject]$array| ConvertTo-Html -Fragment -As Table
$table
<table>
<colgroup><col/><col/><col/><col/><col/><col/></colgroup>
<tr><th>Name</th><th>Age</th><th>Surname</th><th>DateOfBirth</th><th>Hobby</th><th>Address</th></tr>
<tr><td>My Name</td><td>My Age</td><td>My Surname</td><td>My Date Of Birth</td><td>My Hobby</td><td>My Address</td></tr>
</table>
From what source do you want to add rows?
add a comment |
You mean something like this?
$table = [PSCustomobject]$array| ConvertTo-Html -Fragment -As Table
$table
<table>
<colgroup><col/><col/><col/><col/><col/><col/></colgroup>
<tr><th>Name</th><th>Age</th><th>Surname</th><th>DateOfBirth</th><th>Hobby</th><th>Address</th></tr>
<tr><td>My Name</td><td>My Age</td><td>My Surname</td><td>My Date Of Birth</td><td>My Hobby</td><td>My Address</td></tr>
</table>
From what source do you want to add rows?
You mean something like this?
$table = [PSCustomobject]$array| ConvertTo-Html -Fragment -As Table
$table
<table>
<colgroup><col/><col/><col/><col/><col/><col/></colgroup>
<tr><th>Name</th><th>Age</th><th>Surname</th><th>DateOfBirth</th><th>Hobby</th><th>Address</th></tr>
<tr><td>My Name</td><td>My Age</td><td>My Surname</td><td>My Date Of Birth</td><td>My Hobby</td><td>My Address</td></tr>
</table>
From what source do you want to add rows?
answered Nov 12 '18 at 19:19
LotPings
17.9k61532
17.9k61532
add a comment |
add a comment |
'11','22','33' | ForEach{[PSCustomObject]@{'My Column Name'=$_}} | ConvertTo-HTML -Fragment -Property 'My Column Name'
Your output would then be:
<table>
<colgroup><col/></colgroup>
<tr><th>My Column Name</th></tr>
<tr><td>11</td></tr>
<tr><td>22</td></tr>
<tr><td>33</td></tr>
</table>
This is not related to my question. I rather have more complex hash table. But thanks for taking time and answering the question
– TiredOfProgramming
Nov 12 '18 at 19:24
add a comment |
'11','22','33' | ForEach{[PSCustomObject]@{'My Column Name'=$_}} | ConvertTo-HTML -Fragment -Property 'My Column Name'
Your output would then be:
<table>
<colgroup><col/></colgroup>
<tr><th>My Column Name</th></tr>
<tr><td>11</td></tr>
<tr><td>22</td></tr>
<tr><td>33</td></tr>
</table>
This is not related to my question. I rather have more complex hash table. But thanks for taking time and answering the question
– TiredOfProgramming
Nov 12 '18 at 19:24
add a comment |
'11','22','33' | ForEach{[PSCustomObject]@{'My Column Name'=$_}} | ConvertTo-HTML -Fragment -Property 'My Column Name'
Your output would then be:
<table>
<colgroup><col/></colgroup>
<tr><th>My Column Name</th></tr>
<tr><td>11</td></tr>
<tr><td>22</td></tr>
<tr><td>33</td></tr>
</table>
'11','22','33' | ForEach{[PSCustomObject]@{'My Column Name'=$_}} | ConvertTo-HTML -Fragment -Property 'My Column Name'
Your output would then be:
<table>
<colgroup><col/></colgroup>
<tr><th>My Column Name</th></tr>
<tr><td>11</td></tr>
<tr><td>22</td></tr>
<tr><td>33</td></tr>
</table>
answered Nov 12 '18 at 19:04
Ammar Iqbal
314
314
This is not related to my question. I rather have more complex hash table. But thanks for taking time and answering the question
– TiredOfProgramming
Nov 12 '18 at 19:24
add a comment |
This is not related to my question. I rather have more complex hash table. But thanks for taking time and answering the question
– TiredOfProgramming
Nov 12 '18 at 19:24
This is not related to my question. I rather have more complex hash table. But thanks for taking time and answering the question
– TiredOfProgramming
Nov 12 '18 at 19:24
This is not related to my question. I rather have more complex hash table. But thanks for taking time and answering the question
– TiredOfProgramming
Nov 12 '18 at 19:24
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53268257%2fpowershell-convert-array-to-html-table%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Your initial
How would I convert simple arrayand the error msgCannot convert the "System.Collections.Hashtable"should tell you, where you got it wrong:@{}creates a hashtable not a simple arry.– LotPings
Nov 12 '18 at 19:00
@LotPings let me rephrase the question
– TiredOfProgramming
Nov 12 '18 at 19:03