itsource

윈도우즈 Powershell $profile이 실제 경로를 표시하지 않음

mycopycode 2023. 8. 20. 10:47
반응형

윈도우즈 Powershell $profile이 실제 경로를 표시하지 않음

Windows Powershell을 시작합니다(Windows 키를 누르고 "powershell"을 입력한 후 Enter 키를 누르면 시작됨).C:\Windows\System32\WindowsPowerShell\v1.0) 및 유형$profile그리고 Enter 키를 눌러 보세요.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

하지만, 그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

참고: 이 질문은 다음에 대한 것이 아닙니다.$PROFILE파일은 존재하지 않습니다. 아마도 디렉토리와 함께. 만약$PROFILE예상 경로를 표시하고 파일이 존재하는지 확인하기만 하면 됩니다.
if (-not (Test-Path $PROFILE)) { $null = New-Item -Force $PROFILE }

tl;dr:

문제는 PowerShell과 관련이 없지만 레지스트리에 특수 폴더 경로 정의가 없기 때문일 수 있습니다.

레지스트리 키 확인HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders포함REG_EXPAND_SZ명명된 값Personal자료가 있는%USERPROFILE%\Documents아래의 진단 명령을 참조하십시오.

이 파일을 다시 만들어야 하는 경우 다음을 사용합니다.

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

로그오프했다가 다시 시작(또는 재부팅)하여 문제가 해결되었는지 확인합니다.


Eris의 유용한 답변은 사용자별 PS 프로파일 경로가 반환되는 것에서 파생된다는 것을 알려줍니다.

.NET은 아마도 Shell API 함수를 통해 레지스트리 키에서 이 값을 가져옵니다.HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders,가치Personal일반적으로 다음과 같이 정의됩니다.REG_EXPAND_SZ(사용 가능한) 문자열을 포함하는 값%USERPROFILE%\Documents.
(레거시 백업 위치도 있습니다. 여기를 참조하십시오.)

프로필CurrentUserAllHosts그리고.CurrentUserCurrentHost다음과 같은 상대 경로만 포함합니다.

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

결과경로 접두사로 사용되는 호출이 예기치 않게 문자열을 반환했으며, 이는 다시 레지스트리 문제를 시사합니다.


다음은 몇 가지 진단 명령과 예상 출력입니다.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

github의 파워셸 소스 코드에 따르면, 그들은 다음과 같은 것을 찾습니다.Environment.SpecialFolder.Personal

그것은 ConsoleHost.cs 에서 시작되고 당신은 그들이 전화하는 utils.cs 에서 이것을 추적할 수 있습니다.Environment.GetFolderPath(Environment.SpecialFolder.Personal);

오늘도 동일한 문제가 발생했으며 다음 PowerShell 명령을 사용하여 프로파일을 생성할 수 있었습니다.

New-Item -path $PROFILE -type File -force

이것이 도움이 되길 바랍니다!

언급URL : https://stackoverflow.com/questions/39809315/windows-powershell-profile-does-not-show-a-real-path

반응형