0

I have written a custom PowerShell module. My custom module uses SharePoint CMD lets. So in my psd1 file I have a nested module property like:

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

I got this from: PowerShell Modules and SnapIns

When I import this module I get (small section of the number of errors):

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
Danny
  • 746
  • 2
  • 8
  • 20

1 Answers1

0

I ended up creating PowerShell script to load the 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  

    }    
}

In my PowerShell module manifest I added the following property:

ScriptsToProcess = '.\scripts\LoadSharePointPowerShell.ps1'

Whenever the module is imported this script will run and load the SnapIn. When the module is releoded no errors are given

Danny
  • 746
  • 2
  • 8
  • 20