Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 267
  • Last Modified:

powershell command

Hi guys,

I need to start a batch file on a remote server,

i have typed cd cd \\server-exam01\c$\mtl\
and then tried invoke start-docprint.bat

however this does not work, please help!
0
chgl
Asked:
chgl
  • 8
  • 4
  • 2
1 Solution
 
footechCommented:
Do you have PowerShell Remoting enabled on the remote computer?  If so, you can use something like below:
Invoke-Command -ComputerName somecomputer -ScriptBlock { \\server-exam01\c$\mtl\start-docprint.bat }

Open in new window


Otherwise, you could use something like psexec for this.
0
 
chglAuthor Commented:
what if i want to open an exe file, or a jpeg, etc??
0
 
chglAuthor Commented:
hi,

i dont have powershell remoting enabled .

regards,
k
0
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 
QlemoC++ DeveloperCommented:
Please think about your request. What is the motivation behind opening a JPEG remotely, or anything needing interaction in a window? Console applications are different, of course, as you can control them remotely.
Amyway, it wouldn't matter - you just start the application, in most cases you can even "start" a file if it has an application associated with it.

If you do not have PS Remoting available, or do not want to use it, psexec as mentioned is your choice. You can get it from Sysinternals (http://technet.microsoft.com/en-us/sysinternals/bb897553). Syntax for the example is
psexec \\server-exam01 c:\mtl\start-docprint.bat

Open in new window

0
 
chglAuthor Commented:
thank you for your answer, my primary motivation or intent or objective is simply to learn
0
 
chglAuthor Commented:
ive unzipped psexec, however it doesnt do anything when i type psexec in powershell or the command prompt?
0
 
footechCommented:
You need to be in the same folder as the psexec.exe file, or else reference the full path to it.  If you're in the same folder, just typing "psexec" will give you the help information for the utility.
0
 
chglAuthor Commented:
sorry i dont understand, the folder contains cmd files and if i open them it closes
0
 
QlemoC++ DeveloperCommented:
What's the result of:
psexec \\server-exam01 cmd /k c:\mtl\start-docprint.bat

Open in new window

0
 
chglAuthor Commented:
pexec is not recognised as an internal or external command....
0
 
QlemoC++ DeveloperCommented:
Then you need to provide the full path to psexec, of course:
C:\DirOfPsExec\psexec \\server-exam01 cmd /k c:\mtl\start-docprint.bat

Open in new window

0
 
chglAuthor Commented:
i see
0
 
chglAuthor Commented:
I have written this script:

cd "C:\Documents and Settings\k.uddin\Desktop\downloads\PSTools"

.\psexec \\server-vexam01 cmd /k c:\mtl\stop-docprint.bat

.\psexec \\server-vexam01 cmd /k c:\mtl\start-docprint.bat

and saved it as start-stop.ps1 - when i open it powershell does not open, i then copied and pasted the script to a powershell, only the stop-docprint.bat runs.

also what does the /k stand for?
0
 
QlemoC++ DeveloperCommented:
This NOT PowerShell, it is cmd.exe batch scripting. Though you can call batches and exes from PowerShell, it adds a layer of complexity we do not need at the moment.

PowerShell is not set up to run .ps1 files by default - default action is "Edit". Double-clicking the file should hence open Notepad.

cmd /k ...    runs a command/batch, and then does not terminate. You should have a "remote console" now - just type exit to leave it. Then the other psexec will get executed. I have used /k only for testing purposes, in production you would use /c instead (which only executes the command, and then terminates cmd.exe).
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 8
  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now