Share via


PowerShell 드라이브 관리

이 샘플은 Windows 플랫폼에만 적용됩니다.

PowerShell 드라이브는 PowerShell의 파일 시스템 드라이브처럼 액세스할 수 있는 데이터 저장소 위치입니다. PowerShell 공급자가 파일 시스템 드라이브(C:D: 포함), 레지스트리 드라이브(HKCU:HKLM:), 인증서 드라이브(Cert:) 등과 같은 일부 드라이브를 만들고, 사용자는 자신의 PowerShell 드라이브를 만들 수 있습니다. 이러한 드라이브는 유용하지만 PowerShell 내에서만 사용할 수 있습니다. 파일 탐색기 또는 Cmd.exe 등과 같은 다른 Windows 도구를 사용하여 이 드라이브에 액세스할 수 없습니다.

PowerShell은 PowerShell 드라이브 작업을 위한 명령에 명사 PSDrive를 사용합니다. PowerShell 세션의 PowerShell 드라이브 목록을 보려면 Get-PSDrive cmdlet을 사용합니다.

Get-PSDrive
Name       Provider      Root                                   CurrentLocation
----       --------      ----                                   ---------------
A          FileSystem    A:\
Alias      Alias
C          FileSystem    C:\                                 ...And Settings\me
cert       Certificate   \
D          FileSystem    D:\
Env        Environment
Function   Function
HKCU       Registry      HKEY_CURRENT_USER
HKLM       Registry      HKEY_LOCAL_MACHINE
Variable   Variable

디스플레이의 드라이브는 시스템의 드라이브에 따라 다르지만 위에 표시된 명령의 Get-PSDrive 출력과 유사하게 표시됩니다.

파일 시스템 드라이브는 PowerShell 드라이브의 하위 집합입니다. 공급자 열의 FileSystem 항목으로 파일 시스템 드라이브를 식별할 수 있습니다. PowerShell의 파일 시스템 드라이브는 PowerShell FileSystem 공급자에서 지원됩니다.

cmdlet의 구문을 Get-PSDrive 보려면 구문 매개 변수를 사용하여 Get-Command명령을 입력합니다.

Get-Command -Name Get-PSDrive -Syntax
Get-PSDrive [[-Name] <String[]>] [-Scope <String>] [-PSProvider <String[]>] [-V
erbose] [-Debug] [-ErrorAction <ActionPreference>] [-ErrorVariable <String>] [-
OutVariable <String>] [-OutBuffer <Int32>]

PSProvider 매개 변수를 사용하면 특정 공급자가 지원하는 PowerShell 드라이브만 표시할 수 있습니다. 예를 들어 PowerShell FileSystem 공급자가 지원하는 PowerShell 드라이브만 표시하려면 Get-PSDrive 명령을 PSProvider 매개 변수 및 FileSystem 값과 함께 입력합니다.

Get-PSDrive -PSProvider FileSystem
Name       Provider      Root                                   CurrentLocation
----       --------      ----                                   ---------------
A          FileSystem    A:\
C          FileSystem    C:\                           ...nd Settings\PowerUser
D          FileSystem    D:\

레지스트리 하이브를 나타내는 PowerShell 드라이브를 보려면 PSProvider 매개 변수를 사용하여 PowerShell 레지스트리 공급자가 지원하는 PowerShell 드라이브만 표시합니다.

Get-PSDrive -PSProvider Registry
Name       Provider      Root                                   CurrentLocation
----       --------      ----                                   ---------------
HKCU       Registry      HKEY_CURRENT_USER
HKLM       Registry      HKEY_LOCAL_MACHINE

표준 Location cmdlet을 PowerShell 드라이브와 함께 사용할 수도 있습니다.

Set-Location HKLM:\SOFTWARE
Push-Location .\Microsoft
Get-Location
Path
----
HKLM:\SOFTWARE\Microsoft

새 PowerShell 드라이브 추가

New-PSDrive 명령을 사용하여 자체 PowerShell 드라이브를 추가할 수 있습니다. 명령에 대한 New-PSDrive 구문을 얻으려면 구문 매개 변수를 Get-Command사용하여 명령을 입력합니다.

