다음을 통해 공유


Get-Location

현재 작업 위치 또는 위치 스택에 대한 정보를 가져옵니다.

구문

Get-Location
   [-PSProvider <String[]>]
   [-PSDrive <String[]>]
   [-UseTransaction]
   [<CommonParameters>]
Get-Location
   [-Stack]
   [-StackName <String[]>]
   [-UseTransaction]
   [<CommonParameters>]

Description

Get-Location cmdlet은 pwd(인쇄 작업 디렉터리) 명령과 마찬가지로 현재 디렉터리를 나타내는 개체를 가져옵니다.

Windows PowerShell 드라이브 간에 이동하면 Windows PowerShell은 각 드라이브에 사용자의 위치를 유지합니다. 이 cmdlet을 사용하여 각 드라이브에서 위치를 찾을 수 있습니다.

이 cmdlet을 사용하여 런타임에 현재 디렉터리를 가져와서 Windows PowerShell 프롬프트에서 현재 디렉터리를 표시하는 함수와 같은 함수 및 스크립트에서 사용할 수 있습니다.

이 cmdlet을 사용하여 위치 스택의 위치를 표시할 수도 있습니다. 자세한 내용은 참고 사항 및 StackStackName 매개 변수에 대한 설명을 참조하세요.

예제

예제 1: 현재 드라이브 위치 표시

PS C:\> Get-Location
Path
----
C:\WINDOWS

이 명령은 현재 Windows PowerShell 드라이브의 위치를 표시합니다.

예를 들어 C: 드라이브의 Windows 디렉터리에 있는 경우 해당 디렉터리의 경로가 표시됩니다.

예제 2: 다른 드라이브의 현재 위치 표시

The first command uses the **Set-Location** cmdlet to set the current location to the Windows subdirectory of the C: drive.
PS C:\> Set-Location C:\Windows

The second command uses the **Set-Location** cmdlet to change the location to the HKLM:\Software\Microsoft registry key. When you change to a location in the HKLM: drive, Windows PowerShell retains your location in the C: drive.
PS C:\>
PS C:\WINDOWS> Set-Location HKLM:\Software\Microsoft
PS HKLM:\Software\Microsoft>

The third command uses the **Set-Location** cmdlet to change the location to the HKCU:\Control Panel\Input Method registry key.
PS C:\>
PS HKLM:\Software\Microsoft> Set-Location "HKCU:\Control Panel\Input Method"
PS HKCU:\Control Panel\Input Method>

The fourth command uses the **Get-Location** cmdlet to find the current location on the C: drive. It uses the *PSDrive* parameter to specify the drive.
PS C:\>
PS HKCU:\Control Panel\Input Method> Get-Location -PSDrive C



Path
----
C:\WINDOWS

The fifth command uses the **Set-Location** cmdlet to return to the C: drive. Even though the command does not specify a subdirectory, Windows PowerShell returns you to the saved location.
PS C:\>
PS HKCU:\Control Panel\Input Method> Set-Location C:
PS C:\WINDOWS>

The sixth command uses the **Get-Location** cmdlet to find the current location in the drives supported by the Windows PowerShell registry provider. **Get-Location** returns the location of the most recently accessed registry drive, HKCU.
PS C:\>
PS C:\WINDOWS> Get-Location -PSProvider registry




Path
----
HKCU:\Control Panel\Input Method

To see the current location in the HKLM: drive, you need to use the *PSDrive* parameter to specify the drive. The seventh command does just this:
PS C:\>
PS C:\WINDOWS> Get-Location -PSDrive HKLM



Path
----
HKLM:\Software\Microsoft

이 예제에서는 Get-Location 사용하여 현재 위치를 다른 Windows PowerShell 드라이브에 표시하는 방법을 보여 줍니다.

예제 3: 현재 위치 스택 및 대체 위치 스택의 위치 나열

The first command sets the current location to the Windows directory on the C: drive.
PS C:\> Set-Location C:\Windows

The second command uses the **Push-Location** cmdlet to push the current location (C:\Windows) onto the current location stack and change to the System32 subdirectory. Because no stack is specified, the current location is pushed onto the current location stack. By default, the current location stack is the unnamed default location stack.
C:\WINDOWS> Push-Location System32

