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
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.
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
Can't Load PhpMyadmin On After Server Update
Redirect www to non-www in Apache Conf
How To Check If Your SSL Cert Is SHA 1
Windows TrackPad Gestures