I am having a very specific issue with scheduling a PowerShell script to run with Task Scheduler in Windows 2012 server. The script works as expected from the PowerShell ISE console. The script is checking the size of C:\ and a particular log folder size and if the log folder size is more than 20 GB then it clears the logs of the folder with the help of application.
The stop application stops 3 of the particular services and while starting the start application undergoes a interactive session with CMD and if we press y and enter , it will clear the logs and start those 3 services.
Then it will send the mail the output.
The issue is, if i start the script from powershell console it complete successfully as expected but if i do the same from task scheduler then only the start application is not executing and the task is getting completed with stop application and sending the mail. The middle part is not happening.
$cdrive = $NULL
$cdrive = gwmi win32_logicaldisk -Filter "DeviceId='C:'"
if($percentage -gt 50)
$logsize = [math]::Round((Get-ChildItem C:\HPE\HPSS\pa\tomcat\logs -Recurse | Measure-Object -Property Length -Sum -ErrorAction Stop).Sum / 1GB,0)
if($logsize -lt 10)
$cdrive1 = gwmi win32_logicaldisk -Filter "DeviceId='C:'"
$percentage1 = [math]::Round($cdrive1.FreeSpace/$cdrive1.Size * 100,0)
$SMTPSRV = "xyz.abc.net"
Script has cleared the HP performance unused logs from the path C:\HPE\HPSS\pa\tomcat\logs and below is the output of C: drive.
Before log deletion
After Log Deletion
Send-MailMessage -To $EmailTo -Subject "HP Performance advisor log status" -From $EmailFrom -Body $MyReport -SmtpServer $SMTPSRV
$percentage2 = [math]::Round($cdrive2.FreeSpace/$cdrive2.Size * 100,0)
$logsize1 = [math]::Round((Get-ChildItem C:\HPE\HPSS\pa\tomcat\logs -Recurse | Measure-Object -Property Length -Sum -ErrorAction Stop).Sum / 1MB,0)
C: drive freespace is < 50% but the HP Performance log folder "C:\HPE\HPSS\pa\tomcat\logs" is not occupied more than 10GB. Current size of the log folder is $logsize1 MB. "@ Send-MailMessage -To $EmailTo -Subject "HP Performance advisor log status" -From $EmailFrom -Body $MyReport -SmtpServer $SMTPSRV } } Task Scheduler information tried: Progrm/Script: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe Arguments : -ExecutionPolicy RemoteSigned/ByPass/Unrestricted -File D:\ClearDBlog.ps1 this is the exception i am getting while executing manually but script works as usual. exception calling : process '1990' is not found.
Do you have Task Scheduler configured to run the script under a specific user account, or just SYSTEM?
I have created one specific local user account for this called svc_user.
try using ServiceUI.exe (included in the MDT) in your scheduled task run as system, then you should see the prompt
e.g. ServiceUI.exe -process:TSProgressUI.exe %SYSTEMROOT%\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass -File yourscript.ps1
You must be logged in to reply to this topic.