You can create a PowerShell profile to set your environment (aliases, modules you want to import, functions,etc..)
First of all check if a profile already exists with the command
test-path $profile
This will return true or false. If no profile exists you can create one with the following command:
new-item -type file -path $profile -force
This will create a Microsoft.PowerShell_profile.ps1 file in “%UserProfile%\My Documents\WindowsPowerShell”. The commands you enter in this file will apply to the current user and thePowerShell Shell.
You can now edit this profile with notepad, just type:
notepad $profile
I just entered the command import-module ActiveDirectory, this will automatically load the AD module whenever I start PowerShell.
note:
Their are 4 different profiles in PowerShell:
%windir%\system32\WindowsPowerShell\v1.0\profile.ps1
This profile applies to all users and all shells.
%windir%\system32\WindowsPowerShell\v1.0\ Microsoft.PowerShell_profile.ps1
This profile applies to all users, but only to the Microsoft.PowerShell shell.
%UserProfile%\My Documents\WindowsPowerShell\profile.ps1
This profile applies only to the current user, but affects all shells.
%UserProfile%\My Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
This profile applies only to the current user and the Microsoft.PowerShell shell.
Edit:
I just received some nice scripts from @shayLevy (thx) via Twitter.
Check these out (V2 scripts):
A nicer one
And last but best ![]()








