CD~正在低于错误。
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 :(得分:0)
因为您在注册表中而引发此错误,并且默认情况下它没有主目录。错误消息明确表示,为了设置主目录(即使我没有理由),您需要调用echo date('Y-W', strtotime('2015-12-31'));
答案 1 :(得分:0)
之所以如此,是因为PowerShell中没有为Registry Provider分配的Home位置。
默认情况下,在PowerShell中我们有文件系统的主页位置,并且将是加载的用户配置文件的主目录。
PS C:\> Get-PSProvider -PSProvider FileSystem | Select-Object home
Home
----
C:\Users\Admin
对于Registry Provider,Home位置为空
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