PowerShell Module parallel importieren

In PowerShell können mehrere Module mit ähnlichen Commands parallel importiert sein. Tritt der Fall in einer PowerShell Session auf kann es beim Einsatz der Commands zu Konflikten führen. Es lässt sich vermeiden.

Ähnliche Commands sollten vermieden werden. Meist ist es für einen selbst nicht beeinflussbar und es kann div. PowerShell Module treffen. Mit einem Prefix beim Import der Module lässt sich ein Konflikt oft umgehen. Generell beschreibt Microsoft den Importvorgang von PowerShell Modulen hier.

Allgemein ist es unabhängig zum Modul. Ein Prefix lässt sich auf jedes Modul anwenden. Für das Beispiel verwende ich die SharePoint Module SharePointPnPPowerShellOnline und SharePointPnPPowerShell2019. Sollen beide Module parallel installiert sein muss bei einem der Module bereits der Parameter AllowClobber eingesetzt werden.

Install-Module -Name SharePointPnPPowerShellOnline
Install-Module -Name SharePointPnPPowerShell2019 -AllowClobber
Parallelinstallation der SharePoint Module

Wichtig ist beim Import der Module nun darauf zu achten den Modulen einen Prefix zu vergeben. Den Prefix kannst du frei wählen, logischerweise sollte dieser unique sein.

Import-Module SharePointPnPPowerShellOnline -Prefix "SPO"
Import-Module SharePointPnPPowerShell2019 -Prefix "SPOP2019"

Eine Kontrolle zeigt die bekannten Commands wurden im Format [Command]-[Prefix][CommandName] mit dem Prefix erweitert. Aus einem Connect-PnPOnline wurde Connect-SPOP2019PnPOnline bzw. Connect-SPOPnPOnline.

Mit Connect-SPOP2019PnPOnline baut es die Verbindung über das Modul SharePointPnPPowerShell2019 auf. Mit Connect-SPOPnPOnline über das Modul SharePointPnPPowerShellOnline. Über die Art lässt sich unterscheiden welches Modul beim Einsatz von ähnlichen Commands zur Anwendung kommt.

Am Beispiel der SharePoint Module und um vermeidbare Konflikte abzuwenden würde ich eher raten einen Server für die SharePoint Server Module einzusetzen, und einen weiteren für das SharePoint Online (oder PnP PowerShell) Modul.

Share
Avatar photo

Tobias Asböck

Tobias is a Senior System Engineer with more than 10 years of professional experience with Microsoft 365 products such as SharePoint Online, SharePoint Premium, OneDrive for Business, Teams Collaboration, Entra ID, Information Protection, Universal Print, and Microsoft 365 Licensing. He also has 15+ years of experience planning, administering, and operating SharePoint Server environments. Tobias is a PowerShell Scripter with certifications for Microsoft 365 products. In his spare time, Tobias is busy with updates in the Microsoft 365 world or on the road with his road bike and other sports activities. If you have additional questions, please contact me via LinkedIn or [email protected].

Leave a Reply

Your email address will not be published. Required fields are marked *