Ich fragte bereits eine etwas verwandte Frage here.Wie importiere ich Funktionen in separaten Dateien in eine Hauptdatei und führe sie als Jobs aus?
Ich habe eine Reihe von Funktionen in separaten Dateien, die in einer Hauptdatei gespeichert sind. Wie würde ich diese Funktion in der Hauptdatei als Job bezeichnen?
Hier ist func1.ps1:
function FOO { write-output "HEY" }
Hier ist func2.ps1:
function FOO2 { write-output "HEY2" }
Hier ist testjobsMain.ps1
$Functions = {
. .\func1.ps1
. .\func2.ps1
}
$var = Start-Job -InitializationScript $Functions -ScriptBlock { FOO } | Wait-Job | Receive-Job
$var
Wenn ich laufen testjobsMain.ps1 ich Dieser Fehler:
. : The term '.\func1.ps1' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the
name, or if a path was included, verify that the path is correct and try again.
At line:2 char:4
+ . .\func1.ps1
+ ~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (.\func1.ps1:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
. : The term '.\func2.ps1' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the
name, or if a path was included, verify that the path is correct and try again.
At line:3 char:4
+ . .\func2.ps1
+ ~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (.\func2.ps1:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Running startup script threw an error: The term '.\func2.ps1' is not recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again..
+ CategoryInfo : OpenError: (localhost:String) [], RemoteException
+ FullyQualifiedErrorId : PSSessionStateBroken
Haben Sie versucht mit vollen (nicht relativen) Wegen? Das ist: '. c: \ func1.ps1' –
Verdammt das war alles was es war. Gibt es eine Möglichkeit, den relativen Pfad der Funktionsdateien zu verwenden? Sie werden alle im selben Ordner sein. – red888
Siehe meine Antwort unten. Ich habe eine Menge Schmerzen mit PS relativen/absoluten Pfaden, glaub mir. –