Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ScriptsToProcess is only processed for the first import #6170

Closed
alx9r opened this issue Feb 16, 2018 · 4 comments
Closed

ScriptsToProcess is only processed for the first import #6170

alx9r opened this issue Feb 16, 2018 · 4 comments
Labels
Issue-Discussion the issue may not have a clear classification yet. The issue may generate an RFC or may be reclassif Resolution-No Activity Issue has had no activity for 6 months or more WG-Cmdlets-Core cmdlets in the Microsoft.PowerShell.Core module

Comments

@alx9r
Copy link

alx9r commented Feb 16, 2018

The scripts named in ScriptsToProcess are processed only for the first module that is imported. This has the following implications for SessionStates that need to include the alterations caused by ScriptsToProcess:

  • An Import-Module statement that usually causes changes to the active SessionState does not make those changes if the module named in the statement happens to already be loaded.
  • Where more than one SessionState imports the same module, at most one of those SessionStates will have the alterations caused by ScriptsToProcess. Which one depends on the order the module importing occurs.

A workaround for this might be to use Import-Module -Force. However, if the module also involves PowerShell classes, then it might run afoul of #2505.

Steps to reproduce

ScriptsToProcess.psd1

@{
    ModuleVersion = '0.1.0'
    RootModule = 'ScriptsToProcessTest.psm1'
    ScriptsToProcess = 'ScriptsToProcessTest.ps1'
}

ScriptsToProcess.psm1

empty file

ScriptsToProcess.ps1

Write-Host 'ScriptsToProcessTest.ps1'
$v = 'importerscope.v'

Invoke the following

Remove-Variable v -ea si
Remove-Module ScriptsToProcessTest -ea si

New-Module m {
    Write-Host 'module'
    Import-Module ScriptsToProcessTest
    function Get-V {$v}
} | Import-Module

Write-Host 'global'
Import-Module ScriptsToProcessTest
"v: $v"
"Get-V: $(Get-V)"

Expected behavior

module
ScriptsToProcessTest.ps1
global
ScriptsToProcessTest.ps1
v: importerscope.v
Get-V: importerscope.v

Actual behavior

module
ScriptsToProcessTest.ps1
global
v:
Get-V: importerscope.v

Environment data

> $PSVersionTable

Name                           Value                                            
----                           -----                                            
PSVersion                      6.0.0                                            
PSEdition                      Core                                             
GitCommitId                    v6.0.0                                           
OS                             Microsoft Windows 6.3.9600                       
Platform                       Win32NT                                          
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                          
PSRemotingProtocolVersion      2.3                                              
SerializationVersion           1.1.0.1                                          
WSManStackVersion              3.0                                              
@iSazonov iSazonov added Issue-Discussion the issue may not have a clear classification yet. The issue may generate an RFC or may be reclassif WG-Cmdlets-Core cmdlets in the Microsoft.PowerShell.Core module labels Feb 20, 2018
Copy link
Contributor

This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

1 similar comment
Copy link
Contributor

This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

@microsoft-github-policy-service microsoft-github-policy-service bot added Resolution-No Activity Issue has had no activity for 6 months or more labels Nov 16, 2023
Copy link
Contributor

This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

Copy link
Contributor

This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Discussion the issue may not have a clear classification yet. The issue may generate an RFC or may be reclassif Resolution-No Activity Issue has had no activity for 6 months or more WG-Cmdlets-Core cmdlets in the Microsoft.PowerShell.Core module
Projects
None yet
Development

No branches or pull requests

2 participants