Почему следующий код не работает? Согласно этой статье, использование глобальной должно быть правильным: http://technet.microsoft.com/en-us/library/ff730957.aspxPowerShell и глобальные функции
Function global:writeLog {
param($logType, $logString, $logFile)
$fileStream = New-Object IO.FileStream $logFile ,'Append','Write','Read'
$streamWriter = New-Object System.IO.StreamWriter $fileStream
$time = get-date -Format "hh:mm:ss"
$streamWriter.writeLine("[${time}][$logType] ${logString}")
$streamWriter.close()
}
$temp = {
writeLog -logType "INFO" -logString "Test" -logFile "d:\scripts\powershell\logtest.txt"
}
Start-Job -ScriptBlock $temp
get-job | receive-job -AutoRemoveJob -Wait
Это исключение, которое Powershell бросает
The term 'writeLog' 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 : ObjectNotFound: (writeLog:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
+ PSComputerName : localhost
ли ваш '$ {темп WriteLog ...}' существует для чего-нибудь, кроме передачи аргументов? Вместо этого передайте аргументы непосредственно из «Start-Job» в функцию, используя параметр «ArgumentList», пропуская среднего человека. –