#requires -Modules fails in Enter-PSSession remoting session (PowerShell.7 endpoint) — regression from 7.4 to 7.6 · Issue #27907 · PowerShell/PowerShell · GitHub
Skip to content

#requires -Modules fails in Enter-PSSession remoting session (PowerShell.7 endpoint) — regression from 7.4 to 7.6 #27907

Description

Prerequisites

Steps to reproduce

When running a script that contains a #requires -Modules statement inside a Enter-PSSession session configured with the PowerShell.7 endpoint, the script fails with a missing module error in PS 7.6. The same script ran correctly in PS 7.4. The module is present and loadable — removing #requires and running the script succeeds.

1. Open a remote session

Enter-PSSession -ComputerName -Credential (Get-Credential) -ConfigurationName 'PowerShell.7'

2. Run a script that contains:

#requires -Modules ActiveDirectory

3. Invoke it

& .\test.ps1

Expected behavior

Script runs as it did in PS 7.4.

Actual behavior

The script 'test.ps1' cannot be run because the following modules that are specified by the
"#requires" statements of the script are missing: The module 'ActiveDirectory' cannot be found.

Error details

Workaround

Remove the #requires -Modules ActiveDirectory line, run the script once (it succeeds), then restore the line — it now works for the remainder of the session.

Environment

Broken: PowerShell 7.6
Working: PowerShell 7.4
Platform: Windows, remoting session via PowerShell.7 configuration endpoint


The ActiveDirectory module is a Windows PowerShell compatibility module (loaded via the implicit remoting shim in PS7). The #requires pre-flight check appears to fail to locate it through the compatibility path in 7.6 — but the module itself loads fine when #requires is bypassed, confirming it is present.

Related closed issues (no resolution): #16167, #17052

Environment data

PS 7.2 and 7.4

Visuals

No response

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs-TriageThe issue is new and needs to be triaged by a work group.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions