Posts Tagged ‘scheduled task’

Recently a Webroot Bug : https://community.spiceworks.com/topic/2114911-netlogon-5820-endpoint-duplicate-windows-10  and https://community.webroot.com/t5/Known-Issues-KB/Netlogon-is-not-starting-after-Reboot/ta-p/316119 Had caused Netlogon service to not start on some machines which stops group policy running. We needed to deploy the following which ran a script when it detected netlogon stopped : 

SCHTASKS /Create  /TN “System_NETLOGON_5820” /TR c:\Scripts\netstartnetlogon.cmd /SC ONEVENT /RL Highest /RU SYSTEM /EC SYSTEM /MO “*[System[Provider[@Name=’NETLOGON’] and EventID=5820]]” /F

With netstartnetlogon.cmd stored on the local machine in C:\Scripts\containing “net start netlogon”

You can deploy a schedule task remotelty using : 

SCHTASKS /Create /s %machinename%  /TN “System_NETLOGON_5820” /TR c:\Scripts\netstartnetlogon.cmd /SC ONEVENT /RL Highest /RU SYSTEM /EC SYSTEM /MO “*[System[Provider[@Name=’NETLOGON’] and EventID=5820]]” /F

Then Run it remotely using 

SCHTASKS /run /s %machinename%  /TN “System_NETLOGON_5820”

However it seemed a long method to go through all the machines with this. I used BatchPatch to deploy the netstartnetlogon.cmd files into the Folder on each machine , then used the Deploy Software/Patch/Script/Regkey to deploy and run the file : 

createscheduledtask.bat

Which containned : 

SCHTASKS /Create /TN “System_NETLOGON_5820” /TR c:\Scripts\netstartnetlogon.cmd /SC ONEVENT /RL Highest /RU SYSTEM /EC SYSTEM /MO “*[System[Provider[@Name=’NETLOGON’] and EventID=5820]]” /F
SCHTASKS /Run /TN “System_NETLOGON_5820”

VN:F [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

When running a bat file scheduled task coming back with 0x2 

You need to put the exit of the IF statement to exit 0

VN:F [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

powershell2xa4

Param(
[string]$foo,
)

./Powershellscript.ps1 -foo "Bar1 bar2/ Bar3/Bar4"

When I ran the above as a scheduled task the output I would get for $foo is Bar1 bar2/ Bar3

When I ran the below as a scheduled task ( Single Quotes ) the output I would get for $foo is Bar1 bar2/ Bar3/Bar4 (Correct )

./Powershellscript.ps1 -foo 'Bar1 bar2/ Bar3/Bar4'

So why?

When you run powershell.exe from inside Powershell you are forcing the arguments to go through the old Windows style command line processing.

This way all of the arguments will pass right through without being converted to strings, having double quotes stripped and then being re-parsed.

VN:F [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)