My Profile Settings


Thought I’d share what I like to put in my Powershell profile(s).

$isadmin = ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator')
if($isadmin)
{ $adminString = 'Administrator'}
else
{ $adminString = 'NotAdmin'}

I use the following to change the title of my window to indicate whether I’ve launched with Admin or not.

New-PSDrive -Name PS -PSProvider FileSystem -Root C:\Powershell

I use the new-psdrive commandlet so i can just change to my scripts location with PS:

$credsFile = 'c:\cred.txt'
$cred = Get-Content $credsFile | ConvertTo-SecureString
$credentials = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList 'mydomain\thom', $cred

Since I need to use my credenitals with other commandlets I just create a Credentials object so I can use it later with those commandlets.

$Host.UI.RawUI.WindowTitle = "Windows PowerShell $([String]$host.version) ($(whoami)) $adminString"

Now I put it all together by changing the title bar of my current session.  So I know what version I’m running of powershell and if I launched as admin or not admin.

Full Script:

$isadmin = ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator')
if($isadmin)
{ $adminString = 'Administrator'}
else
{ $adminString = 'NotAdmin'}
New-PSDrive -Name PS -PSProvider FileSystem -Root C:\Powershell
$credsFile = 'c:\cred.txt'
$cred = Get-Content $credsFile | ConvertTo-SecureString
$credentials = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList 'mydomain\thom', $cred
$Host.UI.RawUI.WindowTitle = "Windows PowerShell $([String]$host.version) ($(whoami)) $adminString"

In addition I add TabExpansion++ to my profile.  See this article for more information:

Auto-Complete .NET Constructor Params

until then keep scripting

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s