What is the usual way to provide configuration information to a custom Powershell cmdlet

Given that custom PS cmdlets are assemblies, I cannot provide them with configuration information through the regular App.config route. What is the usual way to provide configuration information to a user cmdlet?

+3
source share
2 answers

Usually I suggest just using the parameters for data transfer.

Get-MyData -connectionstring $connectionString -table Test ...

If this is impractical (too many parameters, etc.), then you can always specify the path to the configuration file using the parameter:

Get-MyData -Config .\My.config

Then you can read the specified configuration file from the cmdlet.

This allows cmdlet users to define their own configuration files for use.

+1

PowerShell - . - . powershell, :

$global:MyComponent_MySetting = '12'
# i.e. 
$PSDefaultParameterValues
$ErrorActionPreference

, , . , #/PowerShell. :

$env:PATH
$env:PSModulePath

, - .NET, . PAAS ASP.NET, CLR (ASP.NET v5).

. https://github.com/JabbR/JabbRv2/blob/dev/src/JabbR/Startup.cs#L21
: .AddEnvironmentVariables()

, . , , PowerShell <appSettings>. IMO, PS .NET .

, JSON. POSH v3 + ConvertFrom-JSON . , .json .

, , PATH, GIT .gitignore ASP.NET web.config > ( ).

+1

All Articles