Скрипт (.ps1) импортира ModuleA, който импортира ModuleB. От скрипта мога да видя функция от ModuleB (с Get-Command), но тя е посочена като принадлежаща към ModuleA. Мога също да променя/премахвам функцията. Когато изпълнението влезе в ModuleA, функцията от ModuleB се посочва като принадлежаща на ModuleB (чрез Get-Command) и се връща към първоначалното състояние.
Това по дизайн ли е?
пример:
Invoke-Greeting.ps1
Import-Module .\Import-First.psm1
Get-Command -Module "Import-First" # Write-Greetings and Write-Goodbye
Get-Command -Module "Import-Second" # no functions found
Get-Command -Name "Write-Goodbye" # Write-Goodbye (module = Import-First) ***is this by design?***
Remove-Item "function:\Write-Goodbye"
Get-Command -Module "Import-First" # Write-Greetings
Get-Command -Module "Import-Second" # no functions found
Get-Command -Name "Write-Goodbye" # error: function doesn't exist (expected)
Write-Greetings
Import-First.psm1
Import-Module .\Import-Second.psm1
function Write-Greetings
{
Write-Host "hello world!" # hello world!
Get-Command -Module "Import-First" # Write-Greetings
Get-Command -Module "Import-Second" # Write-GoodBye
Get-Command -Name "Write-GoodBye" # Write-GoodBye (module = Import-Second) ***module changed since execution scope changed***
Write-GoodBye
}
Import-Second.psm1
function Write-Goodbye
{
Write-Host "bye bye!"
}