Windows Powershell$配置文件未显示实际路径
我启动Windows Powershell(通过按Windows键,键入“Powershell”并按enter键启动Windows Powershell$配置文件未显示实际路径,powershell,windows-10,Powershell,Windows 10,我启动Windows Powershell(通过按Windows键,键入“Powershell”并按enter键启动C:\Windows\System32\WindowsPowerShell\v1.0),键入$profile,然后按enter键查看WindowsPowerShell\Microsoft.Powershell\u profile.ps1 据我所知,这不是一条有效的路径。我希望得到像C:\Windows\… 但是,当我键入$profile | Format List*-Force时,
C:\Windows\System32\WindowsPowerShell\v1.0
),键入$profile
,然后按enter键查看WindowsPowerShell\Microsoft.Powershell\u profile.ps1
据我所知,这不是一条有效的路径。我希望得到像C:\Windows\…
但是,当我键入$profile | Format List*-Force
时,会有一些进展,我会
AllUsersAllHosts : C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1
AllUsersCurrentHost : C:\Windows\System32\WindowsPowerShell\v1.0\Microsoft.PowerShell_profile.ps1
CurrentUserAllHosts : WindowsPowerShell\profile.ps1
CurrentUserCurrentHost : WindowsPowerShell\Microsoft.PowerShell_profile.ps1
Length : 50
但是,CurrentUserAllHosts
和CurrentUserCurrentHosts
仍然是非路径。这些非路径意味着什么?它们是指一些隐藏的值还是我需要在某个地方设置一些系统值
这是我的$PsVersionTable.PsVersion
Major Minor Build Revision
----- ----- ----- --------
5 1 14393 206
以下是Get Host
Name : ConsoleHost
Version : 5.1.14393.206
InstanceId : a2a61a42-f2ee-46b9-b67a-ef441301bdb8
UI : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture : en-US
CurrentUICulture : en-US
PrivateData : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
DebuggerEnabled : True
IsRunspacePushed : False
Runspace : System.Management.Automation.Runspaces.LocalRunspace
根据github上的powershell源代码,他们查找
Environment.SpecialFolder.Personal
开始于
您可以追踪到他们调用
Environment.GetFolderPath(Environment.SpecialFolder.Personal)的位置代码>tl;博士:
问题可能与PowerShell无关,但可能是由于注册表中缺少特殊文件夹路径定义造成的
验证注册表项HKEY\U CURRENT\u USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\USER Shell Folders
是否包含名为REG\u EXPAND\u SZ
的值,该值包含数据%USERPROFILE%\Documents
-请参阅下面的诊断命令
如果您发现必须(重新)创建它,请使用:
New-ItemProperty `
'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders' `
Personal -Value '%USERPROFILE%\Documents' -Type ExpandString -Force
然后注销并重新启动(或重新启动),看看这是否解决了问题
告诉我们,特定于用户的PS配置文件路径是从Environment.GetFolderPath(Environment.SpecialFolder.Personal)
返回的内容派生而来的
.NET可能通过Shell API函数从注册表项HKEY\U CURRENT\U USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\USER Shell Folders
、valuePersonal
获取此值,通常将其定义为包含(可扩展)的REG\u EXPAND\u SZ
值字符串%USERPROFILE%\Documents
(还有一个传统的后备位置-请参阅。)
仅包含相对路径的配置文件CurrentUserAllHosts
和CurrentUserCurrentHost
,即:
WindowsPowerShell\profile.ps1
WindowsPowerShell\Microsoft.PowerShell\u profile.ps1
表明Environment.GetFolderPath(Environment.SpecialFolder.Personal)
调用(其结果用作路径前缀)意外返回了一个空字符串,这反过来表明存在注册表问题。
以下是一些诊断命令及其预期输出(jdoe
表示您的用户名):
您正在使用某个自定义主机吗?此命令的输出是什么?
[Environment]::GetFolderPath([Environment+SpecialFolder]::Personal)?如果缺少该定义,PowerShell甚至不会拒绝启动吗?在Win 10机器中,它给我一个空响应,$profile的值是C:\Users\userNamexxx\Documents\WindowsPowerShell\Microsoft.PowerShell\u profile.ps1
,但是没有这样的文件夹或文件!默认情况下没有,您必须创建它@标记,如果运行[Environment]:GetFolderPath(“MyDocuments”)
并打开CMD并运行echo%USERPROFILE%
,会发生什么?
# Verify that %USERPROFILE% is defined.
> $env:USERPROFILE
C:\Users\jdoe
# Verify that %USERPROFILE% is defined in the registry.
> Get-ItemPropertyValue 'HKCU:\Volatile Environment' USERPROFILE
C:\Users\jdoe
# Verify that the API call to retrieve the known folder
# "Personal" (Documents) returns the expected value.
> [Environment]::GetFolderPath('Personal')
C:\Users\jdoe\Documents
# See if the registry contains the expected definition.
> Get-ItemPropertyValue 'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders' Personal
C:\Users\jdoe\Documents