How to run PS script at logon time when it requires elevation

I have a small LAN based network of PCs (some VMs) which fail to correctly publish their resources when first started. I can start them manually using PS Restart-Service FDResPub. I want to have this run automatically when the user first logs on. I had been using sc.exe stop FDResPub followed by sc.exe start FDResPub but found that it needed a pause between the commands or the start would not work, the stop not having completed. I tried to change this cmd file into a PS script but now find that it does not run. The executionpolicy for PS is set to remotesigned. If I use PS as administrator the restart-service FDResPub works but not if I run PS unelevated as seems to be the case when it is run by the task scheduler.
How do I correct my script which contains only the Restart-Service FDResPub.
I have seen the blog post about self elevating a script but I cannot get it to work.

Alan,
Welcome to the forum. :wave:t4:

Instead of putting effort into workarounds I’d try to figure out the root cause.

So you should run the script elevated.

And BTW you can set the executionpolicy for the instance you start on the command line with PowerShell.exe -ExecutionPolicy Bypass. :wink:

You actually do not need a script. Provide the command you want to be executed on the command line.

Please run

PowerShell.exe /?

To learn about the command line arguments of the PowerShell executable.

I see you mention a Scheduled Task. One way to run that elevated is to have it run as the SYSTEM account. Also, no need to store creds when using this account.

@Olaf, Thanks for the welcome I hope to become a useful member but I have a lot to learn…
The problem with finding the root cause of the failure is I do not know where to start but will follow up in other forums more appropriate to Windows 10.
I am studying PowerShell.exe /?.
@tonyd, Thanks for the pointer about the SYSTEM account.

@Olaf I have read the help provided by PowerShell.exe /? but have difficulty in including all the parameters needed in the task scheduler to start PowerShell at logon time. I still think that it would be better to use a script called at logon time to achieve my required command restart-service fdrespub.

@Olaf Additional info. I have tried to identify why the publication of devices is not happening, without success. I think I need something which could track the execution of the start up process and log the failure. The setting of the start-up type of the service is Automatic or Automatic (Delayed) neither of which solves the problem of the running status of the service but no publishing of the resources. I think this is more of a Windows 10 problem and I am pursuing that in another place.
I have resolved the connection of the multiple machines through the Network by setting up a local account and set all the other machines to have Windows credentials to access the shared folders on the target machine and set the permissions on those folders to allow all access for that local account only.
I am slowly getting there!