Repository navigation
Closed
Labels
Issue-BugIssue has been identified as a bug in the productResolution-DuplicateThe issue is a duplicate.
Description
Prerequisites
- Write a descriptive title.
- Make sure you are able to repro it on the latest released version
- Search the existing issues.
- Refer to the FAQ.
- Refer to Differences between Windows PowerShell 5.1 and PowerShell.
Steps to reproduce
I have a python script that runs a .ps1 file which includes commands from the Microsoft.PowerShell.Security module. Starting with 7.3.0, these commands fail to import during script execution. This can be reproduced from a PowerShell window:
python -c "import subprocess; subprocess.Popen('powershell -command Get-ExecutionPolicy')"
OR
python -c "import subprocess; subprocess.Popen('powershell -command Import-Module Microsoft.PowerShell.Security')"
Expected behavior
PS C:\> python -c "import subprocess; subprocess.Popen('powershell -command Get-ExecutionPolicy')"
PS C:\> Restricted
PS C:\> python -c "import subprocess; subprocess.Popen('powershell -command Import-Module Microsoft.PowerShell.Security')"
PS C:\>Actual behavior
PS C:\> python -c "import subprocess; subprocess.Popen('powershell -command Get-ExecutionPolicy')"
PS C:\> 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
PS C:\> python -c "import subprocess; subprocess.Popen('powershell -command Import-Module Microsoft.PowerShell.Security')"
PS C:\> 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.ImportModuleCommandError details
No response
Environment data
PS> $PSVersionTable
Name Value
---- -----
PSVersion 7.3.0
PSEdition Core
GitCommitId 7.3.0
OS Microsoft Windows 10.0.22622
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
PS> python --version
Python 3.10.6Visuals
No response
Metadata
Metadata
Assignees
Labels
Issue-BugIssue has been identified as a bug in the productResolution-DuplicateThe issue is a duplicate.
Activity
zurcher commentedon Nov 30, 2022
Following this comment from the PowerShell VSCode extension chat, I found that the behavior was resolved by commenting out the "TypesToProcess" line from Microsoft.PowerShell.Security.psd1
The change was introduced in #16355
This does not occur with PowerShell 7.2.7.
jborean93 commentedon Nov 30, 2022
I believe this is a duplicate of #18530 but I'm not 100% sure. The problem is you start Python from PowerShell 7.3 which inherits the PSModulePath env var and that Python process then spawns Windows PowerShell (5.1) with that inherited env var. It will try to import
Microsoft.PowerShell.Securitythat is provided by PowerShell 7.3.0 when it should be using what Windows PowerShell ships with.SteveL-MSFT commentedon Dec 12, 2022
Yes, this looks like a dupe of #18530, the workaround suggested here #18530 (comment) should work for you
zurcher commentedon Dec 12, 2022
I'm hitting this bug in a long-term product support codebase and probably can't check in this workaround. I also suspect we'll see more reports of this issue as more people move to 7.3, and the error message gives no easy indication of what the problem is.
If
pwshandpowershellalready know how to rebuildPSModulePath, could thepwsh -> powershell.exespecial-case be applied to all executable calls?Apply the same PSModulePath fix to install.ps1, which has the same ex…
studio setup: let Windows PowerShell load its own Security module (#7692
fix: take PowerShell calls out of the shared module-analysis cache
Release: fix the Results runtime signature check on GitHub Actions