UPDATE 20131028: Added snap-in registration
I thought it would be nice to share my PowerShell profile settings as a starter for new users. It’s rather basic, I only added a few things to make my PowerShell console ready from the start. But first some easy tips to check and if needed create a profile.
Test if you have a PowerShell Profile. Start Powershell and type:
Test-Path $PROFILE
If the result is “False” you don’t have a PowerShell profile. Let’s create one:
New-Item -Path $PROFILE -Type File -Force
This will create an empty profile. Now we can edit the profile file:
Notepad $PROFILE
In this profile I’ve put in the following things:
- If I’m working as an administrator, I changed the forground color to red to see the difference.
- I use Dropbox as my central script repository. So I made sure that the start location is my Dropbox directory.
- I also created a Dropbox drive as an easy entry.
- Error messages set to green. Like Don Jones, I prefer green. It’s not a error, but a learning experience.
- Two function to connect and disconnect to Exchange Onlline (Office 365), Of course you need to install the MSOnline PowerShell module.
- I added a command to register snap-ins for like Exchange 2007 or Quest PowerShell Commands for AD
This is my Profile:
# Change Elevated PowerShell Console Colors if ($Host.UI.RawUI.WindowTitle -like "Administrator:*") {$Host.UI.RawUI.ForegroundColor = "Red"} else {$Host.UI.RawUI.ForegroundColor = "White"}
# Set Dropbox as default script location and create Dropbox drive $WshShell = New-Object -ComObject WScript.Shell $dropboxpath = $WshShell.CreateShortcut("$env:userprofile\Links\Dropbox.lnk").TargetPath New-PSDrive -name Dropbox -PSProvider FileSystem -Root $dropboxpath | out-null Set-Location "Dropbox:\Powershell"
# Change ErrorForegroundColor to Green - it's not an error but a learning experience (Don Jones) and I agree $privdata = (Get-Host).PrivateData $privdata.ErrorForegroundColor = "Green"
# Function - Exchange Online Connect function Connect-ExchangeOnline { $LiveCred = Get-Credential $global:Session365 = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $LiveCred -Authentication Basic -AllowRedirection Import-PSSession $global:Session365 } # Function - Exchange Online Disconnect function Disconnect-ExchangeOnline { Remove-PSSession $global:Session365 } #Register Snapins pssnapin -Registered | Add-PSSnapin
When you start a PowerShell prompt and you get a message that running scripts is disabled type:
Set-ExecutionPolicy RemoteSigned
A last note, this will not work with Windows RT.