leex01
Goto Top

Powershell Module

Moin,

mir ist aufgefallen das manche Module standardmäßig von der Powershell geladen werden und andere nicht. In der $Profile und im Netz konnte ich nichts dazu finden. Wo ist definiert welche Module gleich beim starten der PS geladen werden?

Grüße und bleibt gesund

Content-Key: 561061

Url: https://administrator.de/contentid/561061

Printed on: April 25, 2024 at 00:04 o'clock

Mitglied: 143127
Solution 143127 Mar 26, 2020 updated at 11:42:11 (UTC)
Goto Top
Hier steht's
https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell. ...
Abschnitt "Module Autoloading"
Module Auto-Loading
Beginning in PowerShell 3.0, PowerShell imports modules automatically the first time that you run any command in an installed module. You can now use the commands in a module without any set-up or profile configuration, so there's no need to manage modules after you install them on your computer.  
The commands in a module are also easier to find. The Get-Command cmdlet now gets all commands in all installed modules, even if they are not yet in the session, so you can find a command and use it without importing.
......
Only modules that are stored in the location specified by the PSModulePath environment variable are automatically imported. Modules in other locations must be imported by running the Import-Module cmdlet.
Also, commands that use PowerShell providers do not automatically import a module. For example, if you use a command that requires the WSMan: drive, such as the Get-PSSessionConfiguration cmdlet, you might need to run the Import-Module cmdlet to import the Microsoft.WSMan.Management module that includes the WSMan: drive.
You can still run the Import-Module command to import a module and use the $PSModuleAutoloadingPreference variable to enable, disable and configure automatic importing of modules. For more information, see about_Preference_Variables.
Member: LeeX01
LeeX01 Mar 26, 2020 at 12:58:08 (UTC)
Goto Top
Hi Vibrations,

Danke dir. Das Autoload kannte ich aber dachte es würden auch Module vorab schon geladen werden. Das ist aber bis auf die NetCmdlets nicht der Fall. Habe es gerade getestet. Die anderen Module waren einfach durch vorherige Befehle in der Session geladene Module.
Member: LeeX01
LeeX01 Mar 26, 2020 at 13:49:13 (UTC)
Goto Top
Darauf gekommen bin ich eigentlich weil ich wieder ein Modul installieren wollte was Funktionen mit Namen hat welche schon in anderen Modulen existieren. Das könnte ich mit AllowClobber ignorieren.

Das Verhalten was auch in der Doku beschrieben ist das bei gleichem Namen das cmdlet was zuletzt importiert wurde gewinnt ist soweit klar. Auch könnte man alle Skripte ändern und das mit Module\Befehl fest definieren oder immer einen Import mit alias zu Beginn machen

Aber was wenn das nicht der Fall ist und die Module per Autoload geladen werden? Wie wird bestimmt welches cmdlet dann geladen wird?

When the session includes commands of the same type with the same name, such as two cmdlets with the same name, by default, it runs the most recently added command
Mitglied: 143127
143127 Mar 26, 2020 updated at 14:12:25 (UTC)
Goto Top
Zitat von @LeeX01:

Aber was wenn das nicht der Fall ist und die Module per Autoload geladen werden? Wie wird bestimmt welches cmdlet dann geladen wird?
Das neueste/aktuellste Modul gewinnt
About Command Precedence
When the session contains items of the same type that have the same name, PowerShell runs the newer item.

Deswegen sag ich immer, Leute, lernt die PS Doku von der Pike und nutzt die von MS bereitsgestellte Dokumentation, da steht eigentlich alles was man braucht face-wink