3

I want to have several (more than one) PowerShell profiles which will create different environments.

More specifically I need way for start separate PowerShell ISE for work with TFS and other PowerShell ISE instance for regular work. 'TFS' environment require loading some additional snappins, modules, modify prompt and so on. I do not want all this stuff will be executed for regular PowerShell ISE sessions but only when I want to.

I found that I can automatically load arbitrary script through command line parameter -File, but it does not executed automatically..

Sergey Azarkevich
  • 2,641
  • 2
  • 22
  • 38
  • If you want multiple ISE profiles could you not make your own modules to import into the different sessions? – Matt Jun 24 '15 at 11:40
  • Yes, I want load modules into one session (TFS Work) and not load them into other session (Usual Work). And I want that it will be executed automatically by clicking on different shortcuts on Desktop – Sergey Azarkevich Jun 24 '15 at 11:46
  • Based on the last sentence in your question does that mean you already tried to make shortcuts for `PowerShell_Ise ` where `` is a path to your own module or script that would load TFS for you? Or does TFS already load automatically? – Matt Jun 24 '15 at 11:52
  • 2
    One possible way is to set an environment variable before starting ISE (e.g. in a batch file `set ISE_CONFIG=... & powershell_ise.exe`). Then in a profile check its value and configure the current session accordingly. – Roman Kuzmin Jun 24 '15 at 12:00
  • Matt, I try `\PowerShell_Ise.exe ` but this command open script, but does not execute and close it automatically. – Sergey Azarkevich Jun 24 '15 at 12:01
  • Roman Kuzmin, thanks, good idea. – Sergey Azarkevich Jun 24 '15 at 12:02
  • I still think `` should work but if you only have these 2 settings then you could still set the profile and then have a shortcut with the `-NoProfile` which would ignore the profile you created. – Matt Jun 24 '15 at 12:26

2 Answers2

5

I do it by creating a shortcut for PowerShell ISE with a default directory :

ISE PowerShell ShortCut here

In the default Directory (here called D:\TFS) I create a .PS1 file called local_profile.ps1.

In the beginning of the current profile file (C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1) I add :

# Try to load local profile
Get-ChildItem "local_profile.ps1" -ErrorAction SilentlyContinue | %{.$_}

You just have to add your initialization code to D:\TFS\local_profile.ps1.

noctonura
  • 12,763
  • 10
  • 52
  • 85
JPBlanc
  • 70,406
  • 17
  • 130
  • 175
1

powershell ISE has a profile too.

Probably is something like: E:\Users\UserName\Documents\WindowsPowerShell\Microsoft.PowerShellISE_profile.ps1

Or you can open powershell ise and look at $profile variable.

After locate your profile file, write your modules import and custom scripts in it.

wallybh
  • 934
  • 1
  • 11
  • 28
  • Of course it has, but I want to execute different profiles for different situations. Start PoserShell ISE for 'normal' using should not load TFS modules. – Sergey Azarkevich Jun 24 '15 at 11:29