Загрузка модуля PowerShell с вложенным модулем выдает ошибки

Я написал собственный модуль PowerShell. В моем настраиваемом модуле используется SharePoint CMD. Итак, в моем файле psd1 у меня есть свойство вложенного модуля, например:

NestedModules = @( 'Microsoft.SharePoint.PowerShell',
        '.\Modules\MyModule.psd1')

Я получил это от: Модули PowerShell и SnapIns

Когда я импортирую этот модуль, я получаю (небольшой участок количества ошибок):

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

person Danny    schedule 07.09.2018    source источник


Ответы (1)


В итоге я создал сценарий PowerShell для загрузки SharePoint PSSnapin.

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 я добавил следующее свойство:

ScriptsToProcess = '.\scripts\LoadSharePointPowerShell.ps1'

Каждый раз, когда модуль импортируется, этот скрипт будет запускаться и загружать SnapIn. Когда модуль перезагружен, ошибки не выдаются

person Danny    schedule 14.09.2018