Skip to content

Get-SettingsFromFile

SYNOPSIS

Get settings for script

SYNTAX

1
2
Get-SettingsFromFile [[-Filename] <String>] [[-Path] <String>] [-ProgressAction <ActionPreference>]
 [<CommonParameters>]

DESCRIPTION

The Get-SettingsFromFile function looks for a file named globalSettings.json, a file named scriptName.json and for a object in globalSettings.json with same name as the script file invoking the function and returns a PSCustomObject with the combined settings.

If the same setting is found in multiple places the following priority is used:

  1. Scriptnamed object in globalSettings.json.
  2. scriptName.json.
  3. Global object in globalSettings.json.

Before returning the PSCustomObject all settings values are matched against the string 'globalValue'. If there is a match the value for the global settings with the same name will be used.

EXAMPLES

EXAMPLE 1

1
Get-SettingsFromFile

In this example we are using the function in a scriptfile named testService.ps1. All settings from 'testService.json' (if exist) and the testService object in 'globalSettings' will be added to the returning PSCustomObject.

PARAMETERS

-Filename

Name of file containing script specific settings.

1
2
3
4
5
6
7
8
9
Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: 1
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Path

Path to directory where settings files are located.

1
2
3
4
5
6
7
8
9
Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: 2
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-ProgressAction

Determines how PowerShell responds to progress updates generated by a script, cmdlet, or provider, such as the progress bars generated by the Write-Progress cmdlet. The Write-Progress cmdlet creates progress bars that show a command's status.

The ProgressAction parameter takes one of the ActionPreference enumeration values: SilentlyContinue, Stop, Continue, Inquire, Ignore, Suspend, or Break.

1
2
3
4
5
6
7
8
9
Type: ActionPreference
Parameter Sets: (All)
Aliases: proga

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

INPUTS

None. You cannot pipe objects to Get-SettingsFromFile

OUTPUTS

PSCustomObject

NOTES