开发者

Managing profiles in Powershell 2.0

as far as I understand, powershell has one profile per user. I would like to prepare multiple environments for different "hats" I could put on my head. Like start my "database worker shell" which provides a set of shortcuts for working with special databases开发者_运维问答. Later I would start an environment which might be my "data processing shell" that provides other shortcuts.

What's the best way to manage that?

cheers, Achim


I believe there are quite a number of ways and “the best one” depends on many not explained factors. One not best but kind of straightforward way is the following.

Profiles are just scripts automatically dot-sourced in the global scope on start-up. In some sense we can call any script that is dot-sourced in the global scope later “a dynamic profile”. We can have several scripts that install global variables, functions, aliases and etc. with the same names but different values. In other words, we can have several scripts that install different “environments”. At any moment we take one and do:

. Set-Environment<SomeName>.ps1

and continue work with new environment SomeName. More or less, I use the approach like this in practice (exactly when working with databases, BTW).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