Skip to content

win_powershell - fix: WDAC check to check for enforce mode specifically rather than not none - #973

Open
Adamvg wants to merge 1 commit into
ansible-collections:mainfrom
Adamvg:patch-1
Open

Adamvg wants to merge 1 commit into
ansible-collections:mainfrom
Adamvg:patch-1

Conversation

@Adamvg

@Adamvg Adamvg commented Nov 25, 2026

Copy link
Copy Markdown
SUMMARY

Fixes #972

win_powershell treated the host as App Control enabled whenever [SystemPolicy]::GetSystemLockdownPolicy() returned anything other than None, and then forced the script into Constrained Language Mode. In audit mode the call returns Audit, but Windows does not constrain PowerShell there, so scripts that work in any other session failed through the module.

This changes the check to -eq 'Enforce', the same condition ansible-core uses in exec_wrapper.ps1. Behaviour on hosts with an enforced policy is unchanged.

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

win_powershell

ADDITIONAL INFORMATION

On a host with an audit-only App Control policy:

PS> $ExecutionContext.SessionState.LanguageMode
FullLanguage
PS> [System.Management.Automation.Security.SystemPolicy]::GetSystemLockdownPolicy()
Audit

Before: a script with a .NET property write fails with PropertySetterNotSupportedInConstrainedLanguage.

After: the same task completes, with the script running in FullLanguage.

@Adamvg Adamvg changed the title fix: Change WDAC check to check for enforce mode rather than not none win_powershell fix WDAC check to check for enforce mode specifically rather than not none Nov 25, 2026
@Adamvg Adamvg changed the title win_powershell fix WDAC check to check for enforce mode specifically rather than not none win_powershell - fix: WDAC check to check for enforce mode specifically rather than not none Nov 25, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

win_powershell WDAC check looks for not 'none' rather than -eq 'Enforced' - fails in audit mode

1 participant