次のコードが関数をエクスポートしない理由を教えてください:
# load all functions
$moduleRoot = Split-Path -Path $MyInvocation.MyCommand.Path
$functionFiles = "$moduleRoot\functions\*.ps1" | Resolve-Path
$functionFiles | ForEach-Object { . $_.ProviderPath }
$functionFiles | ForEach-Object { [io.path]::GetFileNameWithoutExtension($_) } | Export-ModuleMember
またはこれの違い:
動作していません:
$test = "Cmd1", "Cmd2"
Export-ModuleMember $test
働く:
Export-ModuleMember "Cmd1", "Cmd2"
アップデート:
「import-module MyCrazyModule」を呼び出すと、エクスポートされたコマンド (get-module) が表示されます。
ただし、「get-module -ListAvailable」を呼び出すと、エクスポートされたコマンド プロパティが空になります。(モジュールは PSModulePath にあります)
更新 2: 証拠
$PSModulePath には D:\powershell が含まれています
モジュール: "D:\powershell\MyCrazyModule\MyCrazyModule.psm1"
$test = "Cmd1", "Cmd2"
Export-ModuleMember $test
エクスポートが表示されません:
ただし内容によって
Export-ModuleMember "Cmd1", "Cmd2"
ありがとうございました