<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.technet.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Use PowerShell to Detect if a Workstation Is in Use</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2011/03/17/use-powershell-to-detect-if-a-workstation-is-in-use.aspx</link><description>Summary : Learn how to use Windows PowerShell to detect if a workstation is in use prior to performing a reboot 
 
 Hey, Scripting Guy! I have a problem in that I need to detect when a user is logged on to a system so that I can patch it and reboot</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>re: Use PowerShell to Detect if a Workstation Is in Use</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2011/03/17/use-powershell-to-detect-if-a-workstation-is-in-use.aspx#3485502</link><pubDate>Thu, 08 Mar 2012 16:20:56 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3485502</guid><dc:creator>Alex</dc:creator><description>&lt;p&gt;I&amp;#39;ve been browsing through those blogs since 1 month and this tutorial is by far something of the best you are able to find!&lt;/p&gt;
&lt;p&gt;useful, informative and really well graphical aranged. most people who try to explain regex should be refered to your tutorial, even though its just a part of it.&lt;/p&gt;
&lt;p&gt;congratulations again.&lt;/p&gt;
&lt;p&gt;regards&lt;/p&gt;
&lt;p&gt;alex&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3485502" width="1" height="1"&gt;</description></item><item><title>re: Use PowerShell to Detect if a Workstation Is in Use</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2011/03/17/use-powershell-to-detect-if-a-workstation-is-in-use.aspx#3446685</link><pubDate>Fri, 12 Aug 2011 08:21:37 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3446685</guid><dc:creator>techibee.com</dc:creator><description>&lt;p&gt;Thank you very much for the article. It really helped me. However, I had to make a few alterations to it so that it won&amp;#39;t report incorrect data.&lt;/p&gt;
&lt;p&gt;The changes I made are...&lt;/p&gt;
&lt;p&gt; * Removed (?&amp;lt;user&amp;gt;\S+) from regular expression so that it won&amp;#39;t report &amp;quot;Connecting&amp;quot; in user account. This is happening because when psloggedon is run, it outputs the data saying &amp;nbsp;connecting to \\computer.&lt;/p&gt;
&lt;p&gt; * Suppressed psloggedon logo information by redirecting the error output to null&lt;/p&gt;
&lt;p&gt;Thanks again. Modified script is available at &lt;a rel="nofollow" target="_new" href="http://techibee.com/powershell/powershell-script-to-get-local-loggedon-user-information/1082"&gt;techibee.com/.../1082&lt;/a&gt;&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3446685" width="1" height="1"&gt;</description></item><item><title>re: Use PowerShell to Detect if a Workstation Is in Use</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2011/03/17/use-powershell-to-detect-if-a-workstation-is-in-use.aspx#3423769</link><pubDate>Sat, 23 Apr 2011 09:29:36 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3423769</guid><dc:creator>Brisvegas</dc:creator><description>&lt;p&gt;I am seeing an issue with PSLoggedOn where it is reporting users as being logged on when they definitely aren&amp;#39;t. I am not sure, but I assume that PSLoggedOn works by querying which user registries hives have been loaded. Looking at these machines, sure enough multiple registry hives for the various users have been loaded (Windows 7), but they&amp;#39;re not actually logged on and have not been logged into these machines for months. A restart resolves the issue, but anyone know what could cause this behaviour? I&amp;#39;m thinking maybe it is Symantec AV.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3423769" width="1" height="1"&gt;</description></item><item><title>re: Use PowerShell to Detect if a Workstation Is in Use</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2011/03/17/use-powershell-to-detect-if-a-workstation-is-in-use.aspx#3413834</link><pubDate>Thu, 17 Mar 2011 18:29:14 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3413834</guid><dc:creator>smudge2112</dc:creator><description>&lt;p&gt;Thanks Glenn. &amp;nbsp;That very neatly solves an issue I was just starting to try to figure out.&lt;/p&gt;
&lt;p&gt;Regarding the use of psloggedon.exe, I added a couple of lines to run psloggedon.exe from webdav if it is not found locally and also added the &amp;quot;-accepteula&amp;quot; switch (becaue I didn&amp;#39;t feel like testing the registry for the &amp;quot;EulaAccepted&amp;quot; key) so that I don&amp;#39;t have to click &amp;quot;agree&amp;quot; when running from different machines or accounts. &amp;nbsp;&lt;/p&gt;
&lt;p&gt;if (Test-path Y:\PSTools\psloggedon.exe) {&lt;/p&gt;
&lt;p&gt;		#run locally&lt;/p&gt;
&lt;p&gt;		$PsloggedonPath = &amp;quot;Y:\PSTools\psloggedon.exe&amp;quot;&lt;/p&gt;
&lt;p&gt;		}&lt;/p&gt;
&lt;p&gt;	Else {&lt;/p&gt;
&lt;p&gt;		#run via webdav:&lt;/p&gt;
&lt;p&gt;		$PsloggedonPath = &amp;quot;\\live.sysinternals.com\tools\psloggedon.exe&amp;quot;&lt;/p&gt;
&lt;p&gt;		}&lt;/p&gt;
&lt;p&gt;With those changes the first line of the ForEach loop becomes:&lt;/p&gt;
&lt;p&gt;[object[]]$sessions = Invoke-Expression &amp;quot;$PsloggedonPath -accepteula -x -l \\$Computer&amp;quot; |&lt;/p&gt;
&lt;p&gt;This seems a little clunky to me but it work adequately for my needs. YMMV.&lt;/p&gt;
&lt;p&gt;Thanks again for the excellent article. :-)&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3413834" width="1" height="1"&gt;</description></item><item><title>re: Use PowerShell to Detect if a Workstation Is in Use</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2011/03/17/use-powershell-to-detect-if-a-workstation-is-in-use.aspx#3413823</link><pubDate>Thu, 17 Mar 2011 17:50:16 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3413823</guid><dc:creator>realinit</dc:creator><description>&lt;p&gt;Thanks for the article, well written. I am new to Powershell scripting and Windows scripting, as a result my current knowledge does not provide me the ability to &amp;quot;cook the meal&amp;quot;. &amp;nbsp;I have a Client/Server sandbox running XP 64bit and VPC DC &amp;amp; 3 clients, I would really appreciate it if you could point me to a doc or reference which would provide the necessary cooking directions, as any good recipe does. :)&lt;/p&gt;
&lt;p&gt;Thank you for your time!&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3413823" width="1" height="1"&gt;</description></item><item><title>re: Use PowerShell to Detect if a Workstation Is in Use</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2011/03/17/use-powershell-to-detect-if-a-workstation-is-in-use.aspx#3413748</link><pubDate>Thu, 17 Mar 2011 15:27:53 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3413748</guid><dc:creator>Glenn Sizemore</dc:creator><description>&lt;p&gt;Bartek,&lt;/p&gt;
&lt;p&gt;Thank you so much for the tip, and of course you are 100% correct. Honestly I picked up the habit from reading Jakul’s code, It’s handy because reordering the items in an array won’t break anything. &amp;nbsp;If you use the trailing comma you constantly have to shuffle commas as you modify your code. &amp;nbsp;Plus it&amp;#39;s easy to spot a typo using a preceding comma. &amp;nbsp;Most people hate them, but I&amp;#39;ve grown so accustomed to it, that it just looks wrong without it. &amp;nbsp;The fix of coarse would be to remove the first comma, or use no commas at all, but again it just looks wrong to me.&lt;/p&gt;
&lt;p&gt;Thanks again for your kind words and highlighting the potential pitfall of defining an array as I have.&lt;/p&gt;
&lt;p&gt;~Glenn&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3413748" width="1" height="1"&gt;</description></item><item><title>re: Use PowerShell to Detect if a Workstation Is in Use</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2011/03/17/use-powershell-to-detect-if-a-workstation-is-in-use.aspx#3413626</link><pubDate>Thu, 17 Mar 2011 08:29:07 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3413626</guid><dc:creator>Bartek Bielawski</dc:creator><description>&lt;p&gt;First of all - great article, very professional, thanks Glenn! :)&lt;/p&gt;
&lt;p&gt;One tip regarding array definition I&amp;#39;ve recently (and accidentally) discovered: you do not need comma if you use &amp;lt;newline&amp;gt;:&lt;/p&gt;
&lt;p&gt;@( &amp;nbsp;1&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;2&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;3&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;4 )[1] &lt;/p&gt;
&lt;p&gt;2&lt;/p&gt;
&lt;p&gt;And the result can get quite unexpected if you use comma at the line start, as Glenn did:&lt;/p&gt;
&lt;p&gt;$a = 1..20&lt;/p&gt;
&lt;p&gt;@( $a, $a, $a&lt;/p&gt;
&lt;p&gt; &amp;nbsp; ,$a,$a, $a) | foreach { $_.length }&lt;/p&gt;
&lt;p&gt;&amp;#39;-&amp;#39; * 80&lt;/p&gt;
&lt;p&gt;@( $a, $a, $a,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; $a,$a, $a) | foreach { $_.length }&lt;/p&gt;
&lt;p&gt;&amp;#39;-&amp;#39; * 80&lt;/p&gt;
&lt;p&gt;$b = @( $a, $a&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;,$a, $a)&lt;/p&gt;
&lt;p&gt;&amp;#39;No such index&amp;#39;&lt;/p&gt;
&lt;p&gt;$b[1][0][1]&lt;/p&gt;
&lt;p&gt;&amp;#39;Unary comma, so array got nested&amp;#39;&lt;/p&gt;
&lt;p&gt;$b[2][0][9]&lt;/p&gt;
&lt;p&gt;It won&amp;#39;t bite you if array element is alone on the line, but well... you may get something unpredictable at times... ;)&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3413626" width="1" height="1"&gt;</description></item></channel></rss>