Troubleshooting a Scheduled Task Not Running My PowerShell Script

0
0
Asked By TechieFrog77 On

Hey everyone! I'm having a bit of trouble with a PowerShell script I created that pulls information about expiring applications and sends it via email. It runs perfectly fine when I execute it manually, but when I configure it to run as a scheduled task using a gMSA account, I'm not receiving the expected CSV file or email notification. Here's the relevant part of the code I'm using:

```powershell
$Action = New-ScheduledTaskAction -Execute "PowerShell.exe" -Argument "-File C:ScriptsAppRegWithExpCertSecrets.ps1"

$Trigger = New-ScheduledTaskTrigger -Weekly -DaysOfWeek Monday -At 9am

Register-ScheduledTask -TaskName "AppExpiringCertsAndSecrets1" `
-Action $Action `
-Trigger $Trigger `
-Principal (New-ScheduledTaskPrincipal -UserId "xxxxgMSA_p_svrinfra$" -LogonType Password -RunLevel Highest) `
-Description "AppRegistrations_Expiring_CertsAndSecrets weekly at 9 AM"

Start-ScheduledTask -TaskName "AppExpiringCertsAndSecrets1"
```

If anyone has insights into why this scheduled task doesn't seem to produce any output, I'd greatly appreciate the help!

2 Answers

Answered By ShadowCoder88 On

I agree with the permission aspect. Sometimes logs can be elusive, so I’d suggest enabling logging for your scheduled task. You can also try using a different account that has more permissions to see if that changes the output. Test runs using both accounts might help narrow down the problem.

Answered By CodeWhiz22 On

Have you considered just creating the task manually? If the script works and you're only having an issue with the scheduled task part, that could save you a lot of hassle. Scripting the task creation is more beneficial when you need to deploy it across multiple systems, but if it's just for you, doing it manually might work better.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.