Guy recommends :
Free Solarwinds
VM Console

Solarwinds VM Console Free Download

Find out which of your VMs are a waste of space and which VMs need more resources.



PowerShell Scripting  - Profile.ps1

Introduction to PowerShell's Profile.ps1

DOS old timers may remember AutoExec.bat and Config.sys.  More modern Microsoft operating systems need boot.ini; all these files control the startup environment.  Well the purpose of this page is to configure the equivalent PowerShell file: profile.ps1.

PowerShell Profile.ps1 Topics

 ♣

Setting up PowerShell's Profile.ps1

Profile.ps1 location
The key to getting started is to make sure that profile.ps1 is in the correct path.

C:\Documents and Settings\All Users\Documents\PSConfiguration\profiles.ps1
alternatively
C:\Documents and Settings\%username%\Documents\PSConfiguration\profiles.ps1

Registry Setting for Scripts e.g. Profile.ps1
HKLM\Software\Microsoft\PSConfiguration\1\ShellIds \Microsoft.Management.Automation.ps1

Change the REG_SZ ExecutionPolicy from Restricted to UNRestricted or RemoteSigned (RemoteSigned as the name suggests, means that scripts from the internet must have digital certificates, however scripts on the localhost run without restriction.)  For more details of setting up profile.ps1 in the \PSConfiguration folder see here.

Customising Profile.ps1

The principle behind profile.ps1 and other cmdlets with a msh extension is to save keystrokes into a file for reuse later.  Once you have absorbed the concept then you can truly customize your profile.ps1, merely look at examples for ideas and then adapt the most promising to set your PowerShell environment.

Working Directory.
My first task was to change the working directory from My Documents..\..\. to
D:\ scripts.  I typed set-location d:\ scripts in the Microsoft Shell - it worked.  Then I put the very same commands in profile.ps1.  At first PowerShell did not executed this instruction when it launched, this was because profile.ps1 was in the wrong folder.

Aliases
If you want to create Aliases that last for more than one session, then add them to your profile.ps1.  Experiment at the PowerShell command prompt with set-alias aliasname verb-noun pair.  When your alias works perfectly save the command into profile.ps1.  Example: set-alias xcopy. 

PowerShell Module Directory
It is possible to create the special module folder.

Guy Recommends:  Solarwinds' Free Bulk Import ToolFree Download of Solarwinds  Bulk Import Tool

Import users from a spreadsheet.  Just provide a list of the users with their fields in the top row, and save as .csv file.  Then launch this FREE utility and match your fields with AD's attributes, click to import the users.  Optionally, you can provide the name of the OU where the new accounts will be born.

There are also two bonus tools in this free download, and all 3 have been approved by Microsoft:

  1. Bulk-import new users into Active Directory.
  2. Seek and zap unwanted user accounts.
  3. Find inactive computers.

Download your FREE bulk import tool.

Summary of Profile.ps1

In PowerShell RC1, profiles.ps1 does not appear in the correct folder.  After you hack the registry key called ExecutionPolicy, then you can create the msh folder in the All Users\documents.  Finally, you can add instructions to the profiles.ps1 file.

If you like this page then please share it with your friends

 


See more Microsoft PowerShell tutorials

PowerShell Tutorials  • Methods  • Cmdlets  • PS Snapin  • Profile.ps1  • Exchange 2007

Command & Expression Mode  • PowerShell pipeline (|)  • PowerShell 'where'  • PowerShell 'Sort'

If you see an error of any kind, do let me know.  Please report any factual mistakes, grammatical errors or broken links, I will be happy to not only to correct the fault, but also to give you credit.

 *


Custom Search

Guy Recommends: WMI Monitor and It's Free!Solarwinds WMI Monitor

Windows Management Instrumentation (WMI) is one of the hidden treasures of Microsoft operating systems.

Fortunately, Solarwinds have created the Free WMI Monitor so that you can actually see and understand these gems of performance information.  Take the guess work out of which WMI counters to use for applications like Microsoft Active Directory, SQL or Exchange Server.

Download your free copy of WMI Monitor

 

Home Copyright © 1999-2012 Computer Performance LTD All rights reserved

Please report a broken link, or an error.