Skip to content

ConvertFrom-Metadata

SYNOPSIS

Deserializes objects from PowerShell Data language (PSD1)

SYNTAX

ConvertFrom-Metadata [[-InputObject] <Object>] [-Converters <Hashtable>] [-ScriptRoot <Object>] [-Ordered]
 [-AllowedVariables <String[]>] [-PSVariable <PSVariableIntrinsics>] [<CommonParameters>]

DESCRIPTION

Converts psd1 notation to actual objects, and supports passing in additional converters in addition to using the built-in registered converters (see Add-MetadataConverter).

NOTE: Any Converters that are passed in are temporarily added as though passed Add-MetadataConverter

EXAMPLES

EXAMPLE 1

ConvertFrom-Metadata 'PSObject @{ Name = PSObject @{ First = "Joel"; Last = "Bennett" }; Id = 1; }'

Id Name


1 @{Last=Bennett; First=Joel}

Convert the example string into a real PSObject using the built-in object serializer.

EXAMPLE 2

$data = ConvertFrom-Metadata .\Configuration.psd1 -Ordered

Convert a module manifest into a hashtable of properties for introspection, preserving the order in the file

EXAMPLE 3

ConvertFrom-Metadata ("DateTimeOffset 635968680686066846 -05:00:00") -Converters @{
"DateTimeOffset" = {
    param($ticks,$offset)
    [DateTimeOffset]::new( $ticks, $offset )
}
}

Shows how to temporarily add a "ValidCommand" called "DateTimeOffset" to support extra data types in the metadata.

See also the third example on ConvertTo-Metadata and Add-MetadataConverter

PARAMETERS

-InputObject

The metadata text (or a path to a metadata file)

Type: System.Object
Parameter Sets: (All)
Aliases: PSPath

Required: False
Position: 1
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False

-Converters

A hashtable of MetadataConverters (same as with Add-MetadataConverter)

Type: System.Collections.Hashtable
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: @{}
Accept pipeline input: False
Accept wildcard characters: False

-ScriptRoot

The PSScriptRoot which the metadata should be evaluated from. You do not normally need to pass this, and it has no effect unless you're referencing $ScriptRoot in your metadata

Type: System.Object
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: "$PSScriptRoot"
Accept pipeline input: False
Accept wildcard characters: False

-Ordered

If set (and PowerShell version 4 or later) preserve the file order of configuration This results in the output being an OrderedDictionary instead of Hashtable

Type: System.Management.Automation.SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False

-AllowedVariables

Allows extending the valid variables which are allowed to be referenced in metadata BEWARE: This exposes the value of these variables in your context to the caller You ware reponsible to only allow variables which you know are safe to share

Type: System.String[]
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-PSVariable

You should not pass this. The PSVariable parameter is for preserving variable scope within the Metadata commands

Type: System.Management.Automation.PSVariableIntrinsics
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

INPUTS

OUTPUTS

NOTES

Back to top