Skip Posted February 6, 2020 Posted February 6, 2020 Hello, In the past I use to make Batch startup scripts run only once by creating a .txt file somewhere on the C: drive at the end of the script, the first line of the script would check if the file exist and then quit the script. This way I made sure that the script will run only once. Now I have a PS command line that fixes AppX on Windows 10, I need to achieve the same but only that this time it has to run as a Powershell script. I have tried to run the Powershell from with in a batch file: "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -executionpolicy bypass -NoProfile -file "C:\SoftwareInstall\CalcFix.ps1" But that doesn't work. Will be extremely useful if I could have a Powershell script that can do the same as what I've used to do in my Batch scripts. Thanks
tri_94 Posted February 24, 2020 Posted February 24, 2020 Hi there You could use something on the lines of the code below. So it will check if the a text file is present. If not it will run whatever code you add. Then it will create a text file Thanks $Location = "Replace with File Location" # Testing For File Named 1.txt In The Above Location if (!(test-path -PathType Leaf -Path "$Location\1.txt")) { #Here you will need the code in which you require# # Creating a File Named 1.txt New-Item "$Location\1.txt"
HPlum78 Posted February 24, 2020 Posted February 24, 2020 Another take on the above would be to create a reg key and then check if its there or not
mavhc Posted February 24, 2020 Posted February 24, 2020 I'd write the logs to a central store, and check that store, then a) you can check if it works, b) you can easily delete them to rerun
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