<?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: Conditional Logic</title>
	<atom:link href="http://www.powershellpro.com/powershell-tutorial-introduction/powershell-tutorial-conditional-logic/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.powershellpro.com</link>
	<description>Sharing the Experience</description>
	<lastBuildDate>Fri, 03 Feb 2012 08:09:32 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Mark</title>
		<link>http://www.powershellpro.com/powershell-tutorial-introduction/powershell-tutorial-conditional-logic/comment-page-1/#comment-713</link>
		<dc:creator>Mark</dc:creator>
		<pubDate>Fri, 28 Oct 2011 23:17:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.powershellpro.com/powershell-tutorial-introduction/powershell-tutorial-conditional-logic/#comment-713</guid>
		<description>For people getting the &quot;Access denied&quot; messages, make sure you right-click on the powershell icon and select &quot;run as administrator&quot;. That fixed it for me.

Ola, re the &quot;elseif&quot; not recognized. I noticed that when I pasted directly into the powershell window I get the same, but when I create a .ps1 file and run it as suggested it works fine. Must be a quirk in the immediate window.</description>
		<content:encoded><![CDATA[<p>For people getting the &#8220;Access denied&#8221; messages, make sure you right-click on the powershell icon and select &#8220;run as administrator&#8221;. That fixed it for me.</p>
<p>Ola, re the &#8220;elseif&#8221; not recognized. I noticed that when I pasted directly into the powershell window I get the same, but when I create a .ps1 file and run it as suggested it works fine. Must be a quirk in the immediate window.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dan K</title>
		<link>http://www.powershellpro.com/powershell-tutorial-introduction/powershell-tutorial-conditional-logic/comment-page-1/#comment-608</link>
		<dc:creator>Dan K</dc:creator>
		<pubDate>Thu, 21 Apr 2011 22:44:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.powershellpro.com/powershell-tutorial-introduction/powershell-tutorial-conditional-logic/#comment-608</guid>
		<description>Nicely written introductory tutorials.  Thank you.

* Minor cleanup:  The if statement syntax has
    else (condition) {code block}
rather than
    else {code block}

* Also, near the top where &quot;Conditional logic&quot; introduces the switch statement, it points out that the PowerShell switch statement is similar to VBScript and some other languages.  Even though you clearly say it later, for the sake of a non-careful reader, perhaps also mention the important difference that PowerShell&#039;s switch can execute multiple cases.

Just minor tweaks in an excellent introduction.</description>
		<content:encoded><![CDATA[<p>Nicely written introductory tutorials.  Thank you.</p>
<p>* Minor cleanup:  The if statement syntax has<br />
    else (condition) {code block}<br />
rather than<br />
    else {code block}</p>
<p>* Also, near the top where &#8220;Conditional logic&#8221; introduces the switch statement, it points out that the PowerShell switch statement is similar to VBScript and some other languages.  Even though you clearly say it later, for the sake of a non-careful reader, perhaps also mention the important difference that PowerShell&#8217;s switch can execute multiple cases.</p>
<p>Just minor tweaks in an excellent introduction.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt</title>
		<link>http://www.powershellpro.com/powershell-tutorial-introduction/powershell-tutorial-conditional-logic/comment-page-1/#comment-516</link>
		<dc:creator>Matt</dc:creator>
		<pubDate>Fri, 03 Sep 2010 15:01:15 +0000</pubDate>
		<guid isPermaLink="false">http://www.powershellpro.com/powershell-tutorial-introduction/powershell-tutorial-conditional-logic/#comment-516</guid>
		<description>I&#039;m new to PowerShell (and I&#039;m finding the tutorials very useful, thanks) but I&#039;ve been around the block a few times with Perl and Bash.  Whilst I can see the PrintReport.ps1 script is useful for demonstrating -or and nested &quot;if&quot; statements, as an example of code efficiency and readability it&#039;s not great for people new to scripting.  I haven&#039;t tested the following, but as far as I can see it would do the same thing in a slightly nicer way...


$strComputer = Read-Host &quot;Printer Report – Enter Computer Name&quot;
$OS = Get-WmiObject -Class win32_OperatingSystem -namespace &quot;root\CIMV2&quot; -ComputerName $strComputer

if($OS.Version -eq &quot;5.1.2600&quot;)
{
   $osName = &quot;Windows XP&quot;
   $class = &quot;win32_Printer&quot;
}
elseif($OS.Version -eq &quot;5.2.3790&quot;)
{
   $osName = &quot;Windows 2003&quot;
   $class = &quot;win32_Printer&quot;
}
elseif($OS.Version -eq &quot;5.0.2195&quot;)
{
   $osName = &quot;Windows 2000 Server&quot;
   $class = &quot;win32_PrintJob&quot;
}
else
{
   Write-Host &quot;The OS for computer $strComputer is not supported&quot;
   exit
}

$colPrinters = Get-WmiObject -Class $class -namespace &quot;root\CIMV2&quot; -computerName $strComputer

Write-Host &quot;Computer Name: &quot; $strComputer
Write-Host &quot;OS Name: &quot; $osName

foreach ($objPrinter in $colPrinters)
{
   Write-Host &quot;Name: &quot; $objPrinter.Name
   Write-Host &quot;Description: &quot; $objPrinter.Description
   Write-Host
}

Write-Host &quot;–END OF REPORT–&quot;
</description>
		<content:encoded><![CDATA[<p>I&#8217;m new to PowerShell (and I&#8217;m finding the tutorials very useful, thanks) but I&#8217;ve been around the block a few times with Perl and Bash.  Whilst I can see the PrintReport.ps1 script is useful for demonstrating -or and nested &#8220;if&#8221; statements, as an example of code efficiency and readability it&#8217;s not great for people new to scripting.  I haven&#8217;t tested the following, but as far as I can see it would do the same thing in a slightly nicer way&#8230;</p>
<p>$strComputer = Read-Host &#8220;Printer Report – Enter Computer Name&#8221;<br />
$OS = Get-WmiObject -Class win32_OperatingSystem -namespace &#8220;root\CIMV2&#8243; -ComputerName $strComputer</p>
<p>if($OS.Version -eq &#8220;5.1.2600&#8243;)<br />
{<br />
   $osName = &#8220;Windows XP&#8221;<br />
   $class = &#8220;win32_Printer&#8221;<br />
}<br />
elseif($OS.Version -eq &#8220;5.2.3790&#8243;)<br />
{<br />
   $osName = &#8220;Windows 2003&#8243;<br />
   $class = &#8220;win32_Printer&#8221;<br />
}<br />
elseif($OS.Version -eq &#8220;5.0.2195&#8243;)<br />
{<br />
   $osName = &#8220;Windows 2000 Server&#8221;<br />
   $class = &#8220;win32_PrintJob&#8221;<br />
}<br />
else<br />
{<br />
   Write-Host &#8220;The OS for computer $strComputer is not supported&#8221;<br />
   exit<br />
}</p>
<p>$colPrinters = Get-WmiObject -Class $class -namespace &#8220;root\CIMV2&#8243; -computerName $strComputer</p>
<p>Write-Host &#8220;Computer Name: &#8221; $strComputer<br />
Write-Host &#8220;OS Name: &#8221; $osName</p>
<p>foreach ($objPrinter in $colPrinters)<br />
{<br />
   Write-Host &#8220;Name: &#8221; $objPrinter.Name<br />
   Write-Host &#8220;Description: &#8221; $objPrinter.Description<br />
   Write-Host<br />
}</p>
<p>Write-Host &#8220;–END OF REPORT–&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ola</title>
		<link>http://www.powershellpro.com/powershell-tutorial-introduction/powershell-tutorial-conditional-logic/comment-page-1/#comment-486</link>
		<dc:creator>Ola</dc:creator>
		<pubDate>Wed, 02 Jun 2010 10:05:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.powershellpro.com/powershell-tutorial-introduction/powershell-tutorial-conditional-logic/#comment-486</guid>
		<description>Hi, 
I seem to be getting the dollowing
The term &#039;elseif&#039; is not recognized as the name of a cmdlet, function, script f
ile, or operable program. Check the spelling of the name, or if a path was incl
uded, verify that the path is correct and try again.
Any ideas?</description>
		<content:encoded><![CDATA[<p>Hi,<br />
I seem to be getting the dollowing<br />
The term &#8216;elseif&#8217; is not recognized as the name of a cmdlet, function, script f<br />
ile, or operable program. Check the spelling of the name, or if a path was incl<br />
uded, verify that the path is correct and try again.<br />
Any ideas?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vishwas Setty</title>
		<link>http://www.powershellpro.com/powershell-tutorial-introduction/powershell-tutorial-conditional-logic/comment-page-1/#comment-484</link>
		<dc:creator>Vishwas Setty</dc:creator>
		<pubDate>Tue, 25 May 2010 19:26:01 +0000</pubDate>
		<guid isPermaLink="false">http://www.powershellpro.com/powershell-tutorial-introduction/powershell-tutorial-conditional-logic/#comment-484</guid>
		<description>Check and make sure you have administrator rights on the machines that you are trying to run that particular script...And, I guess you should run that script which he has made on that particular machine...you might have to add some more code to do run scripts remotely....Hope tat is right....Hopefully Jesse shud look into this question soon...

Regards
Vishwas</description>
		<content:encoded><![CDATA[<p>Check and make sure you have administrator rights on the machines that you are trying to run that particular script&#8230;And, I guess you should run that script which he has made on that particular machine&#8230;you might have to add some more code to do run scripts remotely&#8230;.Hope tat is right&#8230;.Hopefully Jesse shud look into this question soon&#8230;</p>
<p>Regards<br />
Vishwas</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel</title>
		<link>http://www.powershellpro.com/powershell-tutorial-introduction/powershell-tutorial-conditional-logic/comment-page-1/#comment-453</link>
		<dc:creator>Daniel</dc:creator>
		<pubDate>Mon, 15 Mar 2010 21:01:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.powershellpro.com/powershell-tutorial-introduction/powershell-tutorial-conditional-logic/#comment-453</guid>
		<description>One thing I notice, you mention that appending i or c to operators modifies them to be case in/sensitive, however the examples you provide are -ieq and -ceq.  Though technically append does not refer to the beginning or end of the existing element as the location, by convention, append means to add to the end, just as appendices are at the end of books.  What you are describing here is usually referred to as prepending.</description>
		<content:encoded><![CDATA[<p>One thing I notice, you mention that appending i or c to operators modifies them to be case in/sensitive, however the examples you provide are -ieq and -ceq.  Though technically append does not refer to the beginning or end of the existing element as the location, by convention, append means to add to the end, just as appendices are at the end of books.  What you are describing here is usually referred to as prepending.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kuahara</title>
		<link>http://www.powershellpro.com/powershell-tutorial-introduction/powershell-tutorial-conditional-logic/comment-page-1/#comment-441</link>
		<dc:creator>Kuahara</dc:creator>
		<pubDate>Sun, 24 Jan 2010 09:16:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.powershellpro.com/powershell-tutorial-introduction/powershell-tutorial-conditional-logic/#comment-441</guid>
		<description>For all intents and purposes, consider me a day 1 newbie.  I am trying to use your tutorial to get started.

per your instructions, I copied the contents of your PrintReport.ps1 file into a ps1 file on my local machine.

My desktop (the local machine where the script was run) is running vista ultimate x64.  This machine is in the same workgroup as my laptop which runs Windows XP Pro.

I ran the script from the desktop and input the machine name of the laptop.  I get an access denied error and the script ends.


I also tried running it on my domain (all machines are VM&#039;s).

In the first VM, I have Windows Server 2008 running.  The remaining 4 VM&#039;s are all running windows XP Pro and are named XP1, XP2, XP3, and XP4.

When I run the script from the server and input the XP1 machine name, it hangs for about a minute then returns, &quot;The OS for: XP1 is not supported.&quot;


The OS of XP1 is:
OS=Windows_NT

the version is 5.1.2600

If you&#039;re still watching this, any help is appreciated.  Thanks.</description>
		<content:encoded><![CDATA[<p>For all intents and purposes, consider me a day 1 newbie.  I am trying to use your tutorial to get started.</p>
<p>per your instructions, I copied the contents of your PrintReport.ps1 file into a ps1 file on my local machine.</p>
<p>My desktop (the local machine where the script was run) is running vista ultimate x64.  This machine is in the same workgroup as my laptop which runs Windows XP Pro.</p>
<p>I ran the script from the desktop and input the machine name of the laptop.  I get an access denied error and the script ends.</p>
<p>I also tried running it on my domain (all machines are VM&#8217;s).</p>
<p>In the first VM, I have Windows Server 2008 running.  The remaining 4 VM&#8217;s are all running windows XP Pro and are named XP1, XP2, XP3, and XP4.</p>
<p>When I run the script from the server and input the XP1 machine name, it hangs for about a minute then returns, &#8220;The OS for: XP1 is not supported.&#8221;</p>
<p>The OS of XP1 is:<br />
OS=Windows_NT</p>
<p>the version is 5.1.2600</p>
<p>If you&#8217;re still watching this, any help is appreciated.  Thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jesse Hamrick</title>
		<link>http://www.powershellpro.com/powershell-tutorial-introduction/powershell-tutorial-conditional-logic/comment-page-1/#comment-350</link>
		<dc:creator>Jesse Hamrick</dc:creator>
		<pubDate>Mon, 08 Jun 2009 15:46:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.powershellpro.com/powershell-tutorial-introduction/powershell-tutorial-conditional-logic/#comment-350</guid>
		<description>Arnold,
It looks like a syntax error to me.
Try this example:

$d = 40
If(($d -eq 40) and ($d -lt 50)){$True}

$d = 50
If(($d -eq 50) and ($d -gt 60)){$True}

Hope that helps...</description>
		<content:encoded><![CDATA[<p>Arnold,<br />
It looks like a syntax error to me.<br />
Try this example:</p>
<p>$d = 40<br />
If(($d -eq 40) and ($d -lt 50)){$True}</p>
<p>$d = 50<br />
If(($d -eq 50) and ($d -gt 60)){$True}</p>
<p>Hope that helps&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: arnold</title>
		<link>http://www.powershellpro.com/powershell-tutorial-introduction/powershell-tutorial-conditional-logic/comment-page-1/#comment-349</link>
		<dc:creator>arnold</dc:creator>
		<pubDate>Sun, 07 Jun 2009 09:18:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.powershellpro.com/powershell-tutorial-introduction/powershell-tutorial-conditional-logic/#comment-349</guid>
		<description>hello :)
check both conditions ????
im not able to find the right way !
do you have any idee?
(if or switch condition)

$d41 = 90 (1..50)
1 . if ($d41 -le 50) also &quot;50&quot;
{action} True ?????? but is fault !!!!!
2 . if ($d41 -gt 51 -and $d41 -le 100){action} False ?????? but is right !!!
3 . if ($d41 -gt 101 -and $d41 -le 300){action} False
4 . if ($d41 -gt 301 -and $d41 -le 500){action} False
5 . if ($d41 -gt 501 -and $d41 -le 1000) {action} False
6 . if ($d41 -gt 1001) no limite &gt;
{action} False
many tnx for you help
arnold</description>
		<content:encoded><![CDATA[<p>hello <img src='http://www.powershellpro.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
check both conditions ????<br />
im not able to find the right way !<br />
do you have any idee?<br />
(if or switch condition)</p>
<p>$d41 = 90 (1..50)<br />
1 . if ($d41 -le 50) also &#8220;50&#8243;<br />
{action} True ?????? but is fault !!!!!<br />
2 . if ($d41 -gt 51 -and $d41 -le 100){action} False ?????? but is right !!!<br />
3 . if ($d41 -gt 101 -and $d41 -le 300){action} False<br />
4 . if ($d41 -gt 301 -and $d41 -le 500){action} False<br />
5 . if ($d41 -gt 501 -and $d41 -le 1000) {action} False<br />
6 . if ($d41 -gt 1001) no limite &gt;<br />
{action} False<br />
many tnx for you help<br />
arnold</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jesse Hamrick</title>
		<link>http://www.powershellpro.com/powershell-tutorial-introduction/powershell-tutorial-conditional-logic/comment-page-1/#comment-339</link>
		<dc:creator>Jesse Hamrick</dc:creator>
		<pubDate>Thu, 14 May 2009 18:26:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.powershellpro.com/powershell-tutorial-introduction/powershell-tutorial-conditional-logic/#comment-339</guid>
		<description>How about this...
Write-Host &quot;[1]-Server A&quot;
Write-Host &quot;[2]-Server B&quot;
Write-Host &quot;[3]-Server C&quot;
Write-Host &quot;[4] Server D&quot;

$ServerChoice = Read-Host &quot;Select an option 1-4&quot;

Switch ($ServerChoice)
{
    1		{$server = &quot;Server A&quot;}
    2       {$server = &quot;Server B&quot;}
    3       {$server = &quot;Server C&quot;}
    4       {$server = &quot;Server D&quot;}
    default {$server = &quot;Server A&quot;}
  }

Write-Host &quot;You chose $server&quot;</description>
		<content:encoded><![CDATA[<p>How about this&#8230;<br />
Write-Host &#8220;[1]-Server A&#8221;<br />
Write-Host &#8220;[2]-Server B&#8221;<br />
Write-Host &#8220;[3]-Server C&#8221;<br />
Write-Host &#8220;[4] Server D&#8221;</p>
<p>$ServerChoice = Read-Host &#8220;Select an option 1-4&#8243;</p>
<p>Switch ($ServerChoice)<br />
{<br />
    1		{$server = &#8220;Server A&#8221;}<br />
    2       {$server = &#8220;Server B&#8221;}<br />
    3       {$server = &#8220;Server C&#8221;}<br />
    4       {$server = &#8220;Server D&#8221;}<br />
    default {$server = &#8220;Server A&#8221;}<br />
  }</p>
<p>Write-Host &#8220;You chose $server&#8221;</p>
]]></content:encoded>
	</item>
</channel>
</rss>

