SOLVED

Fix a broken $Profie location

Copper Contributor

 

A couple of days ago I remove Documents from OneDrive which seems to have broken the "Oh my POSH" settings in my various terminals. 

 

 

PowerShell 7.4.2
PS C:\Dev> $home
C:\Users\daniel
PS C:\Dev> $Profile
\PowerShell\Microsoft.PowerShell_profile.ps1
PS C:\Dev>

 

 

 

It looks like $Profle has lost the preceding C:\Users\daniel\Documents\PowerShell,  so is there a way to re-add it, without needing to reinstall PowerShell Core and Windows PowerShell? 

 

 

 

17 Replies

@Daniel Westerdale Does this work? This recreates the profile in it's default location.

 

New-Item $profile -Force

 

@Harm_Veenstra 

 

Thanks for the reply.

 

I opened my windows terminal and entered both

 

# attempt 1
New-Item $profile
# attempt 2
New-Item $profile -Value C:\Users\daniel\Documents\PowerShell\Microsoft.PowerShell_profile.ps1 -force -ItemType File

Unfortunately, neither work.

 

Is the file created afterward? And if you re-enable the OneDrive backup, does it work?

@Harm_Veenstra 

 

Hi the original issue was caused due my attempting at fixing an invalid profile name on my other laptop  with OneDrive Documents in place . Essentially, I want the profile just to reference my local path.

I made another attempt at fixing the profile:

 

 

$PROFILE = "$env:USERPROFILE\Documents\PowerShell\Microsoft.PowerShell_profile.ps1"

 

This re-enables my Oh My Posh settings but doesn't seem to persist the  $Profile path 

 

Powrrshwll.png

I was just wondering since you deleted the My Documents in your OneDrive... Did you have a backup of My Desktop, My Pictures, and My Documents configured? If you right-click your My Documents folder in Windows Explorer and select properties... What folder does the Location tab specify?

@Harm_Veenstra 

 

Good morning.  No backup as yet which I will remedy shortly.  I do appear to have lost the My Documents quick access although Downloads, Music, Pictures all seem ok.

 

You have got me thinking : open up the recycle bin as all my previous PowerShell modules are located at c:\daniel\OneDrive\Documents\WindowsPowerShell\Modules. 

 

Could these be the next steps:

  1. Restore these and back up this directory
  2. Re-add Documents to OneDrive
  3. Copy files over from backed up directory
  4. Check / amend the $Profile 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

It seems like a plan to get things back to where they were and move on from there. But check the Known Folder Move /backup settings in the OneDrive client. Default is c:\users\username\documents\WindowsPowerShell\Modules, but with Known Folder Move/backup settings enabled in OneDrive, they are in the OneDrive folder
I am currently restoring Documents from the Recycle bin ... um there is quite a lot of files so it is taking a while. I have looked at the Settings/ backup and not seeing anything for the PS modules. However I do appear to be restoring lots of files from c:\users\username\documents\WindowsPowerShell\Modules so I guess that is the indicator.
It's not the modules listed there, but the My Documents, Pictures and Desktop. (It's all or nothing)

@Harm_Veenstra 

 

so these settings should all be enabled

 

backup settings.png

 However, when I look at the files to settins:  everying in Documents , Pictures etc is added to OneDrive inlcuding Power shell

 

PowerShell.png

Now I appear to be miss PSReadline so I guess this not available in new location:cry:

 

PowerShell 7.4.2
Cannot load PSReadline module. Console is running without PSReadline.
Loading personal and system profiles took 2319ms.


 $Profile
\PowerShell\Microsoft.PowerShell_profile.ps1

 

Update: I have  installed PSReadline module but in Win 7 session but this is located in C:\Users\daniel\Documents\PowerShell\Modules and so not the OneDrive location . Weirdly, $envPSModulePath looks fine with the OneDirve\Dcouments\PowerShellMdoules incuded in the first entry.

 

Ah, more granular now :) Install-Module -Name PSReadLine doesn't work?
That works fine but I don't understand why PSReadline is installed in C:\Users\daniel\Documents\PowerShell\Modules\PSReadLine . I amnot sure this is bad thing though .
ALso $Profle is still broken
What is the value of the Personal Key in HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders ? For me it's C:\Users\HarmVeenstra\OneDrive - NEXXT\Documents
best response confirmed by Daniel Westerdale (Copper Contributor)
Solution

@Harm_Veenstra 

 

 

Ah in my case I have C:\Users\daniel\OneDrive and also through syncing with the other laptop the C:\Users\danie\OneDrive  ( I originally caused issue with my bad spelling lol.)

So do I correct all the ones with the incorrect spelling given I have corrected the issue with the profile name.  

All the paths should be pointing to your homefolder (c:\users\daniel) if that's your user. Copy/Paste or move the Documents folder contents there...

@Harm_Veenstra 

 

Looks like your last instruction was pure gold!

 

I corrected the spelling mistake in some of the entries in 

 

Computer\HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders

 

Rebooted and finally.....

 

Profile fix.png

 

At last:cool:.

 

Thanks very much for your advice. 

No problem, glad it's fixed and nice profile prompt :thumbs_up:
1 best response

Accepted Solutions
best response confirmed by Daniel Westerdale (Copper Contributor)
Solution

@Harm_Veenstra 

 

 

Ah in my case I have C:\Users\daniel\OneDrive and also through syncing with the other laptop the C:\Users\danie\OneDrive  ( I originally caused issue with my bad spelling lol.)

So do I correct all the ones with the incorrect spelling given I have corrected the issue with the profile name.  

View solution in original post