File tree Expand file tree Collapse file tree 8 files changed +44
-15
lines changed Expand file tree Collapse file tree 8 files changed +44
-15
lines changed Original file line number Diff line number Diff line change
1
+ function ConvertTo-HashTable {
2
+ <#
3
+ . SYNOPSIS
4
+ Converts a PSCustomObject to Hashtable
5
+
6
+ . DESCRIPTION
7
+ PowerShell v4 on Windows 8.1 seems to have trouble casting [PSCustomObject] to custom classes.
8
+ This function is a workaround, as casting from [Hashtable] is no problem.
9
+ #>
10
+ param (
11
+ # Object to convert
12
+ [Parameter (Mandatory = $true )]
13
+ [PSCustomObject ]$InputObject
14
+ )
15
+
16
+ begin {
17
+ $hash = @ {}
18
+ $InputObject.PSObject.properties | Foreach-Object {
19
+ $hash [$_.Name ] = $_.Value
20
+ }
21
+ Write-Output $hash
22
+ }
23
+ }
Original file line number Diff line number Diff line change @@ -15,12 +15,12 @@ function ConvertTo-Icon {
15
15
Process {
16
16
foreach ($object in $InputObject ) {
17
17
Write-Verbose " [$ ( $MyInvocation.MyCommand.Name ) ] Converting Object to Icon"
18
- ($object | Select-Object `
18
+ [ ConfluencePS.Icon ]( ConvertTo-Hashtable - InputObject ($object | Select-Object `
19
19
Path,
20
20
Width,
21
21
Height,
22
22
IsDefault
23
- ) -as [ ConfluencePS.Icon ]
23
+ ))
24
24
}
25
25
}
26
26
}
Original file line number Diff line number Diff line change @@ -15,11 +15,11 @@ function ConvertTo-Label {
15
15
Process {
16
16
foreach ($object in $InputObject ) {
17
17
Write-Verbose " [$ ( $MyInvocation.MyCommand.Name ) ] Converting Object to Label"
18
- ($object | Select-Object `
18
+ [ ConfluencePS.Label ]( ConvertTo-Hashtable - InputObject ($object | Select-Object `
19
19
id,
20
20
name,
21
21
prefix
22
- ) -as [ ConfluencePS.Label ]
22
+ ))
23
23
}
24
24
}
25
25
}
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ function ConvertTo-Page {
15
15
Process {
16
16
foreach ($object in $InputObject ) {
17
17
Write-Verbose " [$ ( $MyInvocation.MyCommand.Name ) ] Converting Object to Page"
18
- ($object | Select-Object `
18
+ [ ConfluencePS.Page ]( ConvertTo-Hashtable - InputObject ($object | Select-Object `
19
19
id,
20
20
status,
21
21
title,
@@ -55,7 +55,7 @@ function ConvertTo-Page {
55
55
else {$null }
56
56
}
57
57
}
58
- ) -as [ ConfluencePS.Page ]
58
+ ))
59
59
}
60
60
}
61
61
}
Original file line number Diff line number Diff line change @@ -15,11 +15,11 @@ function ConvertTo-PageAncestor {
15
15
Process {
16
16
foreach ($object in $InputObject ) {
17
17
Write-Verbose " [$ ( $MyInvocation.MyCommand.Name ) ] Converting Object to Page (Ancestor)"
18
- ($object | Select-Object `
18
+ [ ConfluencePS.Page ]( ConvertTo-Hashtable - InputObject ($object | Select-Object `
19
19
id,
20
20
status,
21
21
title
22
- ) -as [ ConfluencePS.Page ]
22
+ ))
23
23
}
24
24
}
25
25
}
Original file line number Diff line number Diff line change @@ -15,19 +15,25 @@ function ConvertTo-Space {
15
15
Process {
16
16
foreach ($object in $InputObject ) {
17
17
Write-Verbose " [$ ( $MyInvocation.MyCommand.Name ) ] Converting Object to Space"
18
- ($object | Select-Object `
18
+ [ ConfluencePS.Space ]( ConvertTo-Hashtable - InputObject ($object | Select-Object `
19
19
id,
20
20
key,
21
21
name,
22
22
@ {Name = " description" ; Expression = {$_.description.plain.value }},
23
- icon,
23
+ @ {Name = " Icon" ; Expression = {
24
+ if ($_.icon ) {
25
+ ConvertTo-Icon $_.icon
26
+ }
27
+ else {$null }
28
+ }
29
+ },
24
30
type,
25
31
@ {Name = " Homepage" ; Expression = {
26
32
if ($_.homepage -is [PSCustomObject ]) {
27
33
ConvertTo-Page $_.homepage
28
34
} else {$null } # homepage might be a string
29
35
}}
30
- ) -as [ ConfluencePS.Space ]
36
+ ))
31
37
}
32
38
}
33
39
}
Original file line number Diff line number Diff line change @@ -15,12 +15,12 @@ function ConvertTo-User {
15
15
Process {
16
16
foreach ($object in $InputObject ) {
17
17
Write-Verbose " [$ ( $MyInvocation.MyCommand.Name ) ] Converting Object to User"
18
- ($object | Select-Object `
18
+ [ ConfluencePS.User ]( ConvertTo-Hashtable - InputObject ($object | Select-Object `
19
19
username,
20
20
userKey,
21
21
@ {Name = " profilePicture" ; Expression = { ConvertTo-Icon $_.profilePicture }},
22
22
displayname
23
- ) -as [ ConfluencePS.User ]
23
+ ))
24
24
}
25
25
}
26
26
}
Original file line number Diff line number Diff line change @@ -15,14 +15,14 @@ function ConvertTo-Version {
15
15
Process {
16
16
foreach ($object in $InputObject ) {
17
17
Write-Verbose " [$ ( $MyInvocation.MyCommand.Name ) ] Converting Object to Version"
18
- ($object | Select-Object `
18
+ [ ConfluencePS.Version ]( ConvertTo-Hashtable - InputObject ($object | Select-Object `
19
19
@ {Name = " by" ; Expression = { ConvertTo-User $_.by }},
20
20
when,
21
21
friendlyWhen,
22
22
number,
23
23
message,
24
24
minoredit
25
- ) -as [ ConfluencePS.Version ]
25
+ ))
26
26
}
27
27
}
28
28
}
You can’t perform that action at this time.
0 commit comments