Я уже задал несколько смежный вопрос here.Как импортировать функции в отдельные файлы в основной файл и запускать их в качестве заданий?
У меня есть куча функций в отдельных файлах, найденных в одном основном файле, как бы я назвал эти функции в основном файле заданиями?
Вот func1.ps1:
function FOO { write-output "HEY" }
Здесь func2.ps1:
function FOO2 { write-output "HEY2" }
Вот testjobsMain.ps1
$Functions = {
. .\func1.ps1
. .\func2.ps1
}
$var = Start-Job -InitializationScript $Functions -ScriptBlock { FOO } | Wait-Job | Receive-Job
$var
Когда я бегу testjobsMain.ps1 я получаю эта ошибка:
. : 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
Вы пробовали с полными (не относительными) дорожками? То есть: '. c: \ func1.ps1' –
Черт, это было все, что было. Есть ли способ, которым я могу использовать относительный путь к файлам функций? Все они будут в одной папке. – red888
См. Мой ответ ниже. Поверьте мне, у меня много боли с относительными/абсолютными путями PS. –