首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用嵌套模块加载PowerShell模块产生错误

用嵌套模块加载PowerShell模块产生错误
EN

Stack Overflow用户
提问于 2018-09-07 10:21:27
回答 1查看 349关注 0票数 0

我已经编写了一个定制的PowerShell模块。我的自定义模块使用SharePoint CMD让。因此,在我的psd1文件中,我有一个嵌套的模块属性,类似于:

代码语言:javascript
复制
NestedModules = @( 'Microsoft.SharePoint.PowerShell',
        '.\Modules\MyModule.psd1')

我是从:PowerShell Modules and SnapIns得到的

当我导入这个模块时,我得到(错误数量的一小部分):

代码语言:javascript
复制
Import-Module : The following error occurred while loading the extended type data file: Error in TypeData
"Microsoft.Office.Server.Search.Administration.SearchServiceApplication": The member ServiceName is already present.
At line:1 char:1
+ Import-Module Test
+ ~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Import-Module], RuntimeException
    + FullyQualifiedErrorId : Module_ImportModuleError,Microsoft.PowerShell.Commands.ImportModuleCommand

Import-Module : The following error occurred while loading the extended type data file: Error in TypeData
"Microsoft.Office.Server.Search.Administration.SearchService": The member ProcessIdentity is already present.
At line:1 char:1
+ Import-Module Test
+ ~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Import-Module], RuntimeException
    + FullyQualifiedErrorId : Module_ImportModuleError,Microsoft.PowerShell.Commands.ImportModuleCommand

Import-Module : The following error occurred while loading the extended type data file: Error in TypeData
"Microsoft.Office.Server.Search.Administration.SearchService": The member ServiceName is already present.
At line:1 char:1
+ Import-Module Test
+ ~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Import-Module], RuntimeException
    + FullyQualifiedErrorId : Module_ImportModuleError,Microsoft.PowerShell.Commands.ImportModuleCommand

Import-Module : The following error occurred while loading the extended type data file: Error in TypeData
"Microsoft.Office.Server.Search.Administration.Keyword": The member ExpiryDate is already present.
At line:1 char:1
+ Import-Module Test
+ ~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Import-Module], RuntimeException
    + FullyQualifiedErrorId : Module_ImportModuleError,Microsoft.PowerShell.Commands.ImportModuleCommand

Import-Module : The following error occurred while loading the extended type data file: Error in TypeData
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-09-14 15:25:49

最后,我创建了PowerShell脚本来加载SharePoint PSSnapin。

代码语言:javascript
复制
Begin {
    $SPSnapin = "Microsoft.SharePoint.PowerShell"

    Write-Verbose "The GasuniePowerShell module will try to load the $SPSnapin snappin"  -Verbose

    try {        
        if (Get-PSSnapin $SPSnapin -ErrorAction SilentlyContinue) {
            Write-Verbose "Microsoft.SharePoint.PowerShell Snappin already registered and loaded" -Verbose
        }
        elseif (Get-PSSnapin $SPSnapin -Registered -ErrorAction SilentlyContinue) {
            Add-PSSnapin $SPSnapin
            Write-Verbose "$SPSnapin Snappin is registered and has been loaded for script operation" -Verbose
        }
        else {
            Write-Warning "$SPSnapin Snappin not installed on this server. SharePoint cmdlets disabled." -Verbose
            Exit                
        }
    }
    catch {
        Write-Warning "There was an issue loading the $SPSnapin Snappin. Exiting function." -Verbose
        Write-Warning $_
        Exit  

    }    
}

在我的PowerShell模块清单中,添加了以下属性:

代码语言:javascript
复制
ScriptsToProcess = '.\scripts\LoadSharePointPowerShell.ps1'

每当导入模块时,该脚本将运行并加载SnapIn。当模块发布时,不给出错误。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52220482

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档