Link to home
Create AccountLog in
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
Avatar of Muhammad Mulla
Muhammad Mulla
Flag of United Kingdom of Great Britain and Northern Ireland image

Avatar of Maniman man
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
Avatar of Maniman man
Maniman man

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
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