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
Visuals
No response
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
Error details
Environment data
Visuals
No response