Executing procdump64.exe remotely using wmic - powershell

I am trying to generate a dump file using procdump64.exe in Powershell. I need to run the executable remotely using wmic. I am running the following command:
wmic /node:[IP Address] /user:"[DOMAIN/USER]" /password:"[PASSWORD]" process call create "cmd.exe /c U:\procdump64.exe -ma U:\lsass.exe > C:\dump.dmp"
For reference, I have verified that both procdump64.exe and lsass.exe are located at U:\ .
I receive output that says "Method execution successful" with a Return Value of 0.
However, the file that is generated is empty. Can anyone tell me what is wrong with my command?

Related

Silent install of application with PowerShell

I'm working to automate the install of some of our software and was able to do so using a batch file, but was having issues with getting the silent install working in PowerShell.
The batch file which is working properly to install the application is:
#echo off
start /wait Setup.exe -s -l=EN
echo %errorlevel%
I've tried the following code in PowerShell, but the GUI installer will appear when I attempt to run it.
cmd.exe /c "Start /wait c:\temp\application\setup.exe -s -l=EN"
I don't receive any error messages when running the PowerShell script, it just doesn't install the application silently.
Try this:
&{ "c:\temp\application\setup.exe" -s -l=EN }
This should call an external Commandline command from Powershell.
The braces are not always strictly necessary either if you are just running the command and not doing anything with the output the following would likely work
& c:\temp\application\setup.exe -s -l=EN

Using Netsh with PsExec

I'm trying to dump DHCP settings from an older server thats being decommissioned. I ran the command fine while on the actual server but when trying to run it using psexec remotely, it keeps failing. The command is: psexec \\$source netsh dhcp server \\$source dump>$dhcpSettings
$source = the server being decommissioned
$dhcpSettings = the path to save the dumped settings
I've tried all sorts of combinations of encapsulating quotation marks but still nothing. the errors I'm getting is, "The system cannot find the file specified" and "The system cannot find the path specified"
EDIT: So I got rid of the path to save the dumped settings and now it works. But how should I format the command so that it'll save the settings to the remote computer's C:\USER.SET\LOG directory?
One solution might be to bundle the command you want to run and the stdout redirection into a single line cmd file and use PsExec -c or -f to copy and execute that file on the remote system. As an example
Create a line cmd file named DHCPSettings.cmd with the following in it and save it to C:\temp\:
netsh dhcp server \\localhost dump >c:\user.set\log\dhcpsetting.log
Then use
psexec \\$source -c c:\temp\DHCPSettings.cmd
You did not really provide any code to go by and I am not sure I understand the all requirements and constraints you have, so consider this as an idea; not the exact commands you need to run. Hope it helps.

launch cmd run command isn't working

I am working on a script or batch file (or combo of the two) which imports an outlook prf file, then launches a new cmd.exe window runs a application specific program which when passed a server cluster name pulls in an outlook data file in the previously created outlook profile. So i have the vbs script that checks for the outlook profile if it doesn't exist it imports the prf. That's working fine, now the program i need to is called addiman.exe the server cluster name is gsiapp...the manual method is i launch a cmd windows and type "addiman gsiapp" i wish to automates this by calling it in a routine called :Filesite the below command has been unsuccessful, it launches a new cmd.exe window but doesn't run the command.
:ImportPRf
call cscript \\gsf1\Apps\Scripts\public\deployprf.vbs
GOTO :FileSite
:FileSite
start cmd.exe /c "c:\program files\interwoven\worksite\addiman.exe" GSIAPP
GOTO :EXIT
:Exit
Exit
start cmd.exe /c "c:\program files\interwoven\worksite\addiman.exe GSIAPP"
try this, because cmd.exe interprets the part between "" as comand and ignores the GSIAPP statement
wild guess. Try adding another call before the "start" - like this
:FileSite
call start cmd.exe /c "c:\program files\interwoven\worksite\addiman.exe" GSIAPP
problem solved, the full path isn't needed. just had to putt "addiman GSIAPP". Thanks everyone who provided suggestions.

How does PUTTY/PLINK determine a command has returned?

Is it newline? prompt? What exactly?
Trying to run powershell over plink and the command executes but plink doesn't recognise its finished and the session hangs. Most curiously though, the command executes successfully when sent through the shell (via Putty). However, when sent via plink, the same command hangs...
Any ideas?
Telnet is nearly a raw TCP connection. All Putty needs back is a response from the server. The rest is controlled by the shell and SSH/Telnet server.
While your task is running, it's not going to return a command prompt.
On Linux, Unix, and Mac OS X you could put a & after the command to run it in the background and return to the command prompt.
Try running it in the local terminal/command shell. You should basically see the same thing.
Ok, well I'm still not quite sure what the problem is, but I've found a workaround via the TeamCity forums.
Basically you want to echo some abitrary string and pipe that output into your powershell executable, like thus:
echo 'executing powershell...' | C:\windows\system32\windowspowershell \v1.0\powershell.exe exit 1
So then your full plink command becomes:
plink.exe user#someIp -i key.ppk -P 22 -batch -v "echo 'executing powershell...' | C:\windows\system32\windowspowershell\v1.0\powershell.exe exit 1"
Nb. Plink will still pass through return codes and console output using this method.
Link to TeamCity forum:
http://youtrack.jetbrains.net/issue/TW-6021
Hope this helps
I had the same problem with an other program. I used the >&2 (redirect output to std err) after the last command, this worked fine for me.
Just add "return XX" into remote shell script, it will be return value to local console. After plink has been finished, type echo %errorlevel% to see return code XX.

How to create a file without a Command Prompt window

I'm using WinRAR SFX module to create an installation, and use its presetup option to run some preliminary tests.
Since wscript can only accept vbs file, and not the script itself, I first run "cmd /c echo {...script code...} > setup.vbs", and then I run "wscript setup.vbs". The run of the first cmd command opens a brief command window, and I would really like to avoid this. I thought of using RunDll32 to write this data, but couldn't find any suitable API to use.
Can anyone think of a way to bypass it and create a small file with a small VBScript text without opening a Command Prompt window?
Thanks a lot,
splintor
Is the script code already in a file? If so,
You can use the TYPE command to send the script to a file:
TYPE [script_file] > setup.vbs
or COPY the script file:
COPY [script_file] setup.vbs
If the script code is in the body of your cmd, you can use the START command to run the cmd without a window (/b flag):
START /B cmd /c echo {...script code...} > setup.vbs
Rather than use cmd /c echo {...script code...} > setup.vbs as a presetup step, perhaps you could package a VBscript with your install that does your preliminary tests and creates setup.vbs, and then calls setup.vbs for you. You'd have to put this in the setup portion of the WinRAR script.
You can call another VBScript from VBScript like this:
Set WSHShell = CreateObject("WScript.Shell")
WSHShell.Run "wscript d:\setup.vbs, ,True
See this MSDN link for the syntax of the Run command.