Created
August 23, 2018 15:25
-
-
Save gitfvb/22fd85208306bcfd53ed54a8d17a7c84 to your computer and use it in GitHub Desktop.
settings in json files - an easy example... this can be nested, also pscustomobjects can be nested
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################################ | |
# | |
# SCRIPT ROOT | |
# | |
################################################ | |
# script root path | |
if ($MyInvocation.MyCommand.CommandType -eq "ExternalScript") | |
{ $scriptPath = Split-Path -Parent -Path $MyInvocation.MyCommand.Definition } | |
else | |
{ $scriptPath = Split-Path -Parent -Path ([Environment]::GetCommandLineArgs()[0]) } | |
$settings = [pscustomobject]@{ | |
template = "value a"; | |
data = "value b"; | |
attachments = @("array content A";"array content B"); # array | |
} | |
################################################ | |
# | |
# PACK TOGETHER SETTINGS AND SAVE AS JSON | |
# | |
################################################ | |
$json = $settings | ConvertTo-Json -Depth 8 # -compress | |
$json | |
$json | Set-Content -path "$( $scriptPath )\settings.json" -Encoding UTF8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################################ | |
# | |
# PREPARATION / ASSEMBLIES | |
# | |
################################################ | |
# Load scriptpath | |
if ($MyInvocation.MyCommand.CommandType -eq "ExternalScript") { | |
$scriptPath = Split-Path -Parent -Path $MyInvocation.MyCommand.Definition | |
} else { | |
$scriptPath = Split-Path -Parent -Path ([Environment]::GetCommandLineArgs()[0]) | |
} | |
# Load settings | |
$settings = Get-Content -Path "$( $scriptPath )\settings.json" -Encoding UTF8 | ConvertFrom-Json | |
# ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment