Describes a language command you can use to run statement lists based (about_If)

   
# TOPIC
about_If

# SHORT DESCRIPTION
Describes a language command you can use to run statement lists based
on the results of one or more conditional tests.

# LONG DESCRIPTION
You can use the If statement to run code blocks if a specified
conditional test evaluates to true. You can also specify one or more
additional conditional tests to run if all the prior tests evaluate to
false. Finally, you can specify an additional code block that is run if
no other prior conditional test evaluates to true.

Syntax
The following example shows the If statement syntax:

if (<test1>)
{<statement list 1>}
[elseif (<test2>)
{<statement list 2>}]
[else
{<statement list 3>}]

When you run an If statement, Windows PowerShell evaluates the
<test1> conditional expression as true or false. If <test1> is true,
<statement list 1> runs, and Windows PowerShell exits the If statement.
If <test1> is false, Windows PowerShell evaluates the condition specified
by the <test2> conditional statement.

If <test2> is true, <statement list 2> runs, and Windows PowerShell
exits the If statement. If both <test1> and <test2> evaluate to false,
the <statement list 3> code block runs, and Windows PowerShell exits
the If statement.

You can use multiple Elseif statements to chain a series of conditional
tests so that each test is run only if all the previous tests are
false. If you need to create an If statement that contains many
Elseif statements, consider using a Switch statement instead.

Examples
The simplest If statement contains a single command
and does not contain any Elseif statements or any Else statements. The
following example shows the simplest form of the If statement:

if ($a -gt 2)
{
Write-Host "The value $a is greater than 2."
}

In this example, if the $a variable is greater than 2, the condition
evaluates to true, and the statement list runs. However, if $a is less
than or equal to 2 or is not an existing variable, the If statement does
not display a message. By adding an Else statement, a message is displayed
when $a is less than or equal to 2, as the next example shows:

if ($a -gt 2)
{
Write-Host "The value $a is greater than 2."
}
else
{
Write-Host "The value $a is less than or equal to 2, is not
created or is not initialized."
}

To further refine this example, you can use the Elseif statement to
display a message when the value of $a is equal to 2, as the next
example shows:

if ($a -gt 2)
{
Write-Host "The value $a is greater than 2."
}
elseif ($a -eq 2)
{
Write-Host "The value $a is equal to 2."
}
else
{
Write-Host "The value $a is less than 2 or was not created
or initialized."
}

SEE ALSO
about_Comparison_Operators
about_Switch

C:\Windows>powershell get-help about_jobs -full

ColorConsole [Version 1.7.1000] PowerShell 2.0-Export
Microsoft Windows [Version 6.1.7600]
Copyright (c) 2014 Microsoft Corporation.

OS: Windows-10 / Windows-8.1 & 8 / Windows-7 & Vista / Windows Server 2008-2016
»»»» ColorConsole



 


... Home  
... Impressum
... ColorConsole

... CMD
... Netsh-XP
... Netsh-7
... Netsh-Vista
... Powershell





;-)









Download the Windows 7 Starter, Home (Basic Premium), Professional und Ultimate!

... facebook.de
0.062
Kann man die nicht komprimierbaren Dateien auch mit 7-Zip nicht komprimieren?!  / What is Program Files (x86) Folder in Windows 8.1 / 10 64-Bit (x64)?  / IE8.0 was now automatically updated to the latest ver., but on the surface is nothing to see?  / How do I open/start directly the Windows-7 Task Manager, keyboard shortcuts?  / Kann ich einen Wiederherstellungspunkt in Windows-8 u. 8.1 manuell erstellen?  / Windows 10 change password, remove, or set a new password, but where?  / Wo finde ich die Windows Bildschirmtastatur?  / The wrong program opens a file Why?  / Wie kann ich rechts der Adressleiste und des Pulldown-Menüs den HD-Schnellzugriff abschalten?  / Hiberfil.sys auf ein anderes Laufwerk, weil meine SSD bei Windows 8.1/8 voll ist!  / Kann man mit Freeware Geld verdienen!  / Adressleisten Regeln in Q-Dir sind wie im Windows MS-Explorer!  /