Windows 예약 된 작업에서 매우 간단한 PowerShell 스크립트를 실행하려고합니다.Windows에서 PowerShell 실행 작업 스케줄러
내 PowerShell 스크립트는 이것이다 :
$currentTime = (Get-Date).ToString('yyyy-MM-ddTHH.mm.ss')
$contentToDump = "JLS"
$path = "$home\Desktop\resutfile_" + $currentTime + ".txt"
Add-Content $path $contentToDump
그래서 단순히 이름의 일부로 현재 시간 내 바탕 화면에 파일에 문자열 "JLS"를 씁니다.
Windows PowerShell ISE를 사용하여 실행하면 정상적으로 작동합니다. 또한 명령 프롬프트를 사용하여 실행하면 잘 작동합니다.
그러나 예약 된 작업에 연결하면 작동하지 않습니다. 작업은 유효한 ("0x0")
-result와 함께 반환되지만 파일은 생성되지 않습니다.
작업의 내 구성은 이것이다 :
Action: Start a program
Program/script: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
Add Arguments: -NoProfile -NoLogo -NonInteractive -ExecutionPolicy Bypass -Command “&{c:\Users\jls\desktop\untitled2.ps1}”
Start in (optional): C:\users\jls\desktop
작업은 "저를"가장 높은 권한으로 실행하도록 설정되어 있고 내가 관리자 오전 어디에 내 컴퓨터에서 로컬로 실행됩니다.
무엇이 누락 되었습니까? `-noprofile -nologo -NonInteractive -ExecutionPolicy 바이 패스 - 파일 "C : \ 사용자
당신의 인수 대신 명령의 파일 PARAM를 사용해보십시오에
-File
와-Command
를 교체해야 \ jls \ desktop \ untitled2.ps1 "' –디버깅을 위해 $ path = 'C : \ users \ jls \ desktop \ resultfile _'+ ... –
과 같은 전체 경로를 넣고 스크립트 행에 추가하십시오. content 'c : \ users \ public \ homevalue.txt'$ home 그리고 실행 후 내용을 확인하십시오 –