PowerShell 기본 디렉토리를 설정하는 방법은 무엇입니까?
Powershell의 기본 위치를 변경하는 방법이 있습니까?
Powershell의 기본 작업 디렉터리를 어떻게 설정합니까?
PowerShell을 시작할 때 열 디렉터리를 지정할 수 있습니다.
powershell.exe -NoExit -command "& {Set-Location $env:systemroot}"
바로 가기에서 사용하십시오.
또는 프로필 을 사용하여 시작 디렉터리를 설정합니다.
PowerShell 프로필을 만듭니다 .
관리자 권한으로 powershell을 실행하고 다음 명령을 실행합니다.
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
이렇게하면 PowerShell이 로컬 스크립트와 서명 된 인터넷에서 다운로드 한 스크립트를 실행할 수 있습니다. 이 명령에 대한 자세한 내용은 설명서를 참조하십시오 .
당신에
Documents
폴더라는 디렉토리를 찾을 수 있습니다WindowsPowerShell
. 존재하지 않으면 괜찮습니다. 그냥 만드십시오.- 라는 새 파일 만들기
profile.ps1
에WindowsPowerShell
폴더를. profile.ps1
다음 명령을 열고 추가하여 기본 작업 디렉토리를 설정하십시오.Set-Location C:\my\default\working\directory
새 powershell 창을 엽니 다 ... 변경 사항이 적용되어야합니다.
나는 서버 2016에서 위의 답변을 성공하지 못했습니다.
그러나 나는이 접근 방식 (Windows 10에서도 동일해야 함)이 저에게 효과적이라는 것을 알았습니다.
- Powershell 시작
- 작업 표시 줄에서 마우스 오른쪽 버튼을 클릭하고 고정하여 링크를 유지합니다.
- 작업 표시 줄의 아이콘을 다시 마우스 오른쪽 단추로 클릭 한 다음 Windows PowerShell 을 마우스 오른쪽 단추로 클릭 하고 속성을 선택합니다.
- 시작 위치 : 입력 필드 에 원하는 디렉토리를 입력하고 확인을 누릅니다.
- 작업 표시 줄 아이콘에서 시작
끝난!
동일한 속성 대화 상자에서 글꼴, 색상, 크기와 같은 다른 많은 설정을 변경할 수도 있으며 고급 버튼을 통해 바로 가기 탭 에서 해당 Powershell을 관리자 권한으로 실행할지 여부를 선택할 수 있습니다.
기본 디렉토리를 설정하는 더 쉬운 방법은 다음과 같습니다.
- Windows Powershell 아이콘을 마우스 오른쪽 단추로 클릭하고 시작에 고정하십시오.
- 시작에서 Windows Powershell 아이콘을 마우스 오른쪽 단추로 클릭 한 다음 Windows Powershell을 다시 마우스 오른쪽 단추로 클릭하고 속성 (Windows Powershell ISE가 아닌 관리자 권한으로 실행이 아님)을 선택합니다.
- 바로 가기 탭-> '시작 위치'필드에서 Powershell을 시작할 위치로 변경하십시오.
Set-Location
프로필에 넣으면 현재 작업 디렉터리가 무조건 변경되어 "powershell로 실행"을 통해 실행하는 스크립트의 작업 디렉터리와 관련하여 원치 않는 결과를 초래할 수 있습니다.
대체 솔루션은 .lnk
파일 의 작업 디렉토리를 일반적으로 %USERPROFILE%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Windows PowerShell
. 링크를 마우스 오른쪽 버튼으로 클릭하여 작업 %HOMEDRIVE%%HOMEPATH%
디렉토리를 원하는 디렉토리로 변경하십시오 .
위에서 언급 한대로 무조건 작업 디렉터리를 변경하는 대신 function
powershell 프로필에 간단한 내용 을 작성하여 set-location
필요할 때마다 작업 디렉터리를 빠르게 변경할 수 있습니다.
powershell 프로필을 생성 / 수정하려면 위의 답변 을 확인하십시오 .
powershell 프로필에 기능 추가 :
function goto_this {set-location 'your\path\to\some\dir'}
function goto_that {set-location 'your\path to some\dir with space'}
Just change the function name and directory pointed to. Using quotes on the path is mandatory if its contains spaces. I try to keep the prefix goto_
as it helps in remembering the functions' names.
You can start typing goto_
then press TAB to cycle through all the added functions (remember to start a new powershell window after adding/modifying functions).
Using just command line, if file exists already it will append to it
$(if (-Not (Test-Path ~\Documents\WindowsPowerShell\)){ mkdir ~\Documents\WindowsPowerShell\}) ; echo "Set-Location c:\THELOCATIONYOUWANT" >> ~\Documents\WindowsPowerShell\profile.ps1
I get that this is old, and this is a bit nit-picky. But, I feel it's better for everyone to have all the knowledge possible.
With that, there seems to be some confusion on "Working Directory" and PowerShell's "Location". What most people here are doing, and saying to do is change PowerShell's "Location". The "Working Directory" is actually different. Here is a link that explains it.
For those who don't want to read the link: Open PowerShell and use what others have said to do Set-Location "C:\some\directory"
notice that your "working directory" is still where your PS was opened at. Either "~"
or "%SYSTEMROOT%\system32"
depending on if you ran as Admin or not. To check working directory use [Environment]::CurrentDirectory
note: in the article he says to check the "Working Directory" by using this command
\[Environment\]::CurrentDirectory
. Not sure if this works with older PS versions, but with PS 5+ you have to use [Environment]::CurrentDirectory
파워 쉘에 이것을 입력하십시오. New-Item -path $ profile -type file –force 파워 쉘 폴더에 ps1 파일을 생성하고 다음과 같이 열고 편집하십시오.
Set-location c:\files
끝난
이 링크를 참조하십시오. https://www.ntweekly.com/2016/03/21/change-powershell-start-directory/ 잘 작동합니다.
참고 URL : https://stackoverflow.com/questions/32069265/how-to-set-powershell-default-directory
'developer tip' 카테고리의 다른 글
Xcode 버전 4.6.2 (4H1003) 컴파일러 오류 (0) | 2020.09.13 |
---|---|
Carrierwave를 사용한 Rails 4 다중 이미지 또는 파일 업로드 (0) | 2020.09.13 |
프로그래밍 방식으로 탐색 모음에 단추 추가 (0) | 2020.09.13 |
왜 printf ( "% f", 0); (0) | 2020.09.13 |
"."는 어떻게 사용합니까? (0) | 2020.09.13 |