Link to home
Start Free TrialLog in
Avatar of Luis Diaz
Luis DiazFlag for Colombia

asked on

Powershell: disable enable windows task of windows scheduler

Hello experts,

I have access to different VM's. I was wondering if there a way through powershell to disable the various windows tasks of windows scheduler by reporting the IPs in a txt file.

Thank you in advance for your help.
Avatar of Alex
Alex
Flag of United Kingdom of Great Britain and Northern Ireland image

Something like this

$ips = Get-content C:\temp\ip.txt

Foreach ($IP in $IPS){ Invoke-command -computername $ip -scriptblock {Get-scheduledtask | export-csv c:\temp\$IPscheduledtask.csv}}

Open in new window


I think that should work, it'll rely on WinRM being enabled.

Regards
Avatar of Luis Diaz

ASKER

Thank you for your help. Prior to run this I would like to make sure that -scriptblock is the argument, isn't?
SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you very much. I will test it and keep you informed.

I tested and it works!

I was having some issues by finding line 19 to disable for real but finally I realize that line to uncomment is the following:

$null = $task | Disable-ScheduledTask -ErrorAction Stop

Open in new window



Last question, f I want to use the script to apply the opposite approach (enable windows tasks), could you please let me know which are the lines to modify?


Thank you for your help.

ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

Noted, I will test it and keep you informed.

I tested disable and enables tasks and they work!
Thank you very much for your help!