I have a bat file that needs to run in powershell, via the start-process command is slow - windows

I have a powershell script that runs a bat file, it has to run in powershell as it is being called by an application that can only run powershell (not bat files)
I use the Start-Process command
start-process -FilePath D:\versioned\pf_trunk\deployment\environments\development\aws\deployment\awx\development\files\PublishMYPlanetFootprint.bat -Wait
The batch file runs some visual studio builds and then moves some files.
If I run the batch file on its own, it runs and completes and closes the command window.
When I run it in powershell, it runs, completes and closes the command window, however the script continues to run for another 17 minutes before timing out.
I thought the wait would only wait for the bat to finish and then terminate.
Can somebody help with my powershell. What am I missing to ensure the script terminates on completion of the bat file operation.
Thanks

Related

Batch file of powershell commands runs in cmd not in powershell terminal

I made a batch file to run with admin right in windows powershell, it opens a powershell but runs in another cmd windows. I saved the batch file with *.ps1 but it did not work.

Continue With CMD Commands After Batch Script

I am trying to write a batch script which, once complete, would allow the user to continue using the Windows command prompt as they normally would had no script been run. Is this possible? Thank you in advance for any help.
If you manually open CMD (the Command Prompt) and invoke the batch file by name, CMD will remain open for additional commands after the batch file completes. You cannot do this by double-clicking on the batch file, but if you create a shortcut to the batch file that runs CMD.EXE with the /K switch, you will run the batch file and then leave CMD running for additional commands. See CMD at SS64.

Executing .bat files from Powershell via Ansible

I am using Ansible to execute a Powershell script on several Windows hosts. In the Powershell script, I am using Start-Process -FilePath "cmd.exe" -ArgumentList "C:\Path\to\some\bat\file.bat"
The bat files are several programs that run indefinitely.
The issue I'm having is that when I run the Powershell script manually, everything works. The bat files are executed and done. When I execute the file via Ansible, the bat files are not executed. No errors reported that I could find.
Any idea how I can get these two bat files up and running via Ansible?
Thanks.
use win_command
- name: Simple batch script
win_command: "C:\Path\to\some\bat\file.bat"
You can use win_shell too.

How to "open with" in a batch file

I have a windows powershell script that will be available on a server to my users. I don't want them to have to go out and find the PS script, right click and click "run with powershell" or do an "open with". The Windows (Win 7 at least) default program is notepad.
I want to make a batch file to do this. I've tried:
start "c:\myfile.ps1" powershell.exe
and a few other variations, but all I've been able to do is either start powershell, or open my file in its default program, notepad.
Any advice is appreciated! Thanks!
Bonus question: If I run my batch file as administrator will it also run my PS script as administrator?
Simply use the -file argument for PowerShell.exe in your batch file:
PowerShell.exe -file c:\MyFile.ps1
Additionally, some users may have their Execution Policy set to something that would restrict scripts from being executed, so you may want to do something like:
PowerShell.exe -ExecutionPolicy Bypass -file c:\MyFile.ps1
If you would like to use start to launch it you can do so as Ansgar Wiechers noted by running:
start "" PowerShell.exe -ExecutionPolicy Bypass -file c:\MyFile.ps1
Some notes regarding using start: By default it will launch PowerShell in a separate window, and continue to execute the rest of the batch file without waiting for the PowerShell window to close. If that is undesirable you have two options. You can specify /wait which will wait for the PowerShell window to close before continuing the batch file, or you can use the /B option will will not open a new window, and will execute PowerShell in the current console window.
And finally, yes if your batch file is run under the Administrator context, PowerShell will be as well.

Running sysinternals strings.exe command in Jenkins batch command hangs

I have a windows batch command in Jenkins as a build step, and I'm doing this:
CMD /C strings.exe a.bin
And it just sits there and spins forever. I cannot get it to work. I have put it in a batch file, I have tried running it with start, nothing seems to work. How do I get this to work?

Resources