-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathObjectArrayConverter.psm1
More file actions
152 lines (137 loc) · 4.22 KB
/
ObjectArrayConverter.psm1
File metadata and controls
152 lines (137 loc) · 4.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<#
.SYNOPSIS
Creates a HTML-Table from a defined Object-Array
.DESCRIPTION
Creates a HTML-Table from a defined Object-Array
NOTE The obj parameter must be a Object[]
.PARAMETER obj
Parameter obj, Object[]
.PARAMETER showOnlyTheseHeaders
Parameter showOnlyTheseHeaders
Defines which headers should be shown in the HTML Table
.PARAMETER beautified
Parameter beautified
Defines if the table should be beautified with scripts css mechanism
.EXAMPLE
$obj = Get-Service
$table = Object2HTML -obj $obj -beautified:$true -showOnlyTheseHeaders Name, Status
Gets all Services. The object array will be converted into a HTML table.
In the table there are only the properties Name and Status visible.
.NOTES
Contact primark@united-internet.de for assistance.
#>
function Convert-ObjectArrayToJiraTable() {
param(
[Parameter(Mandatory=$true,ValueFromPipeline)]
[Object[]]$obj,
[string[]]$showOnlyTheseHeaders,
[switch]$setToClipboard
)
if($obj.GetType().Name -ne "Object[]") {
throw "$obj is no Object[]"
}
if($showOnlyTheseHeaders) {
$headers = @()
$vheaders = $obj[0].PSObject.Properties.name
foreach($head in $vheaders) {
if($head -in $showOnlyTheseHeaders) {
$headers += $head
}
}
} else {
$headers = $obj[0].PSObject.Properties.name
}
$base_html += "|| "
foreach($h in $headers) {
$base_html += "$h ||"
}
$base_html += "`n"
foreach($o in $obj) {
$base_html += "| "
if($showOnlyTheseHeaders) {
foreach($head in $headers) {
$v = ($o.PSObject.Properties | Where-Object name -eq $head).value
$base_html += "$v |"
}
} else {
foreach($v in $o.PSObject.Properties.value) {
$base_html += "$v |"
}
}
$base_html += "`n"
}
if($setToClipboard) {
return $base_html | Set-Clipboard
} else {
return $base_html
}
}
function Convert-ObjectArrayToHTMLTable() {
param(
[Parameter(Mandatory=$true,ValueFromPipeline)]
[Object[]]$obj,
[string[]]$showOnlyTheseHeaders,
[switch]$beautified
)
if($obj.GetType().Name -ne "Object[]") {
throw "$obj is no Object[]"
}
if($beautified) {
$base_html += "<style>
body {
font-family: Verdana, Geneva, Tahoma, sans-serif;
}
#MakeHTMLTableFromObject {
font-family: Arial, Helvetica, sans-serif;
border-collapse: collapse;
width: 100%;
}
#MakeHTMLTableFromObject td, #prbres th {
border: 1px solid #ddd;
padding: 8px;
}
#MakeHTMLTableFromObject tr:nth-child(even){background-color: #f2f2f2;}
#MakeHTMLTableFromObject tr:hover {background-color: #ddd;}
#MakeHTMLTableFromObject th {
padding-top: 12px;
padding-bottom: 12px;
text-align: left;
background-color: #738fca;
color: white;
}
</style>"
}
$base_html += "<table id=MakeHTMLTableFromObject>"
if($showOnlyTheseHeaders) {
$headers = @()
$vheaders = $obj[0].PSObject.Properties.name
foreach($head in $vheaders) {
if($head -in $showOnlyTheseHeaders) {
$headers += $head
}
}
} else {
$headers = $obj[0].PSObject.Properties.name
}
$base_html += "<tr>"
foreach($h in $headers) {
$base_html += "<th>$h</th>"
}
$base_html += "</tr>"
foreach($o in $obj) {
$base_html += "<tr>"
if($showOnlyTheseHeaders) {
foreach($head in $headers) {
$v = ($o.PSObject.Properties | Where-Object name -eq $head).value
$base_html += "<td>$v</td>"
}
} else {
foreach($v in $o.PSObject.Properties.value) {
$base_html += "<td>$v</td>"
}
}
$base_html += "</tr>"
}
$base_html += "</table>"
return $base_html
}