programing

Powershell 경로에 일시적으로 추가

sourcejob 2023. 8. 12. 10:14
반응형

Powershell 경로에 일시적으로 추가

Visual Studio ASPNET Core 1 프로젝트를 배포하기 위해 간단한 PowerShell 스크립트를 작성하려고 합니다.

현재, 나는 배치 파일에서 말할 수 있습니다.

Path=.\node_modules\.bin;%AppData%\npm;C:\Program Files (x86)\Microsoft Visual Studio 14.0\Web\External;%PATH%;C:\Program Files (x86)\Microsoft Visual Studio 14.0\Web\External\git

그러면 세션 기간 동안 경로 변수가 수정됩니다.아무리 생각해도 파워셸에서 이 간단한 일을 어떻게 하는지 모르겠어요.

누가 이걸 파워셸로 번역하는 걸 도와줄 수 있나요?

TIA!

옵션 1: 수정$env:Path변수

  1. 에 추가Path현재 창의 변수:

    $env:Path += ";C:\New directory 1;C:\New directory 2"
    
  2. 접두사:Path현재 창의 변수:

    $env:Path = "C:\New directory 1;C:\New directory 2;" + $env:Path
    
  3. 교체합니다.Path현재 창의 변수(주의하여 사용!):

    $env:Path = "C:\New directory 1;C:\New directory 2"
    

옵션 2: 사용editenv효용.

환경 변수의 내용을 대화형으로 편집할 수 있는 윈도우즈 명령줄 도구를 만들었습니다.Windows 콘솔(특히 PowerShell ISE에서는 작동하지 않음)에서 작동합니다.

editenv Path

이것은 당신이 당신의 디렉토리를 편집하고 재정렬하고 싶을 때 유용할 수 있습니다.Path보다 상호 작용적인 방식으로 현재 창에만 영향을 미칩니다.

그냥 사용할 수 있습니다.$env:Path하지만 그것이 충분히 명시적이지 않은 것이 걱정된다면, 다음을 사용할 수 있습니다.

[System.Environment]::SetEnvironmentVariable('Path',$Value,[System.EnvironmentVariableTarget]::Process);

GetEnvironmentVariable()은 다음을 명시적으로 검색할 수 있습니다.

[System.Environment]::GetEnvironmentVariable('Path',[System.EnvironmentVariableTarget]::Process);
[System.Environment]::GetEnvironmentVariable('Path',[System.EnvironmentVariableTarget]::Machine);
[System.Environment]::GetEnvironmentVariable('Path',[System.EnvironmentVariableTarget]::User);

언급URL : https://stackoverflow.com/questions/37663602/powershell-add-to-path-temporarily

반응형