Avatar of Maniman man
Maniman man
 asked on

Automate powershell script when system boots

Hello Everyone,

I have the following powershell script:
(Get-Content C:/sample.txt -TotalCount 1) | Set-Content C:\sample.txt
I would like the above script to execute when system boot.

Can someone please advise the best option to do so?
Thank you
Manu
PowershellWindows OSWindows Server 2012

Avatar of undefined
Last Comment
Maniman man

8/22/2022 - Mon
Muhammad Mulla

Maniman man

ASKER
Hey thank you,

I have tried that unfortunately it did not work.
PowerShell -Command "Set-ExecutionPolicy Unrestricted" >> "%TEMP%\StartupLog.txt" 2>&1 PowerShell C:/sample.ps1>> "%TEMP%\StartupLog.txt" 2>&1

But did not work, maybe am missing something.
ASKER CERTIFIED SOLUTION
Maniman man

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Maniman man

ASKER
Looking at the previous answer, plus researching on other forums, I have found the best solution to answer my own question. I have just tested it in prod environment with sucess results.
Best Regards
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy