PowerShell Profiles: Are they right for you?
PowerShell Profiles
Ok, so you’ve decided to bite the bullet and start working more with PowerShell and you’ve seen the benefits or working with it and maybe you’ve even learned to enjoy it! You have a strong foundation of working with CMDLETs, you’ve built some scripts and even developed some aliases and functions that you use daily from your workstation.
This could be the perfect time to start exploring PowerShell profiles. PowerShell profiles allow you to have automatic access to these types of tools without the need to manually build them in each session. The guild below will guide you through the process of creating and building out a profile.
Creating the Profile File
The profile script is a text document that lives in a special file path built into PowerShell as a variable: $profile. To view the full path of the profile’s location, type the variable $profile. This is the location to the file, but the file doesn’t actually exist yet. We can verify that by running a simple CMDLET:
Test-path $profile
This should return the value “False” stating that there is nothing in that location. A new txt file must be created in this location using the CMDLET below.
New-Item -path $profile -ItemType file –force
Updating the Profile
To place content in the profile, use the CMDLET below to open it:
Invoke-Item $PROFILE
This will bring up an empty notepad document used to store content you want to access. For example, the Get-MoreHelp function show below could be added here. Inside of notepad, type or copy and paste the syntax of that function. It should look something like this:
Function Get-MoreHelp
{$cmdlet = Read-Host “What CMDLET would you like more help on?"
Help $cmdlet -ShowWindow}
To add additional items, simply add them to the list like creating a script in ISE. After adding content, save the document and close PowerShell. To verify that everything is working, relaunch PowerShell and type out Get-More(tab). PowerShell should auto complete the function Get-MoreHelp. Although setting up a profile is not at all necessary, it’s a nice feature to have available!