I am working on a script that can capture dump using debug diag for an IIS appPOOL.
i can work on a .VB script however business demands powershell script in this case.
I am unable to find any related post on internet.
As of now i dont even know, if we have a powershell module for debug diag.
Can someone point me in the right direction ?
There is no native way to capture IIS App pool dumps. But you can convert this batch script to PS:
%windir%\system32\inetsrv\appcmd list wps /apppool.name:"Microsoft Team Foundation Server Application Pool" /text:WP.NAME > "%temp%\tfspid.txt"
:: ProcDump.exe (faster, reflects/clones the process for the dump to minimize the time the process is suspended (Windows 7 and higher only))
for /F %%a in (%temp%\tfspid.txt) do "%~dp0\procdump.exe" -accepteula -64 -ma -r %%a f:\dumps
pause
Reference Link: APP Pool Dump
Related
We have an application server running as a service, when some configuration is loaded it starts a bat script which has to run the powershell command Stop-ClusterGroup DRMSERVICES and then start it again.
The bat file works flawless when I manually execute it by dobbelt clicking. But when the service is running the bat, it does not finish, or execute the powershell command.
Bat file looks as follows
#echo off
powershell -command Stop-ClusterGroup DRMSERVICES
powershell -command Start-ClusterGroup DRMSERVICES
The service runs the bat file in silent mode, as a main difference.
I have tried with various switches including the -ExecutionPolicy Unrestricted and START /wait etc
Creating a seperate ps1 file and have the bat execute this instead.
All with the same output:
Manually executing the bat works
When the service executes the bat, it does not work.
I know the bat file is executed by the service, as inserting NET STOP servicename is working correct.
In the powershell event viewer I can also see event of the powershell commands take place.
The difference between manually executing and have the service execute the command in the event viewer, is event id 800 which states info about 'execution pipe' this is not present when the service is executing the bat.
The service does not wait for the powershell, and thus it does not have time to stop the cluster before exiting.
I'm lost whether this is a permission issue, syntax error or whatever.
Hopefully somebody can help
UPDATE:
I have tried with all proposed solutions, all with same result, the bat file works when double clicked, but the service does not execute the powershell command. Pure cmd is executed, as I can pipe to a txt file. I even got to a point when trying runas that the output log text wrote "insert administrator password"
I even managed to have our software guy change our software to call a powershell directly instead of a bat, same result. Powershell won't execute the command, this tells me it probably is permission, but everything have been set to log in as admin and run as admin for the sake of success, but still nothing.
I solved the problem.
Because the service is a 32bit process, it will execute a 32bit powershell.
FailoverClusters module only exists as a 64bit module.
By using %SystemRoot%\sysnative\WindowsPowershell\v1.0\powershell.exe
The service is able to open a 64bit session, and thus use the failover cluster module.
As a side note, the sysnative folder is only visible from a 32bit session, therefore it cannot be found via browsing in a 64bit os.
I think i have dealt with this kind of issue before, after the,
powershell -command Stop-ClusterGroup DRMSERVICES
you need to have cmd wait for a certain number of seconds, and then test if the DRMSERVICES is now stopped, if it is stopped then to start the DRMSERVICES again. This way cmd will keep waiting, and then check if the service has stopped.
After a certain number of tries, maybe have a way to stop checking and exit the script, for example it is trying to stop the service, and has run into a problem.
There is a timeout command in cmd
The UPS software I am using has functionality to run a script on the management PC (PC1) when it goes into battery mode. I have come up with a powershell script (ShutdownVM.ps1) that works fine on its own to Invoke-Commands on the VM server; shutting down VM's gracefully and turning off the host machine (SERVER). The first problem arose when the UPS software could not directly run a .ps1 file.
Simple enough, I thought I would make a simple .bat (shutdown.bat) file to run the .ps1 file on PC1 to shut everything off on SERVER. Running my .bat file from the desktop pc worked perfectly, but as the UPS software would run it as a service, my poor .bat file would run from Session 0.
Here is the code i used in Shutdown.bat:
#echo on
Powershell.exe -executionpolicy unrestricted -command C:\Windows\ShutdownVM.ps1
The interactive services manager would pop up and my computer would hang and finally the UPS software would turn it off and I'd be back to square one, with SERVER and its VM's still running. So I thought I would download and use PSExec to execute my shutdown.bat file.
I made another .bat file and called it PSExec.bat and below is the code in it:
#echo on
psexec.exe -accepteula \\PC1 -h -u user -p pass -i 2 C:\Windows\shutdown.bat
Finally! It tries to run! Upon checking the interactive services manager, it showed the PSExec was throwing the error "the system cannot find the file specified"
"The System Cannot Find The File Specified"
I have no idea what file it is even looking for, I have double, triple checked the path names in my scripts and still have no idea as to what it is doing. If anyone could shed any light (or let me know of an easier way to achieve what I am trying to do) that would be great. Thanks!
-F
I'm attempting to create a scheduled task on two different Windows 2008 R2 Servers that will use Driveimage XML by Runtime Software to create a disk image. The tasks are scheduling fine and running at proper times and after observing the running processes even the dixml.exe shows up in the processes section of the servers task manager under the user account that is specified.
The login used to run the task has administrator credentials as well as the GPO sets to allow admin to elevate an application without prompt.
I've tried writing a batch file for the program and running it which is as follows:
"C:\Program Files (x86)\Runtime Software\DriveImage XML\dixml.exe" /bC /s /c1
/v /t"X:\%date:~10,4%_%date:~4,2%_%date:~7,2%_%~0,3%"
I broke up the above script into two lines of code for easy reading.
This script when manually run either from the cmd or double clicking will properly start the process of the backup. However, when attached as a file to the task scheduler the event 'starts' but the program itself does not begin a back-up.
I've tried converting the batch file into this action:
Start a program: dixml.exe
Arguments: /bC /s /c1 /v /t"X:\%date:~10,4%_%date:~4,2%_%date:~7,2%_%~0,3%"
Start in: C:\Program Files (x86)\Runtime Software\DriveImage XML
According to MS in the 2008 R2 does not recoginze trailing slashes or quotations in their task scheduler so you leave them out.
The second method has the same effect of running the task, the program shows in the process tree and corresponds with the vent viewers PID code, but the back-ups are not made.
Anyone have experience with this perplexing issue?
I am writing a batch for a new deployment of my company's software.. Here is what I have so far...
wscript.exe "invisible.vbs" "apache_start.bat" /wait
wscript.exe "invisible.vbs" "mysql_start.bat" /wait
"C:\Program Files\Internet Explorer\iexplore.exe" http://localhost
So as you can see, this script should start apache, then start mysql and then open the default page with IE.
The problem is if the user runs this script twice, it runs apache and mysql twice and loads two seperate instances. The solution I need is a way to check to see if the processes are already running and, if not, run the two wscript commands. I am absolutely horrible with shell, so please try to give specific responses! I am a software engineer, not a sysadmin. Thanks for the help!
As a software engineer I think you have a leg up on scripting over some sysadmins...
Using PowerShell would make this easy. Use the following template to execute the services - you'll need to use it twice, and follow up with launching IE as above.
If ((Get-Process mysqlprocessname.exe)) {Write-Host Skipping MySQL}
Else { Start-Process ...}
This is going to take a few minutes for you to research the best way of starting a process with PowerShell. Also, you might want to pipe Start-Process to Out-Null so the script waits to start IE and Apache.
Others may want to chime in with a simpler way from a batch file.
For XAMPP, there is a pv.exe file in the apache/bin folder that XAMPP uses to see if a service is running. Look at WorldDrknss' answer in this thread for some great info: http://www.apachefriends.org/f/viewtopic.php?p=80047
The code to solve your problem is to modify your mysql_start.bat file to this:
#echo off
apache\bin\pv mysqld.exe %1 >nul
if ERRORLEVEL 1 goto Process_NotFound
echo MySQL is running
goto END
:Process_NotFound
echo Process %1 is not running
mysql\bin\mysqld.exe --defaults-file=mysql\bin\my.ini --standalone --console
goto finish
:finish
That will check if mysqld.exe is running. If it is, it just echos that out. If not, it starts the service.
When I'm writing a batch file to run automatically, how do I write it so that when the batch file is run, it can pause for a couple seconds in between commands?
Context:
psexec \\server -u user -p pass cmd
[there needs to be a pause here for psexec to establish a connection]
dir /s >output.txt \\server\shared
*Note: the reason I run the dir command server-side using psexec and not locally is because it's much faster to run dir on a local machine than remotely, and time is of the essence.
When I'm doing this by hand it's obviously easy, I just wait. But running a batch file makes it run all commands at near instant speeds next to each other, regardless of the completion status of the last command. How do I put in a pause?
On Windows Vista / Windows 7 you can use the timeout command:
timeout /T [delay in seconds] /NOBREAK > NUL
On previous versions of Windows, you can use the ping command (the ping command has 1000 ms of delay between each iteration):
ping -n [delay in seconds + 1] 127.0.0.1 > NUL
Some versions of Windows (like Windows Server 2003) has the sleep.exe executable:
sleep [delay in seconds]
Note: Windows Resource kit for 2003 contains sleep.exe command.
If you don't know the Windows version, simply use the ping hack since it'll be available.
There is timeout command in more recent version of Windows:
timeout /T 10
Windows Resource kit for 2003 will install on Windows XP. It contains SLEEP.EXE which can be used from a command batch file.
download is here http://www.microsoft.com/download/en/details.aspx?id=17657
I think the information here: http://malektips.com/xp_dos_0002.html would explain it better than I.
There's still the case of error handling though (what if the remote machine isn't up?). cmd.exe is quite useless for doing any remote activities for the most part, using powershell would enable so much more.
EDIT::
In fact, you can execute a program stored locally with psexec (it gets copied across and executed locally server-side) - would using that be a more viable alternative?
Without knowing what commands you're intending to run it's hard to take it much further.
EDIT(2)::
If it's just the one command you're running, simply store it in a dedicated file, like 'remote_dir_listing.cmd', and then use psexec with:
psexec \\server -u <user> -p <pass> -c -f remote_dir_listing.cmd
This will force a copy of the local file to the remote side each time you execute it (in case you want to expand it). In this way, you bypass the need for a pause at all - only when psexec has got the pipes open will it run, and once it completes, it closes itself silently.