我写了一个 PowerShell 5 类:
class ConnectionManager
{
# Public Properties
static [String] $SiteUrl
static [System.Management.Automation.PSCredential] $Credentials
static [SharePointPnP.PowerShell.Commands.Base.SPOnlineConnection] $Connection
...
}
“ SharePointPnP.PowerShell.Commands.Base.SPOnlineConnection
”类型来自自定义(已安装模块),名为“SharePointPnPPowerShell2016”
我的课程在另一个模块/文件中,称为“connection.manager.psm1”。
当我加载此模块以使用此类时,它返回以下错误:
> Import-Module connection.manager.psm1
At connection.manager.psm1:6 char:11
+ static [SharePointPnP.PowerShell.Commands.Base.SPOnlineConnection] ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Unable to find type
[SharePointPnP.PowerShell.Commands.Base.SPOnlineConnection].
当我在加载我的模块之前在 PowerShell 会话中手动加载(PNP)模块时,它已正确加载并且我可以使用它。
但我不想总是在使用我的模块之前先手动加载另一个模块。我尝试通过添加以下内容直接在我的模块中导入 PNP-Module:
Import-Module "SharePointPnPPowerShell2016"
一开始,在类声明之前,但它没有任何改变,仍然出现错误“无法找到类型”。
任何想法如何正确地做到这一点?