Skip to content

Get-ConfigurationPath

SYNOPSIS

Gets an storage path for configuration files and data

SYNTAX

__ModuleInfo (Default)

Get-ConfigurationPath [-Scope <String>] [-Module <PSModuleInfo>] [-Version <Version>] [-SkipCreatingFolder]
 [<CommonParameters>]

__CallStack

Get-ConfigurationPath [-Scope <String>] [-CallStack <CallStackFrame[]>] [-Version <Version>]
 [-SkipCreatingFolder] [<CommonParameters>]

ManualOverride

Get-ConfigurationPath [-Scope <String>] -CompanyName <String> -Name <String> [-Version <Version>]
 [-SkipCreatingFolder] [<CommonParameters>]

DESCRIPTION

Gets an AppData (or roaming profile) or ProgramData path for configuration and data storage. The folder returned is guaranteed to exist (which means calling this function actually creates folders).

Get-ConfigurationPath is designed to be called from inside a module function WITHOUT any parameters.

If you need to call Get-ConfigurationPath from outside a module, you should pipe the ModuleInfo to it, like: Get-Module Powerline | Get-ConfigurationPath

As a general rule, there are three scopes which result in three different root folders User: $Env:LocalAppData Machine: $Env:ProgramData Enterprise: $Env:AppData (which is the "roaming" folder of AppData)

EXAMPLES

EXAMPLE 1

$CacheFile = Join-Path (Get-ConfigurationPath) Data.clixml
$Data | Export-CliXML -Path $CacheFile

This example shows how to use Get-ConfigurationPath with Export-CliXML to cache data as clixml from inside a module.

PARAMETERS

-Scope

The scope to save at, defaults to Enterprise (which returns a path in "RoamingData")

Type: System.String
Parameter Sets: (All)
Aliases:

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

-CallStack

A callstack. You should not ever pass this. It is used to calculate the defaults for all the other parameters.

Type: System.Management.Automation.CallStackFrame[]
Parameter Sets: __CallStack
Aliases:

Required: False
Position: Named
Default value: $(Get-PSCallStack)
Accept pipeline input: False
Accept wildcard characters: False

-Module

The Module you're importing configuration for

Type: System.Management.Automation.PSModuleInfo
Parameter Sets: __ModuleInfo
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: False

-CompanyName

An optional module qualifier (by default, this is blank)

Type: System.String
Parameter Sets: ManualOverride
Aliases: Author

Required: True
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False

-Name

The name of the module or script Will be used in the returned storage path

Type: System.String
Parameter Sets: ManualOverride
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False

-Version

The version for saved settings -- if set, will be used in the returned path NOTE: this is NOT calculated from the CallStack

Type: System.Version
Parameter Sets: (All)
Aliases:

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

-SkipCreatingFolder

By default, Get-ConfigurationPath creates the folder if it doesn't already exist This switch allows overriding that behavior: if set, does not create missing paths

Type: System.Management.Automation.SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: False
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

OUTPUTS

NOTES

  1. This command is primarily meant to be used in modules, to find a place where they can serialize data for storage.
  2. It's techincally possible for more than one module to exist with the same name. The command uses the Author or Company as a distinguishing name.
Back to top