Task Scheduler failed to launch action "powershell.exe" How do i get around this?

0

My script is fairly simple. Just clearing out some AD group.

Get-ADGroupMember "ADGroup1" | ForEach-Object {Remove-ADGroupMember "ADGroup1" $_ -Confirm:$false}

Get-ADGroupMember "ADGroup2" | ForEach-Object {Remove-ADGroupMember "ADGroup2" $_ -Confirm:$false}

Get-ADGroupMember "ADGroup3" | ForEach-Object {Remove-ADGroupMember "ADGroup3" $_ -Confirm:$false}

My Actions are also pretty straight forward. And I do have run with highest privileges checked. However i keep getting "Action Failed to start", followed by "Task Failed to start" error and Last Result as "Directory name is invalid(0x8007010B) Any help is greatly appreciated. I am running it on Windows 10. thanks enter image description here

powershell
task
taskscheduler
windows-task-scheduler
asked on Stack Overflow Dec 30, 2020 by DanielJ

2 Answers

1

In powershell 5.1 powershell.exe with no parameter defaults to -Command and you need to specify -File. If you're using powershell core 6+ it defaults to -File and you wouldn't need to specify. I've tested and confirmed you need to add at least -File for it to work. You can also clean up your script some like this.

"ADGroup1","ADGroup2","ADGroup3" | ForEach-Object {
    Remove-ADGroupMember $_ (Get-ADGroupMember $_) -Confirm:$false
}

enter image description here

answered on Stack Overflow Dec 30, 2020 by Doug Maurer
0

Could you try

Program/Script:
powershell

Add arguments:
.\ADAutomation.ps1

Start in: 
"C:\Dev\"

As you are already changing the Start in directory there is no need to call the whole filepath.

Note the commas in the start in field

answered on Stack Overflow Dec 30, 2020 by Sebastian Wiszowaty

User contributions licensed under CC BY-SA 3.0