Solved

powershell command

Posted on 2013-05-30
14
254 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 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
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
LVL 69

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 69

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 69

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 69

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

This article will help you understand what HashTables are and how to use them in PowerShell.
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 …
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
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)

809 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