2016-02-05 51 views
-2

CD〜拋出低於錯誤。cd〜在PWD處於Regisrty時拋出錯誤

PS HKLM:\> cd ~ 
cd : Home location for this provider is not set. To set the home location,  call "(get-psprovider 'Registry').Home = 'path'". 
At line:1 char:1 
+ cd ~ 
+ ~~~~ 
+ CategoryInfo   : InvalidOperation: (:) [Set-Location], PSInvalidOperationException 
+ FullyQualifiedErrorId : InvalidOperation,Microsoft.PowerShell.Commands.SetLocationCommand 

爲什麼是這樣?

回答

0

由於您在註冊表中並且默認情況下它沒有主目錄,因此會引發此錯誤。錯誤消息明確表示爲了設置主目錄(即使我看不到任何理由),您需要撥打(get-psprovider 'Registry').Home = 'path'

0

這是因爲在PowerShell中沒有爲註冊表提供程序分配歸位置。

默認情況下,在PowerShell中,我們擁有文件系統的主頁位置,並且將成爲加載的用戶配置文件的主目錄。

PS C:\> Get-PSProvider -PSProvider FileSystem | Select-Object home 

Home 
---- 
C:\Users\Admin 

而對於註冊表提供,首頁位置是空的

PS C:\> Get-PSProvider -PSProvider Registry | Select-Object home 

Home 
---- 

但是你可以設置它,

PS C:\> Get-PSProvider -PSProvider Registry | Get-Member 


TypeName: System.Management.Automation.ProviderInfo 

Name    MemberType Definition 
----    ---------- ---------- 
Equals   Method  bool Equals(System.Object obj) 
GetHashCode  Method  int GetHashCode() 
GetType   Method  type GetType() 
ToString   Method  string ToString() 
Capabilities  Property  System.Management.Automation.Provider.ProviderCapabilities Capabilities {get;} 
Description  Property string Description {get;set;} 
Drives   Property System.Collections.ObjectModel.Collection [System.Management.Automation.PSDriveInfo] Drives {get;} 
HelpFile   Property string HelpFile {get;} 
Home    Property string Home {get;set;} # **Can Be SET** . 
ImplementingType Property type ImplementingType {get;} 
Module   Property psmoduleinfo Module {get;} 
ModuleName  Property string ModuleName {get;} 
Name    Property string Name {get;} 
PSSnapIn   Property System.Management.Automation.PSSnapInInfo  PSSnapIn {get;} 

您可以設置它這樣。

PS C:\> $provider = Get-PSProvider -PSProvider Registry 
PS C:\> $provider.Home = "HKLM:\" 
PS C:\> Get-PSProvider -PSProvider Registry | Select-Object home 

Home 
---- 
HKLM:\ 

PS C:\> cd HKLM:\SOFTWARE\ 
PS HKLM:\SOFTWARE\> cd ~ 
PS HKLM:\> 

最好的問候,

kvprasoon