2017-01-13 5 views
-1

작업 스케줄러에서 PowerShell 스크립트를 실행하는 데 문제가 있습니다. PowerShell ISE에서 스크립트를 만들었으므로 제대로 작동합니다.PowerShell vs PowerShell ISE

그러나 PowerShell에서 실행할 때 실수가 있다고보고합니다.

왜 이러한 일이 발생할 수있는 아이디어가 있습니까?

나는

powershell_ise.exe -File D:\script.ps1 

또는

powershell.exe -File D:\script.ps1 

에 단 한 줄의 파일을 만들려고했지만 그 어느 것도 작동합니다. 정책을 확인했지만 제한이 없습니다.

나는 PowerShell을 ISE에서

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NonInteractive -Command d:\Script.ps1 

를 실행하려고하고 그것을 잘 작동합니다. 내가 PowerShell에서 실행하면

는 오류 보여줍니다 -format에 대한

The term '▬' 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:1 char:1
$datetime = Get-Date -f yyyMMdd 

$strFileName = "c:\test\BS_" + $datetime + ".txt" 

if (Test-Path $strFileName) { 
    exit 
} else { 
    exit 
} 

... 
+1

'몇 가지 실수를보고합니다.'라는 오류 메시지가 무엇인지 궁금합니다. 그것들이 그 문제와 관련이 없다고 생각하는 것 같습니다. 왜 그런가요? – vonPryz

+0

.ps1 파일이 대시'- '로 시작합니까? – vonPryz

+0

아니요, BS_test.ps1 – HeadOverFeet

답변

0

get-date cmdlet을하지 않고 별칭

아래 구문을 사용하십시오

$datetime = Get-Date -format "yyyyMMdd" 
+0

당신은 옳았습니다, 실수는 "-"이었지만, -f와 함께 잘 작동합니다 : – HeadOverFeet

+0

위의 코드로 무엇을 달성하려고합니까? – YanivK

0

문제는

입니다.
$datetime = Get-date -f yyyymmdd 

내가 틀린 "-"을 사용했습니다. 조언을 해주셔서 감사합니다.

관련 문제