?
Solved

powershell command

Posted on 2013-05-30
14
Medium Priority
?
259 Views
Last Modified: 2013-06-06
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
Comment
Question by:chgl
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 4
  • 2
14 Comments
 
LVL 40

Expert Comment

by:footech
ID: 39208290
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
 

Author Comment

by:chgl
ID: 39210134
what if i want to open an exe file, or a jpeg, etc??
0
 

Author Comment

by:chgl
ID: 39210138
hi,

i dont have powershell remoting enabled .

regards,
k
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 70

Expert Comment

by:Qlemo
ID: 39210202
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
 

Author Comment

by:chgl
ID: 39210271
thank you for your answer, my primary motivation or intent or objective is simply to learn
0
 

Author Comment

by:chgl
ID: 39210290
ive unzipped psexec, however it doesnt do anything when i type psexec in powershell or the command prompt?
0
 
LVL 40

Expert Comment

by:footech
ID: 39210295
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
 

Author Comment

by:chgl
ID: 39210344
sorry i dont understand, the folder contains cmd files and if i open them it closes
0
 
LVL 70

Expert Comment

by:Qlemo
ID: 39210491
What's the result of:
psexec \\server-exam01 cmd /k c:\mtl\start-docprint.bat

Open in new window

0
 

Author Comment

by:chgl
ID: 39210645
pexec is not recognised as an internal or external command....
0
 
LVL 70

Accepted Solution

by:
Qlemo earned 2000 total points
ID: 39210653
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
 

Author Comment

by:chgl
ID: 39210665
i see
0
 

Author Comment

by:chgl
ID: 39210820
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
 
LVL 70

Expert Comment

by:Qlemo
ID: 39211047
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After seeing many questions for JRNL_WRAP_ERROR for replication failure, I thought it would be useful to write this article.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question