LoginSignup
4

More than 5 years have passed since last update.

共有しているプロファイルからマシンに依存する部分を独立させる

Last updated at Posted at 2014-07-02

$PROFILEを複数のマシンでGitなどを利用して共有していると、プロファイルに書いておきたいけどマシンに依存するから書くと問題になりそうな部分というのが出てきたりします。

そこで、例えばc:\misc\%ホスト名%.ps1というスクリプトファイルを作成します。
%ホスト名%.ps1の中にマシンに依存するスクリプトを追い出せばプロファイルがすっきりしそうです。

$PROFILEには%ホスト名%.ps1を読み込む下記の内容を追加しておけばOk。

#マシン依存スクリプトの読み込み
$scriptthatdependsonthismachine = "C:\misc\$env:UserDomain.ps1"
if ( Test-Path $scriptthatdependsonthismachine ) {
   . $scriptthatdependsonthismachine
}

これでPowerShell起動時に%ホスト名%.ps1が読み込まれてマシンに依存する部分を独立させることができます。

変数名が長いので使う時は適当に短くしてくだし。
Script that depends on this machine.

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4