?
Solved

How Do I implement multiple powershell profiles

Posted on 2014-09-11
4
Medium Priority
?
162 Views
Last Modified: 2014-09-14
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
0
Comment
Question by:c7c4c7
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 71

Expert Comment

by:Chris Dent
ID: 40320589
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
0
 

Author Comment

by:c7c4c7
ID: 40321279
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"?
0
 
LVL 71

Accepted Solution

by:
Chris Dent earned 2000 total points
ID: 40321487
It's this you want:
. <PathToScript>

Open in new window

If the script were in the current directory it would be:
. .\Script.ps1

Open in new window

An absolute path may be specified in a similar manner:
. c:\somewhere\scripts\script.ps1

Open in new window

The existing profile scripts execute in a similar manner (dot-sourced, and therefore execute in global context), so if you want substitution and choice of profiles then this is one way to do it.

There are a myriad of different ways to end up running that particular profile script. From menu-driven options, to short-cuts, to starting PowerShell using a function, etc, etc. The important thing is to find out whether or not this offers you the separation you want.

Chris
0
 
LVL 71

Expert Comment

by:Chris Dent
ID: 40321491
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
0

Featured Post

Bringing Advanced Authentication to the SMB Market

WatchGuard announces the acquisition of advanced authentication provider, Datablink, with one mission – to bring secure authentication to SMB, mid-market, and distributed enterprises with a cloud-based solution, ideal for resale via their established channel & MSSP community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windows 10 came with  a lot of built in applications, Some organisations leave them there, some will control them using GPO's. This Article is useful for those who do not want to have any applications in their image (example:me).
The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question