Converting the Dictionary Object's Exists Method


Windows PowerShell


Definition: Checks to see if a specified key exists. Returns True if the key exists, False if not.

Exists

In PowerShell you can check for the existence of a key or an item. Here we use the ContainsKey method to check for the existence of a specific key:


if ($food.ContainsKey("carrot"))
{
    Write-Host "There are carrots"
}


You use the ContainsValue method to check for the existence of a specific item:


if ($food.ContainsValue("vegetable"))
{
    Write-Host "There are vegetables"
}


See conversions of other Dictionary object methods and properties.
Return to the VBScript to Windows PowerShell home page

Show: