Import Powershell Module

Import Powershell Module

Module bündeln Cmdlets, die nicht in jeder frischen PowerShell stecken. Ob ActiveDirectory, Exchange oder ein REST-Wrapper Richtung Hypervisor: Ohne Import sieht das Script den Befehl nicht. Unter Proxmox-Nähe heißt das oft: Das Script läuft auf einem Windows-Adminhost, das Modul kommt zusätzlich, die API des Hypervisors wird danach angesprochen.

Finden und laden

Get-Module -ListAvailable Import-Module ActiveDirectory Get-Command -Module ActiveDirectory

Liegt das Modul nicht im Standardpfad, Pfad angeben oder $env:PSModulePath erweitern:

Import-Module "C:\Scripts\Modules\MeinModul\MeinModul.psd1"

Aus der Gallery

Install-Module -Name Posh-SSH -Scope CurrentUser Import-Module Posh-SSH

In Scripts festziehen, damit ein fremder Host nicht still ohne Modul weiterläuft:

#Requires -Modules ActiveDirectory Import-Module ActiveDirectory -ErrorAction Stop

Autoload gibt es ab PowerShell 3 für Module im ModulePath – explizites Import-Module bleibt trotzdem klarer, sobald mehrere Versionen oder UNC-Pfade im Spiel sind.