Question [Tutoriel]Les modules sous Powershell

Plus d'informations
il y a 11 ans 6 mois #12702 par Laurent Dardenne
Salut,
voici un tutoriel sur l'usage et la conception de module .

Le sommaire :

1 PREREQUIS 4
2 LA NOTION DE MODULE 4
2.1 LE MODULE, UN SCRIPT COMME UN AUTRE ? 4
3 USAGES ET CREATION D’UN MODULE 5
3.1 LISTER LES MODULES CHARGES EN MEMOIRE 5
3.2 LISTER LES MODULES DISPONIBLES 5
3.3 IMPORTER UN MODULE 6
3.4 SUPPRIMER UN MODULE 7
3.5 FORCER LE CHARGEMENT D’UN MODULE 7
3.6 AJOUTER UN CHEMIN DE RECHERCHE DE MODULE 8
3.6.1 Configurer la variable PSModulePath 9
3.7 EXPORTER DES MEMBRES D’UN MODULE 9
3.7.1 Portée d’une variable 10
3.7.2 Exporter des membres d’un module 12
4 DEVELOPPEMENT D’UN MODULE DE SCRIPT 12
4.1 L’OBJET MODULE 12
4.2 RETROUVER LE CHEMIN DU MODULE 13
4.3 CODE D’INITIALISATION 14
4.4 CODE DE FINALISATION 14
4.5 LOCALISATION D’UN MODULE 15
4.6 CONVENTION DE NOMMAGE DE FONCTION 16
4.7 MODULE EN LECTURE SEULE 16
4.8 FICHIER D’AIDE DE MODULE 16
4.9 CHARGEMENT DE SCRIPTS EXTERNES 17
4.10 GESTION DES ERREURS 18
5 MODULE DYNAMIQUE 18
5.1 UN MODULE COMME OBJET 18
5.2 AJOUT DE MEMBRE PERSONNALISE 19
6 MANIFESTE DE MODULE 19
6.1 LISTE DES CLES D’UN FICHIER MANIFESTE 20
6.2 PRECISIONS SUR LE COMPORTEMENT ET L’USAGE DE CERTAINES CLES 22
6.2.1 Export keys 22
6.2.2 ModuleVersion 22
6.2.3 GUID 23
6.2.4 PowerShellHostVersion 23
6.2.5 RequiredModules 23
6.2.6 RequiredAssemblies 24
6.2.7 NestedModules 24
6.2.8 PrivateData 24
7 MODULES IMBRIQUES 25
7.1.1 Ordre de chargement 25
8 DEVELOPPEMENT D’UN MODULE BINAIRE 26
8.1 MASQUAGE DE CMDLET (SHADOWING) 27
8.2 RAPPEL DES TYPES DE MODULE 27
9 ÉTAT DE SESSION WINDOWS POWERSHELL 28
9.1 L'ETAT DE SESSION D’UN MODULE 28
9.2 DES DONNEES A PORTEE DE MAIN 29
9.2.1 Liaison de scriptblock à une session de module 31
9.2.2 Accès à l’état de session de l’appelant 32
9.3 PARAMETRER UN MODULE A L’AIDE D’ARGUMENTS 32
9.4 IMPORT D’UN MODULE DANS LA SESSION GLOBALE 33
10 MODULE ET REMOTING IMPLICITE 33
11 CONCLUSION 34


Archive des sources et du fichier .pdf .

Bonne lecture.

[edit]
Can advanced functions be added to custom objects ? Exemple de création d'objet via un module.

Deep Dive video: PowerShell Modules by Dan Harman

Avec la v3 la clé RequiredModules importe les modules indiqués :

-RequiredModules <Object[]>
Specifies modules that must be in the global session state. If the required modules are not in the global
session state, Windows PowerShell imports them. If the required modules are not available, the Import-Module
command fails.

Enter each module name as a string or as a hash table with ModuleName and ModuleVersion keys. The hash table
can also have an optional GUID key. You can combine strings and hash tables in the parameter value. For more
information, see the examples.

In Windows PowerShell 2.0, Import-Module does not import required modules automatically. It just verifies that
the required modules are in the global session state.

Importer un module d'un .exe

Message édité par: Laurent Dardenne, à: 20/12/12 14:26

Message édité par: Laurent Dardenne, à: 3/01/13 22:02

Message édité par: Laurent Dardenne, à: 16/08/16 15:10<br><br>Message édité par: Laurent Dardenne, à: 9/08/18 17:20

Tutoriels PowerShell
Les utilisateur(s) suivant ont remercié: LaGirafe

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 11 ans 6 mois #12706 par Matthew BETTON
Bonsoir Laurent,

Bravo et un Grand Merci !

@ +

Matthew

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 11 ans 6 mois #12708 par Richard Lazaro
Pas mieux.

Think-MS : (Get-Life).Days | %{ Learn-More }

\\&quot;Problems cannot be solved by the same level of thinking that created them.\\&quot; - Albert Einstein

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 11 ans 6 mois #12709 par SiSMik
Salut,
J'ai lu en diagonale, ça mérite une lecture plus approfondie, mais ça m'a l'air tout bien.

Bien joué!

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 11 ans 6 mois #12721 par Laurent Dardenne
Salut,
benduru écrit:

ça mérite une lecture plus approfondie

Vaut mieux :)
Surtout il faut pratiquer autour des exemples de code.
Et comme me l'a fait remarqué Richard, la mise en oeuvre du versionning de module est à étudier sérieusement. On peut le faire, reste à en connaitre les limites. De mon côtè je ne l'ai pas encore implémenté.

Je vous fournirais deux exemples supplémentaires sur l'état de session.<br><br>Message édité par: Laurent Dardenne, à: 21/09/12 10:05

Tutoriels PowerShell

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 11 ans 5 mois #12812 par Laurent Dardenne
Une fonction de création de module à partir de méthodes statiques d'une ou + classes, ConvertTo-Module .

Tutoriels PowerShell

Connexion ou Créer un compte pour participer à la conversation.

Temps de génération de la page : 0.096 secondes
Propulsé par Kunena