Сценарий (.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
Импорт-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
}
Импорт-Второй.psm1
function Write-Goodbye
{
Write-Host "bye bye!"
}