Skip to main content
The 2024 Developer Survey results are live! See the results

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

5
  • 1
    What's wrong with using the PowerShell code?
    – DavidPostill
    Commented May 15, 2021 at 20:35
  • @DavidPostill I would preferred to use PowerShell but the script won't run on the remote computers because of PowerShell version on those remote computers. Commented May 15, 2021 at 20:48
  • 3
    As for this I would preferred to use PowerShell but the script won't run on the remote computers because of PowerShell version on those remote computers., then write the script to the lowest version of PowerShell in your environment, or write your script to have code segments for each version in your environment, check the version and run that branch. There is zero reason to flip to batch for this, if PowerShell (any version) already exists on hosts. I am not seeing anything in the posted script as being version-specific, other than Wait-Process. Start-Process has a -wait switch.
    – postanote
    Commented May 15, 2021 at 23:06
  • There is not a native way to do that wait-process with a timer thing in batch either; not without writing more code. Since you are already trying to do that in a batch file, just refactor your script for the lowest version in your environment. You should be writing code that is to run in your environment, not what's on your personal host. Powershell v2 cmdlets
    – postanote
    Commented May 15, 2021 at 23:10
  • 1
    Following on from @postanote if you need to test if your script is compatible with version 2 on your local machine you can execute the script using the following powershell -version 2 <Path-to-Script>, this may need some windows features enabling to accomplish (been a while since I have done this myself). Please note that the version switch is only able to accept the value of 2 otherwise it will try to run with the latest version.
    – CraftyB
    Commented May 16, 2021 at 10:09