internal/functions/Set-PackageUpdateSetting/ConvertFrom-PackageUpdateSetting.ps1

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
function ConvertFrom-PackageUpdateSetting {
    <#
    .SYNOPSIS
        ConvertFrom-PackageUpdateSetting
 
    .DESCRIPTION
        Convert from a PackageUpdateSetting object to a PSCustomObject
 
    .PARAMETER InputObject
        The PackageUpdateSetting object to convert
 
    .PARAMETER AsHashTable
        Output is done as hashtable, not as PSObject
 
    .EXAMPLE
        PS C:\> ConvertFrom-PackageUpdateSetting -InputObject (Get-PackageUpdateSetting)
 
        Check if URI is a URI that can be covered for plain text release notes
    #>

    [CmdletBinding()]
    param (
        [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, ParameterSetName = "SetBehaviour")]
        [PackageUpdate.Configuration]
        $InputObject,

        [switch]
        $AsHashTable
    )

    begin {
    }

    process {
        $hash = [ordered]@{ }

        $notToString = @("System.Boolean", "System.String[]", "System.Int", "PackageUpdate.ModuleRule", "PackageUpdate.ModuleRule[]")
        foreach ($property in $InputObject.psobject.Properties) {
            if ($property.TypeNameOfValue -in $notToString) {
                $hash[$property.Name] = $property.Value
            } else {
                $hash[$property.Name] = [String]($property.Value)
            }
        }

        if ($AsHashTable) {
            $hash
        } else {
            [PSCustomObject]$hash
        }
    }

    end {
    }
}