Powershell script with task scheduler not working
I created a PowerShell script to email if it’s detected a new user account is added to the domain admin group within our AD. It works when I run through the PowerShell window but does throw an error. I am trying to automate and run it every 5 minutes until the user is removed from the domain admins group through task scheduler on our domain controller. Below is my code and beneath it is the error that it throws as well but as mentioned before it does run successfully when ran through a PowerShell window.