The third command uses the *StackName* parameter of the **Push-Location** cmdlet to push the current location (C:\Windows\System32) onto the Stack2 stack and to change the current location to the WindowsPowerShell subirectory. If the Stack2 stack does not exist, **Push-Location** creates it.
C:\Windows\System32> Push-Location WindowsPowerShell -StackName Stack2

The fourth command uses the *Stack* parameter of the **Get-Location** cmdlet to get the locations in the current location stack. By default, the current stack is the unnamed default location stack.
C:\WINDOWS\system32\WindowsPowerShell> Get-Location -Stack
Path
----
C:\WINDOWS

The fifth command uses the *StackName* parameter of the **Get-Location** cmdlet to get the locations in the Stack2 stack.
PS C:\>
C:\WINDOWS\system32\WindowsPowerShell>get-location -stackname Stack2



Path
----
C:\WINDOWS\system32

이 명령은 Get-LocationStackStackName 매개 변수를 사용하여 현재 위치 스택 및 대체 위치 스택의 위치를 나열하는 방법을 보여 줍니다. 위치 스택에 대한 자세한 내용은 노트를 참조하세요.

예제 4: Windows PowerShell 프롬프트 사용자 지정

PS C:\>
function prompt { 'PowerShell: ' + (get-location) + '> '}
PowerShell: C:\WINDOWS>

이 예제에서는 Windows PowerShell 프롬프트를 사용자 지정하는 방법을 보여 줍니다. 프롬프트를 정의하는 함수에는 콘솔에 프롬프트가 나타날 때마다 실행되는 Get-Location 명령이 포함됩니다.

기본 Windows PowerShell 프롬프트의 형식은 프롬프트라는 특수 함수에 의해 정의됩니다. 프롬프트라는 새 함수를 만들어 콘솔에서 프롬프트를 변경할 수 있습니다.

현재 프롬프트 함수를 보려면 다음 명령을 입력합니다. Get-Content Function:prompt

이 명령은 함수 키워드와 함수 이름, 프롬프트로 시작합니다. 함수 본문은 중괄호({}) 내에 나타납니다.

이 명령은 PowerShell 문자열로 시작하는 새 프롬프트를 정의합니다. 현재 위치를 추가하려면 프롬프트 함수가 호출되면 실행되는 Get-Location 명령을 사용합니다. 프롬프트는 문자열 "> "로 끝납니다.

매개 변수

-PSDrive

이 cmdlet이 작업에 가져오는 지정된 Windows PowerShell 드라이브의 현재 위치를 지정합니다.

예를 들어 인증서: 드라이브에 있는 경우 이 매개 변수를 사용하여 C: 드라이브에서 현재 위치를 찾을 수 있습니다.

형식:String[]
Position:Named
Default value:None
필수:False
파이프라인 입력 허용:True
와일드카드 문자 허용:False

-PSProvider

이 cmdlet이 작업에서 가져오는 Windows PowerShell 공급자가 지원하는 드라이브의 현재 위치를 지정합니다.

지정된 공급자가 둘 이상의 드라이브를 지원하는 경우 이 cmdlet은 가장 최근에 액세스한 드라이브의 위치를 반환합니다.

예를 들어 C: 드라이브에 있는 경우 이 매개 변수를 사용하여 Windows PowerShellRegistry 공급자의 드라이브에서 현재 위치를 찾을 수 있습니다.

형식:String[]
Position:Named
Default value:None
필수:False
파이프라인 입력 허용:True
와일드카드 문자 허용:False

-Stack

이 cmdlet은 현재 위치 스택의 위치를 표시합니다.

위치를 다른 위치 스택에 표시하려면 StackName 매개 변수를 사용합니다. 위치 스택에 대한 자세한 내용은 노트를 참조하세요.

형식:SwitchParameter
Position:Named
Default value:None
필수:False
파이프라인 입력 허용:False
와일드카드 문자 허용:False

-StackName

문자열 배열로 명명된 위치 스택을 지정합니다. 하나 이상의 위치 스택 이름을 입력합니다.

