0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

The Export-ModuleMember cmdlet can only be called from inside a module.発生理由

Posted at

発生状況

PowerShellで共通化モジュールを作って、他のPowerShellから呼び出そうとした際に、以下のエラーが発生した。

The Export-ModuleMember cmdlet can only be called from inside a module.

処理内容

呼び出す側

call.ps1
    # 共通化モジュールを読み込む(ここでエラーが発生)
    Import-Module .\called.ps1

    # エクスポートした関数を呼び出す
    test()

呼び出される側

called.ps1
    function test(){
        Write-Output '呼び出された'
    }
    Export-ModuleMember -Function test

原因と解決方法

呼び出される側のファイルが.ps1ファイルだったこと。
.psm1というモジュール用の拡張子があるため、called.psm1とするのが正解らしい。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?