运行if语句时,PowerShell 会将<test1>条件表达式计算为 true 或 false。 如果<test1>为 true,<statement list 1>则运行,PowerShell 退出 语句if。 如果<test1>为 false,则 PowerShell 将计算条件语句指定的<test2>条件。 有关布尔计算的详细信息,请参阅about_Booleans。
Also, by default Powershell already includes the Boolean variables $True and $False to represent True and False. You can use them in any session or script. Evan7191(Evan7191)July 17, 2017, 1:09pm9 Example: If (condition is true) { return $True } If (negative condition is true) { r...
PS> [bool]::Parse('false') False PS> [bool]::Parse('True') True PS> [bool]::Parse('Not True') MethodInvocationException: Exception calling"Parse"with"1"argument(s):"String 'Not True' was not recognized as a valid Boolean."
$Env:<variable-name> = "<new-value>" 例如,若要建立 Foo 環境變數: PowerShell 複製 $Env:Foo = 'An example' 因為環境變數一律是字串,所以您可以使用它們,就像包含字元串的任何其他變數一樣。 例如: PowerShell 複製 "The 'Foo' environment variable is set to: $Env:Foo" $Env:Foo +...
若要刪除變數的值,請使用 Clear-Variable Cmdlet 或將值變更為 $null。 PowerShell 複製 Clear-Variable -Name MyVariable PowerShell 複製 $MyVariable = $null 若要刪除變數,請使用 Remove-Variable 或Remove-Item。 PowerShell 複製 Remove-Variable -Name MyVariable PowerShell 複製 Remove-Item -Pa...
[-Variable <PSObject>] [-InputFile <String>] [-OutputSqlErrors <Boolean>] [-IncludeSqlUserErrors] [-OutputAs <OutputType>] -ConnectionString <String> [-KeyVaultAccessToken <String>] [-ManagedHsmAccessToken <String>] [-StatisticsVariable <String>] [-ProgressAction <ActionPreference>] [<...
The containment and type operators always return a Boolean value The -replace operator returns the replacement result The -match and -notmatch operators also populate the $Matches automatic variable unless the left-hand side of the expression is a collection. Equality operators -eq and -ne W...
AddCommand(String, Boolean) Add a cmdlet to construct a command pipeline. For example, to construct a command string "get-process | sort-object", Copy PowerShell shell = PowerShell.Create("get-process").AddCommand("sort-object"); AddCommand(String) Add a cmdlet to construct a ...
New-DistributionGroup[-Name] <String> [-Alias <String>] [-ArbitrationMailbox <MailboxIdParameter>] [-BccBlocked <Boolean>] [-BypassNestedModerationEnabled <Boolean>] [-Confirm] [-CopyOwnerToMember] [-Description <MultiValueProperty>] [-DisplayName <String>] [-DomainController <Fqdn>] [-Hidden...
Here is your last example. If a variable is defined, we use its value to determine TRUE/FALSE but if the variable is not defined – it is FALSE. PS> $x=10 PS> test $x TRUE PS> $x=0 PS> test $x FALSE PS> test $NoSuchVariable ...