Welcome i have ran into a small issue. So basically i have been coding a program to open up power-shell and run proc dump and dump a process. Using Proc Dump. I keep getting multiple processes running. And there is no way i can get the PID, So its useless. Is there another third party tool that i can use without getting this issue? or can i just do this via CMD or power-shell without using other software's? Thanks!
Error im receiving
Multiple processes match the specified name.
I have used following powershell command in the past to create a procdump of multiple processes with an identical name
gps notepad* | %{
$argumentList = "-accepteula -ma -n 1000 -e 1 $($_.Id) "
start-process C:\My\SysInternals\procdump -argumentList $argumentList
}
The gist of this is to get a list op PID's to pass to procdump. Mind you that when you have dozens of notepads running, you'll create dozens of dumps.
Related
I am fairly new to writing code in Powershell. For my job I have to write multiple Powershell scripts to make changes in the Hardware and Software settings as well as the Registry and Group Policy Editor to get these applications to run. These applications are a little older. Upgrading these software applications or the hardware then run on is NOT an option. as an example, when Microsoft releases the new patches on like Patch Tuesday...when those patches are applied there is a high probability that something will be changed which is where I come in to write a script to fix the issue. I have multiple scripts that I run. When those scripts are ran they may end up terminating because of an Error Code or an Exit Code. A large part of the time I do not that the script has failed immediately.
I am trying to figure out a script that I can run in a 2nd PowerShell Console Window. I am thinking that the only purpose of this script is to just sit there on the screen and wait and monitor. Then when I execute a script or Application (the only file extensions that I am worried about are: EXE, BAT, CMD, PS1) if the script/application that I just ran ends with an exit code or an error code....then output that to the screen...in REAL TIME.
Below, I have a small piece of code that kind of works, but it is not what I am wanting.
I have researched online and read and read tons of stuff. But I just can't seem to find what I am looking for.
Could someone please help me with getting a script that will do what I am wanting.
Thank you for your help!!!!
$ExitErrorCode =
"C:\ThisFolder\ThatFolder\AnotherFolder\SomeApplication.EXE # (this
would
# either be an EXE or CMD or BAT or PS1)"
$proc = Start-Process $ExitErrorCode -PassThru
$handle = $proc.Handle # cache proc.Handle
$proc.WaitForExit();
if ($proc.ExitCode -ne 0) {
Write-Warning "$_ exited with status code $($proc.ExitCode)"
}
Possible duplicate of the approaches shown here:
Monitoring jobs in a PowerShell session from another PowerShell session
Monitoring jobs in a PowerShell session from another PowerShell session
PowerShell script to monitor a log and output progress to another
PowerShell script to monitor a log and output progress to another
I have an scp command that I want to run repeatedly and also watch the output. Putting one or multiple scp commands in a script allows me to see the output but each has to finish before moving on to the next. I can open multiple PowerShell windows but I want to scale it up past the point where that is practical.
I've played with start-job and that allows me to run multiples but when using get-job/receive-job/wait-job I haven't been able to get what I want. I've also tried invoke-command and invoke-expression.
My command is something like this:
C:\temp\scp.exe' -i c:\temp\key c:\temp\test100.dat user1`#10.10.0.100:/tmp/
The output is updated regularly (once/second I guess) and looks like this:
Transfering c:\temp\test100.dat
c:\temp\test100.dat | 5.55mB | 812.13kB/s | 00:01:59 | 5%
Is it possible to do this?
You could pipe the output to file with Out-File and monitor the file with http://www.baremetalsoft.com/wintail/
TASK TO BE ACCOMPLISHED:
To schedule a perl script which is executed on a specific time / day in a week
THINGS I HAVE DONE:
In a schedule Tasks, I have created a new Task by which the Task will call a batch file with below contents
cd "DRIVE\FOLDER\Hummingbird\Connectivity\14.00\Exceed\"
ABCD.xs
cd mDrive/bin
perl baseline.pl -publish -location XXX -email
THINGS NOT WORKING FOR ME / CAUSING THE ISSUE:
Wen I run the scheduler, the prompt opens up the ABCD.xs exceed file window seperately file but the below commands are executed in the command pronpt itself
EXPECTED OUTPUT:
I want the commands
cd mDrive/bin
perl baseline.pl -publish -location XXX -email
to be executed in the exceed window
Any kind of solution wud be great
Thanks in advance.
Haresh
Sounds like you need to start getting into either SendKey stuff (Win32 packages) or else look into writing Exceed/Hummingbird scripts and just executing those.
Some other things to look into... does the remote server have a telnet or ssh server running? Or are there other methods of executing code on the remote server?
For example, my work's mainframe is accessed via a Hummingbird terminal emulator, but I can also telnet to the mainframe and execute commands as well as FTP batch job directly into the JES spool. So when I execute things on the mainframe by way of my PC (Perl scripts, etc.), I don't even fool with Hummingbird.
Good luck...
I've written a powershell script to call sqlcmd.exe to execute a sql script against a remote sql server. The powershell script checks $LASTEXITCODE. If $LASTEXITCODE is non zero, I throw "Script failed. Return code is $LASTEXITCODE."
The script is used multiple times to execute different sql scripts and is part of a chain of powershell scripts that run during deployment.
The script runs fine most of the time but randomly fails with a return code of -1073741502.
This has only started happening after upgrading to SQL2008 and I cannot reproduce it by running either the single powershell script manually or the sql cmd script manually.
This is the powershell command:
& 'sqlcmd.exe' -S $databaseServer -r -b -E -i '$scriptFullPath'
if($LASTEXITCODE -ne 0)
{
throw "Script failed. Return code is $LASTEXITCODE."
}
The seemingly random nature of the failure is causing a lot of pain. I can't determine if the error is SQL2008, SQLCMD (Although I get the same behaviour with osql.exe) or somehow coupled to powershell.
The actual sql that sqlcmd is executing appears to be unrelated to the problem since a sql script will execute ok for a while and then fail.
The same failure has been seen on many different Workstations and Servers (Win7, Win2003 and Win2008)
Any guidance on how to track this down would be much appreciated.
Don't use sqlcmd and command lines if you are using Powershell!
There are very good built-in tools in V2 that give you a lot more robust interaction with SQL Server, and don't require you to parse the text of return codes to check for errors - they actually return proper error codes.
Here's a technet article on Invoke-SQLCmd
Bear in mind you need to load the snapins first:
Add-PSSnapin SqlServerProviderSnapin100
Add-PSSnapin SqlServerCmdletSnapin100
The root-cause is actually explained elsewhere on here
Exit Code -1073741502 is 0xC0000142 in hex (status_dll_init_failed).
Microsoft's KB2701373 addresses the leaky handles made by Console.Write in Microsoft.powershell.consolehost.dll.
Side-Note: Some "Fixes" on the Internet involve doing something differently, then restarting PowerShell. Yet the actual restart of PowerShell is what addresses the problem (temporarily)
I have a service running that can invoke an external process to modify a text stream before it is returned to the service. The text stream is handed from the service to the external process on stdout and the modified result is read from the service on stdin. The external process (command) can in other words be used as a text "filter". I would like to use a powershell script to modify the text stream. I can successfully launch a script from the service on win 2008r2 using the command "powershell -executionpolicy bypass -noninteractive ./myscript.ps1".
I can make the script return text to the service on stdout using the write-host cmdlet. My problem is that I can't find a way to read the text on stdin in the script. Read-host doesn't seem to work as it requires an interactive shell.
I would like to avoid writing the stdout from the service to a tmp file and read that file in the script as the service is multithreaded (can launch more than one external command at a time) and tmp file management (locking, unique filenames etc) is not desired.
Is this possible or should I use for example Perl for this? Powershell seems compelling as it is preinstalled on all my win 2008 machines.
Just a guess - I would have a look at [Console]::In | gm -static.