Skip to main content

Search OfficeIMO

Enter a topic, API type, or PowerShell command.

Documentation Search all OfficeIMO/
Cmdlet

ConvertFrom-OfficeYaml

Module
PSWriteOffice
Inputs
System.String
Outputs
System.Management.Automation.PSObject System.Collections.Specialized.OrderedDictionary System.Object[]

Converts YAML text to PowerShell objects, as ConvertFrom-Json does for JSON.

Syntax

ConvertFrom-OfficeYaml
[-AllDocuments]
[-AsHashtable]
[-Depth <Int32>]
[-InputObject] <String>
[-NoEnumerate]
[-Schema <Failsafe|Json|Core|Yaml11>]
[-Strict]
[-Untrusted]
[<CommonParameters>]
#
Parameter set: InputObject

Description

Mappings become PSCustomObjects with properties in file order (ordered hashtables with AsHashtable), sequences become arrays, and scalars resolve through the Core schema to Int64, BigInteger, Double, Boolean, $null or String. Schema Failsafe keeps every scalar a string; Schema Yaml11 reads yes/no/on/off as Booleans. Aliases and merge keys are resolved. Piped lines are joined before parsing, so Get-Content output works directly. Depth sets the deepest nesting accepted (the engine default is 256).

Examples

Read a configuration file's values.

$config = Get-Content -Path ./settings.yaml -Raw | ConvertFrom-OfficeYaml
$config.database.port

Read every manifest in a multi-document stream as hashtables.

Get-Content ./manifests.yaml | ConvertFrom-OfficeYaml -AllDocuments -AsHashtable |
                ForEach-Object { '{0}/{1}' -f $_.kind, $_.metadata.name }

Parameters

-AllDocuments SwitchParameter optional
Read every document of a multi-document stream; without it, more than one document is an error.
-AsHashtable SwitchParameter optional
Return mappings as ordered hashtables instead of PSCustomObjects.
-Depth Int32 optional
Deepest nesting of mappings and sequences to accept; sets the reader's MaxDepth.
-InputObject String requiredposition: 0pipeline: True (ByValue)
YAML text; piped strings are joined with line breaks before parsing.
-NoEnumerate SwitchParameter optional
Write a root sequence as one array instead of enumerating its items.
-Schema YamlSchema optional
Schema for scalar types: Core (the default), Json, Yaml11, or Failsafe to keep every scalar a string.
Possible values: Failsafe, Json, Core, Yaml11
-Strict SwitchParameter optional
Applies the YAML specification's exact rules instead of accepting common real-world leniencies.
-Untrusted SwitchParameter optional
Caps every limit at the engine's untrusted defaults, for text from outside.

Common Parameters

This command supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable.

For more information, see about_CommonParameters.