2016-10-01 33 views
14

我推出的Windows PowerShell(通過按Windows鍵,鍵入「PowerShell的」並按下Enter鍵這將啓動C:\Windows\System32\WindowsPowerShell\v1.0),然後鍵入$profile然後按回車,看到WindowsPowerShell\Microsoft.PowerShell_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 

然而CurrentUserAllHostsCurrentUserCurrentHosts仍非路徑。這些非路徑意味着什麼?它們是指某些隱藏的值,還是我需要在某處設置一些系統值?

這裏是我的$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 
+0

是否使用一些自定義的主機?這個命令的輸出是什麼'[Environment] :: GetFolderPath([Environment + SpecialFolder] :: Personal)'? – PetSerAl

+0

如果缺少該定義,PowerShell是否會拒絕啓動? –

+0

它給出了一個空的迴應 – Mark

回答

7

TL;博士

問題可能不PowerShell的相關,但可能是由於在註冊表缺少的特殊文件夾路徑定義。

驗證註冊表項HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders是否包含REG_EXPAND_SZPersonal與數據%USERPROFILE%\Documents - 請參閱下面的診斷命令。

如果你發現你必須(重新)創建,使用方法:

New-ItemProperty ` 
    'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders' ` 
    Personal -Value '%USERPROFILE%\Documents' -Type ExpandString -Force 

,然後註銷再重新開機(或重啓),看看是否能解決了這一問題。


Eris's helpful answer告訴我們,特定的用戶 PS配置文件路徑是從什麼Environment.GetFolderPath(Environment.SpecialFolder.Personal)回報的。

.NET得到這個值時,經由所述SHGetKnownFolderPath殼牌API函數推測,從註冊表項HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders,值Personal,其中它通常被定義爲包含(可擴展)串%USERPROFILE%\Documents一個REG_EXPAND_SZ值。
(還有一個傳統的回退位置 - 請參閱here。)

概況CurrentUserAllHosts和只包含相對路徑CurrentUserCurrentHost

  • WindowsPowerShell\profile.ps1
  • WindowsPowerShell\Microsoft.PowerShell_profile.ps1

表明Environment.GetFolderPath(Environment.SpecialFolder.Personal)呼叫,其結果被用作路徑前綴 ,意外退回ned an 空字符串,這又建議註冊表問題


這裏有一些診斷命令和他們預計的產出(jdoe代表您的用戶名):

# 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 
8

結果根據GitHub上的PowerShell的源代碼,他們會尋找Environment.SpecialFolder.Personal

它開始在ConsoleHost.cs 你可以追蹤到utils.cs其中t嘿打電話Environment.GetFolderPath(Environment.SpecialFolder.Personal);