Skip to content

Instantly share code, notes, and snippets.

View chriskuech's full-sized avatar

Chris Kuech chriskuech

  • Datum Source, ex MSFT
View GitHub Profile
class Cluster {
[ValidatePattern("^[A-z]+$")]
[string] $Service
[ValidateSet("TEST", "STAGE", "CANARY", "PROD")]
[string] $FlightingRing
[ValidateSet("EastUS", "WestUS", "NorthEurope")]
[string] $Region
[ValidateRange(0, 255)]
[int] $Index
}
class Cluster {
[ValidatePattern("^[A-z]+$")]
[string] $Service
[ValidateSet("TEST", "STAGE", "CANARY", "PROD")]
[string] $FlightingRing
[ValidateSet("EastUS", "WestUS", "NorthEurope")]
[string] $Region
[ValidateRange(0, 255)]
[int] $Index
class Cluster {
[ValidatePattern("^[A-z]+$")]
[string] $Service
[ValidateSet("TEST", "STAGE", "CANARY", "PROD")]
[string] $FlightingRing
[ValidateSet("EastUS", "WestUS", "NorthEurope")]
[string] $Region
[ValidateRange(0, 255)]
[int] $Index
}
[Cluster]$cluster = Get-Content "./my-cluster.json" | ConvertFrom-Json
[Cluster[]]$clusters = Import-Csv "./my-clusters.csv"
class Node {
[ValidateLength(3, 7)]
[string] $Name
[ValidateSet("INT", "PPE", "PROD")]
[string] $FlightingRing
[ValidateSet("EastUS", "WestUS", "NorthEurope", "WestEurope")]
[string] $Region
Node([string] $Name) {
$Name -match "([a-z]+)(INT|PPE|PROD)([a-z]+)"
$_, $this.Service, $this.FlightingRing, $this.Region = $Matches
# Ensure a path exists
[ValidateScript({Test-Path $_})]
$path
# Ensure a non-empty value
[ValidateNotNullOrEmpty()]
$value
# Ensure a string meets a certain convention
[ValidatePattern("^[a-z]+-[a-z]+-[a-z]+-[0-9]+$")]
# Serialize
$listOfStrings | Out-File "./listOfStrings.txt"
# Deserialize
$listOfStrings = Get-Content "./listOfStrings.txt"
# Serialize
$listOfShallowObjects | Export-Csv "./listOfShallowObjects.csv"
# Deserialize
$listOfShallowObjects = Import-Csv "./listOfShallowObjects.csv"
$container = "./container"
# Serialize
$setOfDeepObjects | % {$_ | ConvertTo-Json | Out-File "$container/$($_.SomeUniqueKeyOnEachObject).json"}
# Deserialize
$setOfDeepObjects = Get-ChildItem "$container/*.json" | % {Get-Content $_ | ConvertFrom-Json}
$nodePropertyNames = "Tier1", "Tier2", "Tier2", "LeafName"
$container = "./container"
$treePath = ($nodePropertyNames | % {$obj.$_}) -join "/"
$fsPath = "$container/$treePath.json"
# Store
New-Item $fsPath -Force
$obj | ConvertTo-Json | Out-File $fsPath