ConvertFrom-OfficeYaml
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>]#InputObjectDescription
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.portRead 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
- Read every document of a multi-document stream; without it, more than one document is an error.
- -AsHashtable SwitchParameter
- Return mappings as ordered hashtables instead of PSCustomObjects.
- -Depth Int32
- Deepest nesting of mappings and sequences to accept; sets the reader's MaxDepth.
- -InputObject String
- YAML text; piped strings are joined with line breaks before parsing.
- -NoEnumerate SwitchParameter
- Write a root sequence as one array instead of enumerating its items.
- -Schema YamlSchema
- 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
- Applies the YAML specification's exact rules instead of accepting common real-world leniencies.
- -Untrusted SwitchParameter
- 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.