현재 위치 스택의 위치를 표시하려면 Stack 매개 변수를 사용합니다. 위치 스택을 현재 위치 스택으로 만들려면 Set-Location 매개 변수를 사용합니다. 위치 스택에 대한 자세한 내용은 노트를 참조하세요.

이 cmdlet은 현재 스택이 아니면 명명되지 않은 기본 스택의 위치를 표시할 수 없습니다.

형식:String[]
Position:Named
Default value:None
필수:False
파이프라인 입력 허용:True
와일드카드 문자 허용:False

-UseTransaction

활성 트랜잭션에 명령을 포함합니다. 이 매개 변수는 트랜잭션이 진행 중인 경우에만 유효합니다. 자세한 내용은 about_Transactions 참조하세요.

형식:SwitchParameter
별칭:usetx
Position:Named
Default value:False
필수:False
파이프라인 입력 허용:False
와일드카드 문자 허용:False

입력

None

이 cmdlet에 입력을 파이프할 수 없습니다.

출력

System.Management.Automation.PathInfo or System.Management.Automation.PathInfoStack

Stack 또는 StackName 매개 변수를 사용하는 경우 이 cmdlet은 StackInfo 개체를 반환합니다. 그렇지 않으면 PathInfo 개체를 반환합니다.

참고

  • 이 cmdlet은 모든 공급자가 노출하는 데이터를 사용하도록 설계되었습니다. 세션의 공급자를 나열하려면 Get-PSProvider입력합니다. 자세한 내용은 about_Providers 참조하세요.

    PSProvider, PSDrive, StackStackName 매개 변수가 상호 작용하는 방법은 공급자에 따라 달라집니다. 드라이브와 해당 드라이브를 노출하지 않는 공급자를 모두 지정하는 등의 일부 조합으로 인해 오류가 발생합니다. 매개 변수를 지정하지 않으면 이 cmdlet은 현재 작업 위치를 포함하는 공급자에 대한 PathInfo 개체를 반환합니다.

    스택은 가장 최근에 추가된 항목만 액세스할 수 있는 마지막 첫 번째 목록입니다. 항목을 사용하는 순서대로 스택에 추가한 다음 역순으로 사용할 항목을 검색합니다. Windows PowerShell을 사용하면 공급자 위치를 위치 스택에 저장할 수 있습니다. Windows PowerShell은 명명되지 않은 기본 위치 스택을 만들고 여러 명명된 위치 스택을 만들 수 있습니다. 스택 이름을 지정하지 않으면 Windows PowerShell에서 현재 위치 스택을 사용합니다. 기본적으로 명명되지 않은 기본 위치는 현재 위치 스택이지만 Set-Location cmdlet을 사용하여 현재 위치 스택을 변경할 수 있습니다.

    위치 스택을 관리하려면 다음과 같이 Windows PowerShellLocation cmdlet을 사용합니다.

    • 위치 스택에 위치를 추가하려면 Push-Location cmdlet을 사용합니다.

    • 위치 스택에서 위치를 얻으려면 Pop-Location cmdlet을 사용합니다.

    • 현재 위치 스택의 위치를 표시하려면 Get-Location cmdlet의 Stack 매개 변수를 사용합니다. 명명된 위치 스택에 위치를 표시하려면 Get-Location cmdlet의 StackName 매개 변수를 사용합니다.

    • 새 위치 스택을 만들려면 Push-Location cmdlet의 StackName 매개 변수를 사용합니다. 존재하지 않는 스택을 지정하면 밀어넣기 위치 스택이 만들어집니다.

    • 위치 스택을 현재 위치 스택으로 만들려면 Set-Location cmdlet의 StackName 매개 변수를 사용합니다.

    명명되지 않은 기본 위치 스택은 현재 위치 스택인 경우에만 완전히 액세스할 수 있습니다. 명명된 위치 스택을 현재 위치 스택으로 만드는 경우 더 이상 Push-Location 사용하거나 기본 스택에서 항목을 추가하거나 가져오거나 이 cmdlet 명령을 사용하여 명명되지 않은 스택의 위치를 표시할 pop-Location을 수 없습니다. 명명되지 않은 스택을 현재 스택으로 만들려면 Set-Location cmdlet의 StackName 매개 변수를 $null 값 또는 빈 문자열("")과 함께 사용합니다.