# encoding: ascii
# api: powershell
# title: PowerShell script config
# description: Stores script configuration on computer. This one is generic and would work with any PowerShell script/tool. A more PowerGUI specific one can be found at: http://dmitrysotnikov.wordpress.com/2010/05/07/storing-powergui-add-on-configuration
# version: 0.1
# type: script
# license: CC0
# x-poshcode-id: 1824
# x-archived: 2010-05-11T02:15:11
#
#
#################################################
# Sample code showing how to save/load PowerShell script
# configuration to disk
#
# (c) Dmitry Sotnikov
# http://dmitrysotnikov.wordpress.com/2010/05/07/storing-powergui-add-on-configuration
#################################################
# Assign unique folder and config names
# This would sore data in
# C:\Users\username\AppData\Roaming\MyPowerGUIAddOn\MyAddOn.Config.xml
$FolderName = "MyPowerGUIAddOn"
$ConfigName = "MyAddOn.Config.xml"
# keep all add-on parameters in a map
$parameters = @{}
# read parameters
if ( Test-Path -Path "$($env:AppData)\$FolderName\$ConfigName") {
$parameters = Import-Clixml -Path "$($env:AppData)\$FolderName\$ConfigName"
# now you can use them, e.g.
$parameters['A']
$parameters['B']
} else {
# Config does not exist yet - set defaults
$parameters['A'] = 5
$parameters['B'] = "Qwerty"
}
# store parameters
if ( -not (Test-Path -Path "$($env:AppData)\$FolderName")) {
mkdir "$($env:AppData)\$FolderName"
}
$parameters | Export-Clixml -Path "$($env:AppData)\$FolderName\$ConfigName"