Solved

powershell command

Posted on 2013-05-30
14
251 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
  • 8
  • 4
  • 2
14 Comments
 
LVL 39

Expert Comment

by:footech
Comment Utility
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
Comment Utility
what if i want to open an exe file, or a jpeg, etc??
0
 

Author Comment

by:chgl
Comment Utility
hi,

i dont have powershell remoting enabled .

regards,
k
0
 
LVL 68

Expert Comment

by:Qlemo
Comment Utility
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
Comment Utility
thank you for your answer, my primary motivation or intent or objective is simply to learn
0
 

Author Comment

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

Expert Comment

by:footech
Comment Utility
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:chgl
Comment Utility
sorry i dont understand, the folder contains cmd files and if i open them it closes
0
 
LVL 68

Expert Comment

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

Open in new window

0
 

Author Comment

by:chgl
Comment Utility
pexec is not recognised as an internal or external command....
0
 
LVL 68

Accepted Solution

by:
Qlemo earned 500 total points
Comment Utility
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
Comment Utility
i see
0
 

Author Comment

by:chgl
Comment Utility
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 68

Expert Comment

by:Qlemo
Comment Utility
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

Are end users causing IT problems again?

You’ve taken the time to design and update all your end user’s email signatures, only to find out they’re messing up the HTML, changing the font and ruining the imagery. What can you do to prevent this? Find out how you can save your signatures from end users today.

Join & Write a Comment

Synchronize a new Active Directory domain with an existing Office 365 tenant
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

762 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now