Run command in powercli using batch - batch-file

I am planning to use batch file to run few commands in VMWare PowerCli tool. I am able to open Powercli tool by batch file. But after the tool is opened, it should automatically go to a specific folder and then run a file from that folder.
Eventually I would like this to add in Task scheduler so that it runs on specific time with no human interaction.
Is there a way to do it in batch or cmd? Any help is appreciated.

If I have read the question correctly you want to run a script on a VMWare VM using PowerCLI in which case you can use the invoke-vmscript command and set the scripttype to BAT
https://www.vmware.com/support/developer/windowstoolkit/wintk40u1/html/Invoke-VMScript.html
The batch file would change the location. Alternatively you can use the copy-vmguestfile command and copy the batch file over and just use the invoke-vmscript command to run that batch file.
If the eventual goal is to have start up run the file then use the copy command and use the invoke command to update registry keys regarding startup.
https://pubs.vmware.com/vsphere-51/index.jsp?topic=%2Fcom.vmware.powercli.cmdletref.doc%2FCopy-VMGuestFile.html

Related

Automatically run .bat file after EC2 reboot without having to remote connect

I am running an AWS Windows 2012 EC2 instance that has to run 24/7. On this instance, I run a Python 3.6 scraper script and to prevent me from having to regularly check up on the server whether the file is running, I have a .bat file in the shell:startup folder of my instance, that automatically restarts it on a daily base. The .bat file works as it will run the Python script and set a timer to restart/reboot the instance after (t=86400). The .bat file runs on the EC2 instance itself.
However, what the file does not do is run automatically after the reboot. I now first have to remote connect to the server before the .bat file will run. What I want it to do is run without me having to first remote connect into the server. How can I achieve this?
I use the following code in my .bat file. Located on my EC2 instance.
#ECHO OFF
START CMD /K (
CD C:/Users/Administrator/Documents/
python scraper.py
)
START CMD /K SHUTDOWN -t 86400 -r -f
I have tried looking into using AWS' Automations and other schedule based methods but couldn't get that to work.
If you want to use something native to Windows Server 2012, look at Schtasks -- this is more or less the Windows equivalent of cron.
I found the answer to my question by using Task Scheduler and looking at the following article: Run a batch file with Windows task scheduler
An important note here is that for my batch file to run I had to create a task that started CMD and run the batch file from there. Asking Task Scheduler to run the batch file directly doesn't work on Windows Server 2012. I ran the task with the following details:
Administrator account
"Run whether user is logged on or not"
"Run with the highest privileges"
"Start on system start-up"
Action: Start a program -> CMD
Add arguments (optional): /c start "" "C:\Users\Administrator\Desktop\file.bat"
More information on how to do this can be found in this answer: https://stackoverflow.com/a/27055435/7736676

Remote exectution of bat file through Winform

There are bat files on some servers that we have. I have Winform app that can view directory files and executables on different server. Is there a way that (based on the selected bat file), to be be able to run that bat file on that server from the Winform app.
Not in the way you are thinking. If you run a batch file from your machine (via app or manually) it runs locally on your machine, not on the remote server.
If you can install software, PsExec maybe be a good fit. If not, I have a couple of options I can think of.
Alternatives: create an app that runs on the server that knows when to run the batch files (via messaging, database records, etc) or use the Windows Task Scheduler.
The Task Scheduler approach is fairly simple. You could have the batch files set to run every one minute and at the start of the batch file, you do a file check. Your WinForm would create that file and at the end of the batch (if the file existed at the start) it would delete the file that triggers the batch.

batch file run as admin registry key?

I was wondering if there is a string/value that I can add to the registry in order to always run a batch file as admin?
note: this batch file will run automatically at windows start up
This is only a project and I do not want to use any other language at this time.
Thanks in advance
The properties of the batch file can be changed to run as admin.

batch how to add schedule backup to batch files

I have a .bat file that use xcopy to pickup users pst file from document and setting then copy it to a shared drive. users always for get to double click to run it. How can I add time and date for the .bat file to run on its own. Windows build schedule doesn't work at time. thank you!
Batch files can't run on their own. Something has to launch the batch file.
You can use Windows Scheduler to schedule the running of the batch file, and then test for the time when the batch file is run in the batch file itself. If it's not the right time, the batch file can just exit; if it is the right time, the batch file can do the backup.
Scheduled tasks can run at a specified time; I have one that runs every weekday (Monday through Friday) at 8:45 AM that runs a process to retrieve files via FTP.
If you need more information about using Windows Scheduled Tasks, you should ask a question about it at SuperUser; that subject is not programming-related and would be off-topic here.
No idea what you mean by Windows build schedule doesn't work at time and you don't say when you want this backup to run - hourly? Weekly? Once a day?
What you could do is investigate the use of the AT command - that may suit you. Perhaps install a batch to run AT in your startup directory.
Or perhaps it would be better to start a hidden batch from the startup directory and use the TIMEOUT or CHOICE command to make it loop periodically.
You would need to explain your requirement in more detail.

Task Scheduler Batch File with Configuration

I'm currently using APEX Data loader to download Raw files from Salesforce.
Using the command line I can download the data that I need by simply typing the command.
Now I need to schedule the task so I don't need to do it everyday.
I run the dataloader by typing in the following
C:/Program Files (x86)/salesforce.com/data loader/bin/process.bat C:/datadownload/
C:/datadownload contains the configuration file I need to connect to Salesforce.
How can I set this thing up with Task Scheduler?
Resolved By creating another batch file... CALLing the Process.bat and adding the location of the file
Create another batch file with the same command - note the double quotes - and schedule that batch file in task scheduler. When you've done that then launch the scheduled task manually (right click on the task) to test that it works. Provide credentials and an account if it is to run when you aren't logged in.
I added the call command in case you want to add any post-processing tasks to the batch file later.
#echo off
call "C:/Program Files (x86)/salesforce.com/data loader/bin/process.bat" C:/datadownload/

Resources