Getting started with PowerShellLoopsOperatorsUsing ShouldProcessPowerShell ClassesSwitch statementWorking with ObjectsUsing existing static classesBasic Set OperationsPowerShell FunctionsSending EmailHandling Secrets and CredentialsPowershell RemotingPowerShell "Streams"; Debug, Verbose, Warning, Error, Output and InformationVariables in PowerShellCommunicating with RESTful APIsWorking with the PowerShell pipelinePowerShell Background JobsReturn behavior in PowerShellWorking with XML FilesIntroduction to PsakeUsing the progress barStringsTCP Communication with PowerShellSharePoint ModuleAliasesAutomatic VariablesEnvironment VariablesPowershell profilesEnforcing script prerequisitesUsing the Help SystemSplattingDesired State ConfigurationSigning ScriptsSecurity and CryptographyCSV parsingIntroduction to PesterModules, Scripts and FunctionsPowerShell.exe Command-LineCommon parametersParameter setsRegular ExpressionsPowerShell Dynamic ParametersWMI and CIMGUI in PowershellConditional logicURL Encode/DecodeMongoDBRunning ExecutablesError handlingHashTablesActiveDirectory modulepowershell sql queriesAutomatic Variables - part 2Package managementCmdlet NamingBuilt-in variablesCreating DSC Class-Based ResourcesPowershell ModulesPowerShell WorkflowsHow to download latest artifact from Artifactory using Powershell script (v2.0 or below)?Calculated PropertiesSpecial OperatorsAnonymize IP (v4 and v6) in text file with PowershellComment-based helpAmazon Web Services (AWS) Simple Storage Service (S3)Amazon Web Services (AWS) RekognitionPSScriptAnalyzer - PowerShell Script AnalyzerNaming ConventionsEmbedding Managed Code (C# | VB)Archive ModuleInfrastructure AutomationScheduled tasks moduleISE module

Powershell profiles

Other topics

Remarks:

Profile file is a powershell script that will run while the powershell console is starting. This way we can have our environment prepared for us each time we start new powershell session.

Typical things we want to do on powershell start are:

  • importing modules we use often (ActiveDirectory, Exchange, some specific DLL)
  • logging
  • changing the prompt
  • diagnostics

There are several profile files and locations that have different uses and also hierarchy of start-up order:

HostUserPathStart orderVariable
AllAll%WINDIR%\System32\WindowsPowerShell\v1.0\profile.ps11$profile.AllUsersAllHosts
AllCurrent%USERPROFILE%\Documents\WindowsPowerShell\profile.ps13$profile.CurrentUserAllHosts
ConsoleAll%WINDIR%\System32\WindowsPowerShell\v1.0\Microsoft.PowerShell_profile.ps12$profile.AllUsersCurrentHost
ConsoleCurrent%USERPROFILE%\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps14$profile.CurrentUserCurrentHost
ISEAll%WINDIR%\System32\WindowsPowerShell\v1.0\Microsoft.PowerShellISE_profile.ps12$profile.AllUsersCurrentHost
ISECurrent%USERPROFILE%\Documents\WindowsPowerShell\Microsoft.PowerShellISE_profile.ps14$profile.CurrentUserCurrentHost

Create an basic profile

A PowerShell profile is used to load user defined variables and functions automatically.

PowerShell profiles are not automatically created for users.

To create a PowerShell profile C:>New-Item -ItemType File $profile.

If you are in ISE you can use the built in editor C:>psEdit $profile

An easy way to get started with your personal profile for the current host is to save some text to path stored in the $profile-variable

"#Current host, current user" > $profile

Further modification to the profile can be done using PowerShell ISE, notepad, Visual Studio Code or any other editor.

The $profile-variable returns the current user profile for the current host by default, but you can access the path to the machine-policy (all users) and/or the profile for all hosts (console, ISE, 3rd party) by using it's properties.

PS> $PROFILE | Format-List -Force

AllUsersAllHosts       : C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1
AllUsersCurrentHost    : C:\Windows\System32\WindowsPowerShell\v1.0\Microsoft.PowerShell_profile.ps1
CurrentUserAllHosts    : C:\Users\user\Documents\WindowsPowerShell\profile.ps1
CurrentUserCurrentHost : C:\Users\user\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
Length                 : 75

PS> $PROFILE.AllUsersAllHosts
C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1

Contributors

Topic Id: 5636

Example Ids: 19986

This site is not affiliated with any of the contributors.