discoveranother Posted July 28, 2018 Posted July 28, 2018 Hi all, I've created the following Powershell script Restart-Service -Name NlaSvc -Force to restart the Network Locations Services but can't get it to work via scheduled task. If I run the powershell command manually it works fine. I'm wanting the command to run once the server is booted up. It doesn't have to be logged in. Any help much appreciated. Thanks.
sparkeh Posted July 28, 2018 Posted July 28, 2018 Ah is this to do with the network profile not being set to domain after reboot? Can you post a screenshot of what you have setup in the scheduled task for when you call the PS script?
discoveranother Posted July 29, 2018 Author Posted July 29, 2018 Ah is this to do with the network profile not being set to domain after reboot? Can you post a screenshot of what you have setup in the scheduled task for when you call the PS script? Yes that is correct. I’ll post the screenshot up of the task scheduler. Yes the network card shows Unidentified network. Two cards, teamed as one.
discoveranother Posted July 30, 2018 Author Posted July 30, 2018 Ah is this to do with the network profile not being set to domain after reboot? Can you post a screenshot of what you have setup in the scheduled task for when you call the PS script? Hi, Please see scheduled task screenshots. I've blacked out the irrelevant bits but the relevant settings in task scheduler can still be seen. Many thanks
Arthur Posted July 30, 2018 Posted July 30, 2018 Please see scheduled task screenshots. Since you are only running a single command, try the following in the settings for the action. Program/script C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe Arguments -Command "Restart-Service -Name NlaSvc -Force" 1
sparkeh Posted July 31, 2018 Posted July 31, 2018 @Arthur ‘s idea is the easiest way. If you did want to call a script I’d be looking at the event log to see what error is it’s throwing. I’m thinking that you might have an issue with option not to store password being ticked and with PS code execution level. I usually put in an argument to set code execution level to run unsigned code just to make sure.
free780 Posted July 31, 2018 Posted July 31, 2018 Assuming the support account has administrator rights. I always find using a Start-Transcript and Stop-Transcript to a log is helpful when getting permissions correct. Also be aware of execution policy. You may need to sign your script or use the bypass switch. It depends on the environment.
Arthur Posted July 31, 2018 Posted July 31, 2018 I usually put in an argument to set code execution level to run unsigned code just to make sure. If the task was ran using the "NT Authority\SYSTEM" account could the OP get away with the following arguments? -NoProfile -NonInteractive -ExecutionPolicy Bypass -Command "Restart-Service -Name NlaSvc -Force"
sparkeh Posted July 31, 2018 Posted July 31, 2018 If the task was ran using the "NT Authority\SYSTEM" account could the OP get away with the following arguments? -NoProfile -NonInteractive -ExecutionPolicy Bypass -Command "Restart-Service -Name NlaSvc -Force" Off the top of my head yes that looks like it would work
discoveranother Posted August 3, 2018 Author Posted August 3, 2018 Since you are only running a single command, try the following in the settings for the action. Program/script C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe Arguments -Command "Restart-Service -Name NlaSvc -Force" That works. Thanks very much. Well done.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now