Click here to Skip to main content
15,749,281 members
Please Sign up or sign in to vote.
1.24/5 (3 votes)
See more:
. $env:USERPROFILE\.config\powershell\user_profile.ps1

ERROR:E212 cant open file for writing:no such file or directory

What I have tried:

i gave all permission to user_profile.ps1
Updated 22-Dec-22 7:53am

It's not the powershell file itself that needs permissions, it's one of the commands it contains that is trying to output to a specific file that causes it. Probably, it's trying to reference a folder that doesn't exist.

Start by looking at the Powershell script in the file and see what it actually does.

Sorry, but we can't help you with that!
Share this answer
Above error comes because you dont have a default powershell profile file
IN powershell terminal Run,
<pre lang="powershell">echo $PROFILE

Output will be in this format which is the path to default powershell profile

The error comes because above file is not present, hence create it and put a space inside it and save it
nvim C:\Users\abesh\OneDrive\Documents\PowerShell\Microsoft.PowerShell_profile.ps1

Dont keep the file empty, add space and hit :wq to save and exit in nvim

Now run
nvim $PROFILE.CurrentUserCurrentHost

Add following lines to the file

. $env:USERPROFILE\.config\powershell\user_profile.ps1

Save and exit, You will not encounter any error.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900