$result = If ($condition) {"true"} Else {"false"}
For use in or as an expression, not just an assignment, wrap it in $()
, thus:
write-host $(If ($condition) {"true"} Else {"false"})
More Related Contents:
- PowerShell says “execution of scripts is disabled on this system.”
- Create objects with custom properties containing derived filesystem path information and export them to a CSV – calculated properties
- What’s the best way to determine the location of the current PowerShell script?
- Using a Variable (PowerShell) inside of a command
- Changing PowerShell’s default output encoding to UTF-8
- PowerShell outputting array items when interpolating within double quotes
- Powershell Invoke-WebRequest Fails with SSL/TLS Secure Channel
- How can I find the Upgrade Code for an installed MSI file?
- How to enter a multi-line command
- Add a where-object on a table construct?
- How to redirect the output of a PowerShell to a file during its execution
- PSCustomObject to Hashtable
- How can I make PowerShell handle [ or ] in file name well?
- How do I write to standard error in PowerShell?
- Saving credentials for reuse by powershell and error ConvertTo-SecureString : Key not valid for use in specified state
- Controlling column widths with Format-Table
- Calling dynamic variable in PowerShell
- Passing string in Get-ADUser filter parameter causes error – property not found in pscustomobject
- Iterate over PSObject properties in PowerShell
- How to use the curl command in PowerShell?
- Ignoring an errorlevel != 0 in Windows PowerShell (ISE)
- $string.Substring Index/Length exception
- Loading Assemblies from NuGet Packages
- Issue with Powershell update string in each file within a folder
- Output file doesn’t match Write-Host
- Running CMD command in PowerShell
- Can’t install nuget package because of “Failed to initialize the PowerShell host”
- How to run powershell command in batch file
- Is there a PowerShell equivalent of `paste` (i.e., horizontal file concatenation)? [duplicate]
- Prevent trailing newline in PowerShell Out-File command