ConvertFrom-PrimitiveType.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
function ConvertFrom-PrimitiveType {
    [CmdletBinding()]
    param(
        [Parameter(Mandatory,ValueFromPipeline)]
        [ValidateNotNullOrEmpty()]
        $InputObject
    )

    Process {
        Write-Debug ('[{0}] Entered process block' -f $MyInvocation.MyCommand)

        $InputObject | ForEach-Object {
            if (-Not $_.GetType().IsPrimitive) {
                throw ('[{0}] Value is not a primitive type' -f $MyInvocation.MyCommand)
            }

            [pscustomobject]@{
                Value = $_
            }
        }
    }
}

New-Alias -Name cfpt -Value ConvertFrom-PrimitiveType -Force