If you are using PowerShell frequently you might want to change some default settings to modify your PowerShell window. We can do this by creating a PowerShell Profile where you can add Alias for function you use a lot, load modules at startup, change the root directory or add path variables.
First we need to check if the Profile file already exists
1. #returns false if it not exists 2. test-path $profile
If the file does not exists, we create it with the the following command
1. New-Item -path $profile -type file –force
The file will be created in the Directory location. Open the file with notepad to start creating your profile.
What can we add to the profile?
Some basic stuff, like the default root location, clearing the screen when loaded or changing some colors:
1. set-location c: 2. 3. $shell = $Host.UI.RawUI 4. 5. $shell.WindowTitle= "PS" 6. 7. $shell.BackgroundColor = "Black" 8. $shell.ForegroundColor = "White"
PATH variable
But more useful is adding folders to you PATH variable. This way you can easily use your scripts, modules or connector scripts that you might have. I keep some of those script in my dropbox folder. You can add them with the following command
1. $env:Path += ";C:\Users\<user>\Dropbox\SysAdminScripts\Connectors"
If I need to connect to Exchange Online for example, I can just type ConnectTo-Exchange and the connector script will run.
Aliases
Many PowerShell cmdlets have aliases, but you might want to create an alias for one of you own scripts or existing cmdlets. For example, if you use the import-module a lot, the following alias would be useful
1. Set-Alias im Import-Module