【发布时间】:2018-02-15 14:07:43
【问题描述】:
我写了一个 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"
一开始,在类声明之前,但没有任何改变,仍然出现“无法找到类型”的错误。
任何想法如何正确地做到这一点?
【问题讨论】:
标签: powershell class powershell-5.0 powershell-module import-module