2

I recently noticed a WindowsPowerShell folder in my Documents folder (in C:\Users\sylva\Documents, sylva being my user profile). I deleted it, but it comes back after each startup.

Please, could you help me get rid of this folder?

For context, I do not use / need Powershell, so not too sure why this folder is there. Many thanks.

New contributor
Sylvain Mons is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
8
  • Please, add to your post what Windows version you're running on your PC. Commented yesterday
  • Did you create and/or change some Powershell's profiles? Commented yesterday
  • Please, add to your post what Powershell version you're running on your PC. Just run the following command line in Powershell terminal: $psversiontable.psversion Commented yesterday
  • What is the exact name of the folder? If you are talking about, C:\Documents and Settings\Sylva/My Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1 then thats your user profile PowerShell profile used by Windows and it cannot be deleted since its required for PowerShell which is used by Windows for numerous things. What you want isn’t possible. The directory should contain very little and take virtually no space. Commented yesterday
  • @JorgeLuiz I'm on Windows 11 Home; I do not believe I created and/or changed some Powershell's profile (at least not on purpose ;) My Powershell version is Major 5, Minor 1, Build 26100, Revision 7019; thanks for your help Commented 10 hours ago

2 Answers 2

4

While the WindowsPowerShell subfolder[1] of the well-known Documents folder:[2]

  • is used by Windows PowerShell (the legacy, ships-with-Windows, Windows-only edition of PowerShell whose latest and final version is 5.1), namely to store optional user-level modules,

  • its existence is not necessary for Windows PowerShell to function, and Windows PowerShell does not create it on demand (it is created only through deliberate user action).[3]

The above implies that in your case some process that runs on login must be recreating said folder, so you'll have to investigate which one that is.
The Sysinternals Autoruns utility can help you with that.

Specifically, given that, as you state in a later comment, subfolders Scripts\InstalledScriptInfos are created inside the undesired WindowsPowerShell folder, look for a PowerShell startup task that calls Install-Script.


[1] Note that PowerShell (Core) 7, the modern, cross-platform, install-on-demand successor edition, uses the PowerShell subfolder instead. The rest of this answer applies analogously.

[2] Its default location is $env:USERPROFILE\Documents, but it may be redirected to a different location on a given machine, often to OneDrive; use [Environment]::GetFolderPath('MyDocuments') to determine the actual location.

[3] Deliberate actions such as force-creating the file that $PROFILE points to with New-Item -Force $PROFILE, which implicitly creates its hosting folder, i.e. WindowsPowerShell under Documents (CAVEAT: if you run this and there's a preexisting file at that location, it will be truncated) or such as installing a module or script with Install-Module or Install-Script.
Conversely, you can verify that the folder is not (re)created on demand as follows: If necessary (only if you see the unexpected creation of the folder), create a new user and log in as that. If the folder exists on your system, temporarily rename it. Then restart your system and run Windows PowerShell: it will start normally, without complaint, and the folder won't be (re)created.

5
  • Can you present evidence that you can remove this folder and it will not get re-created? Even just a narrative as you delete it and reboot, and it does not get recreated? Commented 15 hours ago
  • 1
    @music2myear: I've expanded footnote [3] with such a narrative. Commented 10 hours ago
  • @mklement0 Many thanks for your reply! I downloaded Autoruns but cannot detect any direct reference to Powershell, Install-Module or Install-Script (I used the search bar for these 3 terms but it does not found anything like this unfortunately). Commented 9 hours ago
  • @SylvainMons: I see. Conceivably, the calls could be made from compiled .NET applications that use the PowerShell SDK. Also: Does the folder only reappear after you've opened a Windows PowerShell session after reboot? If so, the system-level profile files C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1 or C:\Windows\System32\WindowsPowerShell\v1.0\Microsoft.PowerShell_profile.ps1 could be the culprits. If that doesn't apply, I suggest disabling startup tasks one after the other until you hit the one that creates the folder. Commented 9 hours ago
  • 1
    @mklement0 The folder appears systematically after reboot; I will follow your suggestion and test each startup task to hopefully identify which one creates this folder; worst case I will just hide the folder but the idea that somethings likes this happens and I don't know why just bugs me ;) Many thanks for your help - much appreciated Commented 7 hours ago
3

While you may not need PowerShell, it is an integral part of the Windows OS, and that folder is a default part of that tool. You cannot remove PowerShell from Windows,

As an alternative: Hide the folder.

I have tested this just now and after hiding the WindowsPowerShell folder (just the folder, not subfolders or files) it remains hidden even after restarting. Of course, if you've told your OS to leave hidden files visible, this won't be so nice, but it's the choice you have.

Update based on further research: No, the answer hasn't changed. I just read these threads from sister sites:

However, these solutions are changing where your entire Documents folder exists, which breaks a LOT of things on an end-user/client system and doesn't actually hide or remove the WindowsPowerShell folder inside the Profile folder (Documents).

7
  • To be specific PowerShell 5.1 cannot be removed. Windows uses PowerShell for all sorts of things. PowerShell (Core) can be removed if it’s installed, there is no reason to remove it, unless your updating it to the current version. Commented yesterday
  • 1
    I am aware. I was clarifying that PowerShell (Core) can be removed but PowerShell 5.1 cannot since it’s built-into Windows 10 and Windows 11. That might change in the future for Windows 11 but Microsoft hasn’t made any announcements about that happening so I doubt it will happen anytime soon. Commented yesterday
  • 2
    A given user's WindowsPowerShell subfolder of their Documents folder is not an integral part of Windows PowerShell. The latter does not create this folder on demand, and it requires deliberate effort on the part of a given user to create it. Commented yesterday
  • 1
    @Ramhound: No, it won't. See my answer for details. (While it is used by PowerShell if present, it won't get created automatically.) Commented yesterday
  • 1
    @music2myear Many thanks for your reply; I guess I will hide this folder as suggested as I cannot figure out what's re-creating it start up; thanks again. Commented 10 hours ago

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.