<?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>Mon, 06 Sep 2010 23:05:11 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<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>
	<item>
		<title>By: Fajza</title>
		<link>http://www.powershellpro.com/powershell-tutorial-introduction/powershell-tutorial-conditional-logic/comment-page-1/#comment-336</link>
		<dc:creator>Fajza</dc:creator>
		<pubDate>Thu, 14 May 2009 17:49:21 +0000</pubDate>
		<guid isPermaLink="false">http://www.powershellpro.com/powershell-tutorial-introduction/powershell-tutorial-conditional-logic/#comment-336</guid>
		<description>Regarding the conditional statement &#039;Switch&#039;, I have looked around a little and can&#039;t seem to find how to accomplish what I need it to do.  It would seem that &#039;Switch&#039; will only output statements to the screen?  I claims that it will &#039;process whatever is in {}&#039; but all the examples are {&#039;literal&#039;} or [Write-Host &#039;literal&#039;}, which works fine.  What I need to know is how to make whatever I put in the script block work.  Example: I want to display choices on the screen, read the users&#039; choice into a variable, run a Switch command that will compare the users&#039; input and perform the code in {} that corresponds to that choice, ie.

Write-Host &quot; Server A&quot;
Write-Host &quot; Server B&quot;
Write-Host &quot; Server C&quot;
Write-Host &quot; Server D&quot;

$ServerChoice = Read-Host &quot;Select one&quot;

$Server = Switch ($ServerChoice)
{
  {
    1       {Server A}
    2       {Server B}
    3       {Server C}
    4       {Server D}
    default {Server B}
  }
}

$Databases = Get-MailboxServer $Server &#124; Get-MailboxDatabase -status &#124; sort-object Name

As you can probably deduce, I am trying to assign the output of the Switch statement to a variable that is to be used in the Get-MailboxServer commandlet which is piped into the Get-MailboxDatabase command.  Am I wrong to think that I could use Switch in this manner?  Can Switch even output anything besides text to the screen?  Further, can Switch be used in such a way as to assign it&#039;s output to a variable?</description>
		<content:encoded><![CDATA[<p>Regarding the conditional statement &#8216;Switch&#8217;, I have looked around a little and can&#8217;t seem to find how to accomplish what I need it to do.  It would seem that &#8216;Switch&#8217; will only output statements to the screen?  I claims that it will &#8216;process whatever is in {}&#8217; but all the examples are {&#8216;literal&#8217;} or [Write-Host &#8216;literal&#8217;}, which works fine.  What I need to know is how to make whatever I put in the script block work.  Example: I want to display choices on the screen, read the users&#8217; choice into a variable, run a Switch command that will compare the users&#8217; input and perform the code in {} that corresponds to that choice, ie.</p>
<p>Write-Host &#8221; Server A&#8221;<br />
Write-Host &#8221; Server B&#8221;<br />
Write-Host &#8221; Server C&#8221;<br />
Write-Host &#8221; Server D&#8221;</p>
<p>$ServerChoice = Read-Host &#8220;Select one&#8221;</p>
<p>$Server = Switch ($ServerChoice)<br />
{<br />
  {<br />
    1       {Server A}<br />
    2       {Server B}<br />
    3       {Server C}<br />
    4       {Server D}<br />
    default {Server B}<br />
  }<br />
}</p>
<p>$Databases = Get-MailboxServer $Server | Get-MailboxDatabase -status | sort-object Name</p>
<p>As you can probably deduce, I am trying to assign the output of the Switch statement to a variable that is to be used in the Get-MailboxServer commandlet which is piped into the Get-MailboxDatabase command.  Am I wrong to think that I could use Switch in this manner?  Can Switch even output anything besides text to the screen?  Further, can Switch be used in such a way as to assign it&#8217;s output to a variable?</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-263</link>
		<dc:creator>Jesse Hamrick</dc:creator>
		<pubDate>Fri, 05 Dec 2008 17:23:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.powershellpro.com/powershell-tutorial-introduction/powershell-tutorial-conditional-logic/#comment-263</guid>
		<description>Hi Kallio,
Try using a variable to capture the Process object (Firefox) and then test the condition.

#Assign object to a variable
$FF = Get-Process -Name &quot;Firefox&quot;
#Test condition and action to take when result is true.
If ($FF.CPU -lt 70){Write-Host &quot;Firefox is using acceptable CPU resources&quot;}</description>
		<content:encoded><![CDATA[<p>Hi Kallio,<br />
Try using a variable to capture the Process object (Firefox) and then test the condition.</p>
<p>#Assign object to a variable<br />
$FF = Get-Process -Name &#8220;Firefox&#8221;<br />
#Test condition and action to take when result is true.<br />
If ($FF.CPU -lt 70){Write-Host &#8220;Firefox is using acceptable CPU resources&#8221;}</p>
]]></content:encoded>
	</item>
</channel>
</rss>
