2016-07-11 16 views
0

Ich habe eine Reihe von Funktionen, die innerhalb und außerhalb eines Workflows in einem Powershell-Skript aufgerufen werden müssen, das einen Workflow zum Verwalten von Remotecomputern verwendet. Ich habe versucht, ein Modul zum Inline passieren, aber die Methode unter dem Inline-Skript kann nicht die dynamischen Module „SharedFunctions“ findenAufruf von Funktionen in Workflows in Powershell 4.0

#Script Only Functions 
function funct1 {} 
function funct2 {} 

#Script and Workflow Functions 
New-Module SharedFunctions { 
    function sharedFunct1 {} 
    function sharedFunct2 {} 
} -Name SharedFunctions | Import-Module 

#Workflow 
workflow w1 { 
    Param([string[]] $computerList) 

    foreach -parallel($computer in $computerList){ 
     #Shared Function out of Inline Script 
     sharedFunct1 


     InlineScript{ 
      #Shared Function inside InlineScript 
      sharedFunct2 
      #Do stuff 
     } -PSRequiredModules "SharedFunctions" 
    } 
} 

<# Local Script #> 
funct1  
sharedFunct1 
w1 

ich die Fehlermeldung

The specified module 'SharedFunctions' was not loaded because no valid module file was found in any module directory. 
    + CategoryInfo   : ResourceUnavailable: (FunctionModule:String) [Import-Module], FileNotFoundException 
    + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand 
    + PSComputerName  : [localhost] 

ich, dass Module lesen kann in Workflows importiert werden. Ist das mit Dynamic Modules nicht möglich? Wie kann ich gemeinsame Funktionen innerhalb des Workflows aufrufen? sharedFunct1 kann eine Aufgabe sein, z. B. das Aktualisieren einer Protokolldatei auf dem Hostcomputer mit Updates von jedem Thread, der auf Remotecomputern ausgeführt wird.

Antwort

0

Es scheint, dass das Importieren von Modulen nur aus der Datei und nicht aus dem Speicher erfolgen kann. Dies scheint den Trick getan zu haben - Datei 1 -

<# MAIN.PS1 #> 
function funct1 {} 
function funct2 {} 

#Workflow 
workflow w1 { 

    Param([string[]] $computerList) 

    $modDir = "Some Directory" 
    Import-Module $$modDir 

    foreach -parallel($computer in $computerList){ 
     #Shared Function out of Inline Script 
     sharedFunct1 


     InlineScript{ 
      #Import module in each Inline Script 
      Import-Module $using:$modDir 

      #Shared Function inside InlineScript 
      sharedFunct2 
      #Do stuff 
     } 
    } 
} 

<# Local Script #> 
funct1  
sharedFunct1 
w1 

File 2 -

<# MODULE.PSM1 #>  
#Script and Workflow Functions   
function sharedFunct1 {} 
function sharedFunct2 {} 

Allerdings würde ich bevorzugen, nur eine Datei zu bleiben also, wenn jemand weiß, wie dynamische Module in Workflows importieren Ich würde es sehr gern sehen.