Jump to content

Recommended Posts

Posted

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

  • 3 weeks later...
Posted

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"

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 account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...