Solved

powershell command

Posted on 2013-05-30
14
258 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
Free NetCrunch network monitor licenses!

Only on Experts-Exchange: Sign-up for a free-trial and we'll send you your permanent license!

Here is what you get: 30 Nodes | Unlimited Sensors | No Time Restrictions | Absolutely FREE!

Act now. This offer ends July 14, 2017.

 
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 500 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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
Resolving an irritating Remote Desktop connection that stops your saved credentials from being used.
This tutorial will walk an individual through setting the global and backup job media overwrite and protection periods in Backup Exec 2012. Log onto the Backup Exec Central Administration Server. Examine the services. If all or most of them are stop…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

726 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