Link to home
Start Free TrialLog in
Avatar of c7c4c7
c7c4c7Flag for United States of America

asked on

How Do I implement multiple powershell profiles

I want to be able to use a powershell profile while I am testing and developing scripts.  
When I am satisfied with the scripts I move them to another directory.  
I want the same machine to use only those scripts in that 2nd directory when it runs throughout the day.

I assume that using different profiles is the way to go, but I don't know how to implement it.  If there is a better way of doing it I'm open to that, using another machine is not acceptable.

Thanks
Avatar of Chris Dent
Chris Dent
Flag of United Kingdom of Great Britain and Northern Ireland image

You could set-up short-cuts (aliases, or any other method you like) to open PowerShell with specific profiles by dot-sourcing scripts:
powershell.exe -command ". C:\DevProfile.ps1" -NoProfile

Open in new window

That'll load your DevProfile script, but won't load the default profile scripts.

Chris
Avatar of c7c4c7

ASKER

So if I start script "a" with . \ and a specific path I get exactly what I need but then if script "a" calls "script b" would I then have to place the call in "a" with a specific path to "b"?
ASKER CERTIFIED SOLUTION
Avatar of Chris Dent
Chris Dent
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry, I failed to address the A and B thing. Ultimately it depends entirely on what you want to happen (and what script B does).

If script A is dot-sourced, and script B is not then script B would execute in the same manner as if you called it from the console (c:\scripts\scriptb.ps1). Variables and functions declared within script B would have Script scope (and be inaccessible outside). Conversely, variables and functions in script A would have Global scope.

Dot-sourcing is a useful method for executing scripts as if you'd typed it directly into the console. You get something like the same effect when you use Import-Module, although it's use is a bit more specialised.

Dot-sourcing is used (in the background) to execute the default profile scripts exposed in the $PROFILE reserved variable ($PROFILE | Select-Object *).

Chris