Skip to main content

Search OfficeIMO

Enter a topic, API type, or PowerShell command.

Documentation Search all OfficeIMO/
Cmdlet

ConvertTo-OfficeYaml

Module
PSWriteOffice
Inputs
System.Object
Outputs
System.String

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

Syntax

ConvertTo-OfficeYaml
[-Depth <Int32>]
[-InputObject] <Object>
[-WriteOptions <YamlWriterOptions>]
[<CommonParameters>]
#
Parameter set: InputObject

Description

Hashtables, ordered dictionaries and object properties become mappings, collections become sequences and enums their names. One piped object is written as itself and several as a sequence. Objects nested deeper than Depth (default 2) are written as their string form with a warning, as ConvertTo-Json does. Strings that YAML 1.1 readers would take as another type (yes, on, 012, 1e3) are quoted.

Examples

Turn a hashtable into a configuration snippet.

[ordered]@{ name = 'web'; replicas = 3; ports = 80, 443 } | ConvertTo-OfficeYaml

Write nested service data with four-space indentation.

Get-Service | Select-Object -First 3 Name, Status, DependentServices |
                ConvertTo-OfficeYaml -Depth 3 -WriteOptions @{ MappingIndent = 4; SequenceIndent = 4; SequenceDashOffset = 2 }

Parameters

-Depth Int32 optional
How many levels of nested objects to write; deeper values become their string form.
-InputObject Object requiredposition: 0pipeline: True (ByValue)
Objects to convert; an argument is written exactly as given, piped objects as one value or a sequence.
-WriteOptions YamlWriterOptions optional
Indentation and line-break settings, as a YamlWriterOptions object or hashtable.

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.