<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: More Powershell Nuggets</title>
	<atom:link href="http://www.youdidwhatwithtsql.com/more-powershell-nuggets/239/feed" rel="self" type="application/rss+xml" />
	<link>http://www.youdidwhatwithtsql.com/more-powershell-nuggets/239</link>
	<description>making DBAs everywhere curse!</description>
	<lastBuildDate>Sat, 04 Feb 2012 06:02:22 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Rhys</title>
		<link>http://www.youdidwhatwithtsql.com/more-powershell-nuggets/239/comment-page-1#comment-1484</link>
		<dc:creator>Rhys</dc:creator>
		<pubDate>Mon, 24 Oct 2011 11:45:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.youdidwhatwithtsql.com/more-powershell-nuggets/239#comment-1484</guid>
		<description>Hi Kev,

Easy, just setup an array and iterate through the value. The sample below will give you a good idea for something more robust...

&lt;code&gt;

# Kill a process on a remote machine
$computer = &quot;localhost&quot;;
$processesToKill = @(&quot;calc.exe&quot;, &quot;notepad.exe&quot;, &quot;wintrv.exe&quot;);

foreach($process in $processesToKill)
{

	$process = Get-WmiObject -Class Win32_Process -Filter &quot;Name = &#039;$process&#039;&quot; -ComputerName $computer;
	if($process -eq $null)
	{	# If null then the process may not be running
		Write-Host -ForegroundColor Red &quot;Couldn&#039;t get process $process on $computer&quot;;
	}
	else
	{
		Write-Host &quot;Attempting to Kill $process on $computer&quot;;
	}
	# Kill the process and get exit status 0 = OK
	$status = $process.InvokeMethod(&quot;Terminate&quot;, $null);
	switch($status)
	{
		0 { Write-Host -ForegroundColor Green &quot;Killed $process on $computer&quot;};
		default { Write-Host -ForegroundColor Red &quot;Error, couldn&#039;t kill $process on $computer&quot;};
 
	};
}
&lt;/code&gt;

Cheers,

Rhys</description>
		<content:encoded><![CDATA[<p>Hi Kev,</p>
<p>Easy, just setup an array and iterate through the value. The sample below will give you a good idea for something more robust&#8230;</p>
<p><code></p>
<p># Kill a process on a remote machine<br />
$computer = "localhost";<br />
$processesToKill = @("calc.exe", "notepad.exe", "wintrv.exe");</p>
<p>foreach($process in $processesToKill)<br />
{</p>
<p>	$process = Get-WmiObject -Class Win32_Process -Filter "Name = '$process'" -ComputerName $computer;<br />
	if($process -eq $null)<br />
	{	# If null then the process may not be running<br />
		Write-Host -ForegroundColor Red "Couldn't get process $process on $computer";<br />
	}<br />
	else<br />
	{<br />
		Write-Host "Attempting to Kill $process on $computer";<br />
	}<br />
	# Kill the process and get exit status 0 = OK<br />
	$status = $process.InvokeMethod("Terminate", $null);<br />
	switch($status)<br />
	{<br />
		0 { Write-Host -ForegroundColor Green "Killed $process on $computer"};<br />
		default { Write-Host -ForegroundColor Red "Error, couldn't kill $process on $computer"};</p>
<p>	};<br />
}<br />
</code></p>
<p>Cheers,</p>
<p>Rhys</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kev</title>
		<link>http://www.youdidwhatwithtsql.com/more-powershell-nuggets/239/comment-page-1#comment-1481</link>
		<dc:creator>Kev</dc:creator>
		<pubDate>Sun, 23 Oct 2011 16:46:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.youdidwhatwithtsql.com/more-powershell-nuggets/239#comment-1481</guid>
		<description>Ok, this script is great for killing one process, how can It be modified to kill say three different processes?
eg. Notepad.exe, Calc.exe and wintrv.exe ?</description>
		<content:encoded><![CDATA[<p>Ok, this script is great for killing one process, how can It be modified to kill say three different processes?<br />
eg. Notepad.exe, Calc.exe and wintrv.exe ?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rhys</title>
		<link>http://www.youdidwhatwithtsql.com/more-powershell-nuggets/239/comment-page-1#comment-214</link>
		<dc:creator>Rhys</dc:creator>
		<pubDate>Tue, 10 Aug 2010 19:17:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.youdidwhatwithtsql.com/more-powershell-nuggets/239#comment-214</guid>
		<description>Hi Brock,

Here&#039;s how you can resolve the issue you pointed out...

http://www.youdidwhatwithtsql.com/kill-all-processes-by-name-with-powershell/853

Cheers,

Rhys</description>
		<content:encoded><![CDATA[<p>Hi Brock,</p>
<p>Here&#8217;s how you can resolve the issue you pointed out&#8230;</p>
<p><a href="http://www.youdidwhatwithtsql.com/kill-all-processes-by-name-with-powershell/853" rel="nofollow">http://www.youdidwhatwithtsql.com/kill-all-processes-by-name-with-powershell/853</a></p>
<p>Cheers,</p>
<p>Rhys</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rhys</title>
		<link>http://www.youdidwhatwithtsql.com/more-powershell-nuggets/239/comment-page-1#comment-213</link>
		<dc:creator>Rhys</dc:creator>
		<pubDate>Mon, 09 Aug 2010 23:06:15 +0000</pubDate>
		<guid isPermaLink="false">http://www.youdidwhatwithtsql.com/more-powershell-nuggets/239#comment-213</guid>
		<description>Yep, probably quite simple to get all process ids with a specific name and then kill them one-by-one. I might have a stab at it in a day or two if you don&#039;t.

Cheers,

Rhys</description>
		<content:encoded><![CDATA[<p>Yep, probably quite simple to get all process ids with a specific name and then kill them one-by-one. I might have a stab at it in a day or two if you don&#8217;t.</p>
<p>Cheers,</p>
<p>Rhys</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brock</title>
		<link>http://www.youdidwhatwithtsql.com/more-powershell-nuggets/239/comment-page-1#comment-212</link>
		<dc:creator>Brock</dc:creator>
		<pubDate>Mon, 09 Aug 2010 22:32:02 +0000</pubDate>
		<guid isPermaLink="false">http://www.youdidwhatwithtsql.com/more-powershell-nuggets/239#comment-212</guid>
		<description>This script works until you have multiple processes with the same name. Try opening two or more notepads and kill them. You get a big fat error. Anyway around it?</description>
		<content:encoded><![CDATA[<p>This script works until you have multiple processes with the same name. Try opening two or more notepads and kill them. You get a big fat error. Anyway around it?</p>
]]></content:encoded>
	</item>
</channel>
</rss>

