-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGeneral.ps1
More file actions
73 lines (62 loc) · 1.66 KB
/
Copy pathGeneral.ps1
File metadata and controls
73 lines (62 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<#
.SYNOPSIS
Demonstrates the public Yaml commands.
#>
Import-Module -Name Yaml
$yaml = @'
---
name: example
enabled: true
ports: [80, 443]
'@
# Parse a mapping to an ordered PSCustomObject.
$config = $yaml | ConvertFrom-Yaml
$config
# Keep a top-level sequence as one pipeline record.
$servers = @'
- name: web-1
- name: web-2
'@ | ConvertFrom-Yaml -NoEnumerate
$servers.Count
# Preserve mappings whose keys cannot be PowerShell property names.
$complexMapping = @'
? [region, port]
: eu-1
'@ | ConvertFrom-Yaml -AsHashtable
$complexMapping
# Serialize supported PowerShell data and parse it again.
$outputYaml = [ordered]@{
name = 'example'
enabled = $true
ports = @(80, 443)
} | ConvertTo-Yaml -ExplicitDocumentStart
$outputYaml
$outputYaml | ConvertFrom-Yaml
# Normalize YAML presentation without projecting its representation graph.
$normalizedYaml = @'
# Presentation differences are removed.
{ name: example, ports: [80, 443] }
'@ | Format-Yaml -Indent 4
$normalizedYaml
# Merge complete YAML streams without projecting their representation graphs.
$baseYaml = @'
service:
image: example:v1
ports: [80]
'@
$overlayYaml = @'
service:
image: example:v2
ports: [443]
'@
$mergedYaml = Merge-Yaml -InputObject @($baseYaml, $overlayYaml)
$mergedYaml
# Atomically export one file, then import it with strict decoding.
$configPath = Join-Path $env:TEMP 'yaml-example.yaml'
$config | Export-Yaml -Path $configPath -PassThru
$importedConfig = Import-Yaml -LiteralPath $configPath
$importedConfig
Remove-Item -LiteralPath $configPath
# Test syntax, duplicate keys, tags, and resource limits without conversion.
$isValid = $outputYaml | Test-Yaml
$isValid