Build, Test, Publish status |
---|
This PowerShell module has scripts for getting and setting configuration values for the current user, optionally encrypting it. This is useful when doing automation and you need to store and retrieve configuration values to avoid hardcoding or committing to git, such as PAT, passwords, etc.
- Windows PowerShell 5.0 or newer.
- PowerShell Core.
JOAT-Config is in the PowerShell Gallery. To install it, execute the following command.
Install-Module -Name joat-config
The two main functions are Get-ConfigData
and Set-ConfigData
which basically set and get a key-value pair in a file in the user's home folder. Help is available for all commands. And the source has Pester tests.
For example, you can store local-specific configuration.
Set-ConfigData my.servername -value 'host-123'
Invoke-Command {dir} -computername (Get-ConfigData my.servername)
Or more useful is storing encrypted data, such as PAT, APIKeys, etc.
Set-ConfigData 'Azure.TenantId' -value 'mytenantId' -Encrypt
Set-ConfigData 'Azure.My.SubscriptionId' -value 'mysubscriptionid' -Encrypt
Connect-AzureRmAccount -TenantId (Get-ConfigData 'Azure.TenantId' -Decrypt) `
-Subscription (Get-ConfigData 'Azure.My.SubscriptionId' -Decrypt) `
-Credential (Get-Credential)
You can use dotted names to group things, or you can use objects well.
$azureConfig = @{
TenantId = 'tidsecret'
SubscriptionId = 'sidsecret'
PAT = 'verysecret'
}
Set-ConfigData -Name "AzConfig" -Value $azureConfig -Encrypt
$config = Get-ConfigData -Name AzConfig -Decrypt
$config.PAT # verysecret
Since encrypted strings are stored as SecureString
s if a cmdlet takes it, you don't need to decrypt.
ipmo VSTeam
Set-ConfigData AzurePat ukxzlafg7aalwzku4m2xzjsysoe65azzruqhady4di4qfx2pd2oq -Encrypt
Add-VSTeamAccount -SecurePersonalAccessToken (Get-ConfigData AzurePat) -Account myaccount
By default, the json file is ~/myconfig.json
. You can override it by passing in Path
to any command, setting $env:joat_config_path
or using $PSDefaultParameterValues
You may want to backup this file. To see the path that will be used, call Get-ConfigDataPath
Note: Currently only Windows supports encrypting and decrypting of data as well as using SecureStrings.
This is one of my more polished set of tools created years ago and finally put out in the Gallery. Check out other stuff at https://github.com/Seekatar