![Setting up your environment](https://sdwheeler.github.io/seanonit/images/psprofiles/slide08.png?v=3b8889b7c09db86354d6937d80f92635)
Tool and application settings
Your profile script is where you configure your environment. Use it to set configuration options that don’t persist across sessions.
Loading modules
Load the modules you use the most. Let PowerShell command discovery autoload other modules on demand.
Adding helper functions
Don’t define a bunch of utility functions in your profile script. Instead, create a module and put your functions there. Only define the functions needed to bootstrap your environment in your profile script.
Configuring colors and keybindings
PSReadLine allows you to configure colors and keybindings. Add these commands to your profile so they persist across sessions.
$PSDefaultParameterValues
The
$PSDefaultParameterValues
preference variable allows you to set default parameter values for cmdlets. For example, you may want theInstall-Module
to alway use the SkipPublisherCheck parameter.Here are several examples:
$PSDefaultParameterValues = @{ 'Out-Default:OutVariable' = 'LastResult' # Save output to $LastResult 'Out-File:Encoding' = 'utf8' # PS5.1 defaults to ASCII 'Export-Csv:NoTypeInformation' = $true # PS5.1 defaults to $false 'ConvertTo-Csv:NoTypeInformation' = $true # PS5.1 defaults to $false 'Receive-Job:Keep' = $true # Prevents accidental loss of output 'Install-Module:AllowClobber' = $true # Default behavior in Install-PSResource 'Install-Module:Force' = $true # Default behavior in Install-PSResource 'Install-Module:SkipPublisherCheck' = $true # Default behavior in Install-PSResource 'Group-Object:NoElement' = $true # Minimize noise in output 'Find-Module:Repository' = 'PSGallery' # Useful if you have private test repos 'Install-Module:Repository' = 'PSGallery' # Useful if you have private test repos 'Find-PSResource:Repository' = 'PSGallery' # Useful if you have private test repos 'Install-PSResource:Repository' = 'PSGallery' # Useful if you have private test repos }
Custom prompts
In PowerShell, the command prompt that is displayed is created by the
prompt
function. You can write your own customprompt
function to display whatever you want.