Get-Command -Name New-PSDrive -Syntax
New-[-Description <String>] [-Scope <String>] [-Credential <PSCredential>] [-Verbose] [-Debug ]
[-ErrorAction <ActionPreference>] [-ErrorVariable <String>] [-OutVariable <St ring>]
[-OutBuffer <Int32>] [-WhatIf] [-Confirm]

새 PowerShell 드라이브를 만들려면 다음과 같은 세 가지 매개 변수를 제공해야 합니다.

  • 드라이브의 이름(모든 유효한 PowerShell 이름 사용 가능)
  • PSProvider - filesystem 위치 및 FileSystem 레지스트리 위치에 Registry 사용
  • 루트, 즉 새 드라이브의 루트 경로입니다.

예를 들어 컴퓨터의 Microsoft Office 애플리케이션을 포함하는 폴더에 매핑되는 Office 드라이브를 만들 수 있습니다(예: C:\Program Files\MicrosoftOffice\OFFICE11). 드라이브를 만들려면 다음 명령을 입력합니다.

New-PSDrive -Name Office -PSProvider FileSystem -Root "C:\Program Files\Microsoft Office\OFFICE11"
Name       Provider      Root                                   CurrentLocation
----       --------      ----                                   ---------------
Office     FileSystem    C:\Program Files\Microsoft Offic...

참고 항목

일반적으로 경로는 대/소문자를 구분하지 않습니다.

PowerShell 드라이브는 이름 뒤에 콜론(:)을 사용하여 액세스합니다.

PowerShell 드라이브를 사용하면 많은 작업을 훨씬 간편하게 수행할 수 있습니다. 예를 들어 Windows 레지스트리에서 가장 중요한 키 중 일부에는 매우 긴 경로가 있으므로 액세스가 번거롭고 기억하기 어렵습니다. 중요 구성 정보는 아래에 있습니다 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion. CurrentVersion 레지스트리 키의 항목을 보고 변경하려면 다음과 같이 입력하여 해당 키의 루트로 사용할 PowerShell 드라이브를 만들 수 있습니다.

New-PSDrive -Name cvkey -PSProvider Registry -Root HKLM\Software\Microsoft\Windows\CurrentVersion
Name       Provider      Root                                   CurrentLocation
----       --------      ----                                   ---------------
cvkey      Registry      HKLM\Software\Microsoft\Windows\...

그런 다음 다른 드라이브와 마찬가지로 cvkey: 드라이브로 위치를 변경할 수 있습니다.

cd cvkey:

또는:

Set-Location cvkey: -PassThru
Path
----
cvkey:\

New-PSDrive cmdlet은 현재 PowerShell 세션에만 새 드라이브를 추가합니다. 따라서 PowerShell 창을 닫으면 새 드라이브가 손실됩니다. PowerShell 드라이브를 저장하려면 Export-Console cmdlet을 사용하여 현재 PowerShell 세션을 내보낸 다음, PowerShell.exePSConsoleFile 매개 변수를 사용하여 가져옵니다. 또는 Windows PowerShell 프로필에 새 드라이브를 추가합니다.

PowerShell 드라이브 삭제

Remove-PSDrive cmdlet을 사용하여 PowerShell에서 드라이브를 삭제할 수 있습니다. 예를 들어 Office: PowerShell 드라이브를 추가한 경우(New-PSDrive 항목 참조) 다음과 같이 입력하여 해당 드라이브를 삭제할 수 있습니다.

Remove-PSDrive -Name Office

cvkey: PowerShell 드라이브를 삭제하려면 다음 명령을 사용합니다.

Remove-PSDrive -Name cvkey

그러나 드라이브에 있는 동안에는 삭제할 수 없습니다. 예시:

cd office:
Remove-PSDrive -Name office
Remove-PSDrive : Cannot remove drive 'Office' because it is in use.
At line:1 char:15
+ remove-psdrive  <<<< -name office

PowerShell 외부 드라이브 추가 및 제거

PowerShell은 다음을 포함하여 Windows에서 추가되거나 제거된 파일 시스템 드라이브를 검색합니다.

  • 매핑된 네트워크 드라이브
  • 연결된 USB 드라이브
  • net use 명령을 사용하거나 또는 WSH(Windows 스크립트 호스트) 스크립트에서 삭제된 드라이브