12

Is there a tool that can convert a batch file into a powershell script?

My issue I'm having with batch files is that they are not running from the task scheduler, unless I stay logged in, and I'm hoping that a conversion to Powershell may obviate this.

7
  • 5
    Sounds like an XY Problem. Dec 12, 2014 at 0:02
  • Have you tried setting "Run whether logged in or not" in Task Scheduler? Dec 12, 2014 at 0:09
  • I have checked run if not logged in. I might use a powershell to launch there batch file. Dec 12, 2014 at 0:10
  • I am thinking that I will have to schedule a task that runs every day on another machine that launches an RDP file with a saved password, to stay logged in on the first machine. I've heard that this is caused by microsoft adding session 0 security in windows vista and newer. The irony is that the workarounds decrease security: I have to stay logged in on another machine to run the task that logs in to the machine that runs these tasks! Dec 13, 2014 at 0:15
  • There's another options that I haven't tried yet: "run hidden". Dec 13, 2014 at 0:21

3 Answers 3

3

At this time there's no magic converter. However, there are tools you can utilize that will help you convert your batch scripts. One such tool is the Powershell ScriptoMatic.

http://technet.microsoft.com/en-us/library/ff730935.aspx

3

To run or convert batch files externally from powershell (particularly if you wish to sign all your scheduled task scripts with a certificate) I simply create a powershell script e.g deletefolders.ps1

Input the following into the script:

cmd.exe /c "rd /s /q C:#TEMP\test1"

cmd.exe /c "rd /s /q C:#TEMP\test2"

cmd.exe /c "rd /s /q C:#TEMP\test3"

*Each command needs to be put on a new line calling cmd.exe again.

This script can now be signed and run from powershell outputing the commands to command prompt / cmd directly.

A much safer way then running batch files!

1
  • How to do Command line to PowerShell?
    – zeitgeist
    Sep 26 at 14:36
0

This is easily fixed. create a group, and user in that group, as a service account. I actually called mine service.account. Make the task run as this user. No matter what you use, batch, vb, powershell, etc, it will run. Now, you need to setup the account to secure against it being used by someone, using policy and some very simple methods. Use a log on script for the account that logs when this account is used, where it is used, and what time, etc....Setup a script that collects and stores this log, (straight text is best) and deletes upon a certain age. It takes a little watching, but youll know if it gets used. Do not share your task account info with ANYONE who doesnt absolutely need it. My techs did not know what mine were. Because at one point early in the pit we all call systems security, I did share it with a tech that would not allow the tech to have admin access on the box, it spread like wildfire.

3
  • I am assuming you know the other portions of doing all this.
    – user258203
    Mar 30, 2018 at 16:41
  • Also, back then, I used bat2exe, and molebox pro to produce an encrypted, packed exe. Molebox pro is a VERY useful program.
    – user258203
    Mar 31, 2018 at 1:00
  • 1
    The guy that posted the following "To run or convert batch files externally from powershell (particularly if you wish to sign all your scheduled task scripts with a certificate) I simply create a powershell script e.g deletefolders.ps1 Input the following into the script: A much safer way then running batch files!" is very clever.....that is a great way to run the scripts...good idea...!
    – user258203
    Mar 31, 2018 at 1:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .