どのように再読み込みユーザープロファイルからスクリプトファイルをユー
-
05-09-2019 - |
質問
たいブログのユーザープロファイルのスクリプトファイルです。と思ったことをドソーシングからのスクリプトファイルのようだというのが動作していません:
# file.ps1
. $PROFILE
してみることはできなかったが、作業場ドソースからユーの通訳です。
なぜってみたいと思います。
私はこのスクリプト時には毎回更新プロフィールとしてテストを行いたいので、たいと思っている必要性を回避するために再スターユーリフレッシュします。
解決
そのアプローチとしての答えは、Powershellコマンドプロンプトで動作しない内部にユー伊勢る労働者とコルホーズの女性像とオスの優れたユーセッション)ん作権その他のユー環境です。
こちらはスクリプトでしたのではないかともいわれてい利用が期間で決済されるものであるためにも私にとって毎に環境です。私は簡単に言うとこの機能にいてあります。ps1~\Documents\WindowsPowerShell、また更新プロフィール、ドット-ソースの機能、すなわち
. Reload-Profile
この機能:
function Reload-Profile {
@(
$Profile.AllUsersAllHosts,
$Profile.AllUsersCurrentHost,
$Profile.CurrentUserAllHosts,
$Profile.CurrentUserCurrentHost
) | % {
if(Test-Path $_){
Write-Verbose "Running $_"
. $_
}
}
}
他のヒント
たい場合には世界的にリフレッシュプロファイルからスクリプトまたは施設まで格安料金プランをスクリプト"ドットを使った".
実際のスクリプト、プロファイルのスクリプト実行スクリプト"の範囲及び変更しませんが"グローバル"です。
るためには、スクリプトを修正すグローバル範囲で必要となる"ドット-ソース"や先と。
. ./yourrestartscript.ps1
がんプロフィールスクリプト"ドット-調達"内の"yourrestartscript.ps1".だが実際にやってはい"yourrestartscript"行の電流範囲内部スクリプトは、ほとんどの$プスクリプトが実行スクリプトのです。以降、スクリプトの範囲は、グローバル範囲は、変数の設定コマンドプロファイルが起こる世界です。
な購入できますか走
. $profile
& $profile
作品の再読み込みます。
場合のプロフィールエイリアスを設定した実行輸入に失敗すると誤って設定されている前の読み込みます。
なぜなっている。
では重複(追加しますが$env:パス)問題設定/読み取り専用オブジェ不具合を起こす.
あのスレッドがこの課題に、最近の microsoft.ます。windowsの場合です。powershell.
合しようとしているリセットの状態セッションを制限することはないと思うこともに、内側の範囲($host.EnterNestedPrompt()
で設定する機能を変数/エイリアス/...で、"すべての範囲を".
この回避策:
#some-script.ps1
#restart profile (open new powershell session)
cmd.exe /c start powershell.exe -c { Set-Location $PWD } -NoExit
Stop-Process -Id $PID
より凝バージョン:
#publish.ps1
# Copy profile files to PowerShell user profile folder and restart PowerShell
# to reflect changes. Try to start from .lnk in the Start Menu or
# fallback to cmd.exe.
# We try the .lnk first because it can have environmental data attached
# to it like fonts, colors, etc.
[System.Reflection.Assembly]::LoadWithPartialName("System.Diagnostics")
$dest = Split-Path $PROFILE -Parent
Copy-Item "*.ps1" $dest -Confirm -Exclude "publish.ps1"
# 1) Get .lnk to PowerShell
# Locale's Start Menu name?...
$SM = [System.Environment+SpecialFolder]::StartMenu
$CurrentUserStartMenuPath = $([System.Environment]::GetFolderPath($SM))
$StartMenuName = Split-Path $CurrentUserStartMenuPath -Leaf
# Common Start Menu path?...
$CAD = [System.Environment+SpecialFolder]::CommonApplicationData
$allUsersPath = Split-Path $([System.Environment]::GetFolderPath($CAD)) -Parent
$AllUsersStartMenuPath = Join-Path $allUsersPath $StartMenuName
$PSLnkPath = @(Get-ChildItem $AllUsersStartMenuPath, $CurrentUserStartMenuPath `
-Recurse -Include "Windows PowerShell.lnk")
# 2) Restart...
# Is PowerShell available in PATH?
if ( Get-Command "powershell.exe" -ErrorAction SilentlyContinue ) {
if ($PSLnkPath) {
$pi = New-Object "System.Diagnostics.ProcessStartInfo"
$pi.FileName = $PSLnkPath[0]
$pi.UseShellExecute = $true
# See "powershell -help" for info on -Command
$pi.Arguments = "-NoExit -Command Set-Location $PWD"
[System.Diagnostics.Process]::Start($pi)
}
else {
# See "powershell -help" for info on -Command
cmd.exe /c start powershell.exe -Command { Set-Location $PWD } -NoExit
}
}
else {
Write-Host -ForegroundColor RED "Powershell not available in PATH."
}
# Let's clean up after ourselves...
Stop-Process -Id $PID
これは精製のラインスクリプトguillermoooの答えは、このような、新しいユー画面のディレクトリだった。すると思いますので$PWDを評価し、新たなユーウィンドウの右クリックではない値にしたい設定の場所です。
function Restart-Ps {
$cline = "`"/c start powershell.exe -noexit -c `"Set-Location '{0}'" -f $PWD.path
cmd $cline
Stop-Process -Id $PID
}
による権利はずがないとしての機能も担うこととし、コマンドラインで吐出は不正もしているように思える仕事が良くあります。
このためトラブルシューティングかプロファイルをいつまでも負荷時のものです。
開始。
powershell_ise -noprofile
その後行ったこ
function Reload-Profile {
@(
$Profile.AllUsersAllHosts,
$Profile.AllUsersCurrentHost,
$Profile.CurrentUserAllHosts,
$Profile.CurrentUserCurrentHost
) | % {
if(Test-Path $_){
Write-Verbose "Running $_"
$measure = Measure-Command {. $_}
"$($measure.TotalSeconds) for $_"
}
}
}
. Reload-Profile
ま@ウィンストンFassettくいう私の課題です。
以来、私をここ数年後、私は考えることができたことを付記する。使用でき、呼び出しオペレーター: &
ロープロファイル、デフォルトの変数のプロフィール: $profile
.
そのため、セッションなんだかに失敗した負荷プロファイル(がっcmder/conemu)タイプ:
& $profile