Skip to content

Windows PowerShell terminal using PowerShell 7 modules #251311

Closed as not planned
Closed as not planned
@splatteredbits

Description

@splatteredbits

Type: Bug

I discovered this error when I tried to run Get-ExecutionPolicy in a Windows PowerShell 5.1 terminal and would get this error:

get-executionpolicy : The 'get-executionpolicy' command was found in the module 'Microsoft.PowerShell.Security', but the module could 
not be loaded. For more information, run 'Import-Module Microsoft.PowerShell.Security'.
At line:1 char:1
+ get-executionpolicy
+ ~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (get-executionpolicy:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CouldNotAutoloadMatchingModule

Steps to reproduce:

  1. Open terminal (Ctrl+`)
  2. Click the "Launch Profile" down-pointing caret and choose "Windows PowerShell".
  3. Run Import-Module Microsoft.PowerShell.Security and you'll get the error: import-Module : The following error occurred while loading the extended type data file: Error in TypeData "System.Security.AccessControl.ObjectSecurity": The member AuditToString is already present.. (Full error below [1].)
  4. Open a Windows PowerShell terminal from the Windows start menu outside Visual Studio Code. The above command runs without errors.

The root of the problem is that the Windows PowerShell process launched by Visual Studio Code contains module paths from PowerShell 7. These modules can't be loaded by Windows PowerShell. Here are the module paths from Windows PowerShell launched from the Windows start menu:

> $env:PSModulePath -split ';'
C:\Users\********\Documents\WindowsPowerShell\Modules
C:\Program Files\WindowsPowerShell\Modules
C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules

Here are the module paths in Windows PowerShell launched by Visual Studio Code:

> $env:PSModulePath -split ';'
C:\Users\********\Documents\WindowsPowerShell\Modules
C:\Users\********\Documents\PowerShell\Modules
C:\Program Files\PowerShell\Modules
c:\program files\powershell\7\Modules
C:\Program Files\WindowsPowerShell\Modules
C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules

[1] Import-Module Microsoft.PowerShell.Security error:

import-Module : The following error occurred while loading the extended type data file: Error in TypeData 
"System.Security.AccessControl.ObjectSecurity": The member AuditToString is already present.
Error in TypeData "System.Security.AccessControl.ObjectSecurity": The member AccessToString is already present.
Error in TypeData "System.Security.AccessControl.ObjectSecurity": The member Sddl is already present.
Error in TypeData "System.Security.AccessControl.ObjectSecurity": The member Access is already present.        
Error in TypeData "System.Security.AccessControl.ObjectSecurity": The member Group is already present.
Error in TypeData "System.Security.AccessControl.ObjectSecurity": The member Owner is already present.
Error in TypeData "System.Security.AccessControl.ObjectSecurity": The member Path is already present.
At line:1 char:1
+ import-Module Microsoft.PowerShell.Security
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Import-Module], RuntimeException
    + FullyQualifiedErrorId : FormatXmlUpdateException,Microsoft.PowerShell.Commands.ImportModuleCommand       

VS Code version: Code 1.101.0 (dfaf441, 2025-06-11T15:00:50.123Z)
OS version: Windows_NT x64 10.0.19045
Modes:

System Info
Item Value
CPUs 12th Gen Intel(R) Core(TM) i7-12800H (20 x 2803)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: enabled_on
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: disabled_off
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled
webnn: disabled_off
Load (avg) undefined
Memory (System) 31.67GB (11.80GB free)
Process Argv --crash-reporter-id 0218cdfb-59b0-432f-b010-d05368101361
Screen Reader no
VM 0%
Extensions (20)
Extension Author (truncated) Version
insert-unicode bru 0.15.1
chef che 2.2.12
vscode-markdownlint Dav 0.60.0
docker doc 0.10.0
EditorConfig Edi 0.17.4
terraform has 2.34.4
vscode-containers ms- 2.0.3
vscode-docker ms- 2.0.0
csdevkit ms- 1.20.35
csharp ms- 2.80.16
vscode-dotnet-runtime ms- 2.3.5
vscodeintellicode-csharp ms- 2.2.3
remote-containers ms- 0.417.0
remote-wsl ms- 0.99.0
powershell ms- 2025.0.0
pester-test psp 2023.7.7
vscode-xml red 0.29.0
vscode-yaml red 1.18.0
ruby-lsp Sho 0.9.28
rewrap stk 1.16.3
A/B Experiments
vsliv368:30146709
vspor879:30202332
vspor708:30202333
vspor363:30204092
vscod805:30301674
binariesv615:30325510
c4g48928:30535728
azure-dev_surveyone:30548225
a9j8j154:30646983
962ge761:30959799
h48ei257:31000450
pythontbext0:30879054
cppperfnew:31000557
dwnewjupytercf:31046870
pythonrstrctxt:31112756
nativeloc2:31192216
5fd0e150:31155592
dwcopilot:31170013
6074i472:31201624
dwoutputs:31242946
customenabled:31248079
9064b325:31222308
copilot_t_ci:31222730
e5gg6876:31282496
pythoneinst12:31285622
bgtreat:31268568
4gafe986:31271826
c7cif404:31314491
pythonpulldiag:31325930
996jf627:31283433
pythonrdcb7:31303018
usemplatestapi:31297334
0aa6g176:31307128
7bj51361:31289155
747dc170:31275177
pylancecolor:31314202
aj953862:31281341
generatesymbolt:31295002
convertfstringf:31295003
gendocf:31295004
pylancequickfixf:31319675

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions