
In the above PowerShell script, the $str variable contains the string data.

It searches if a string contains the substring in it or not $str = "WelCome to ShellGeek Tutorials!" In such a case, use PowerShell like operator with a wildcard character (*) to check if a string contains a specified string. The output of the above PowerShell script to check if the string contains a value is: PS C:\> $str = "WelCome to ShellGeek Tutorials!" PowerShell contains operator checks $str matches the entire value or not, it doesn’t contain the entire value, hence returns a False value. We have used PowerShell contains operator to check if the given string contains a word ShellGeek. In the following operator, the $str variable contains the string. It checks for the entire value match in the given string and returns True if it is present else False.

PowerShell string contains operator checks the string contains the value. PS C:\> Using PowerShell String contains operator PS C:\> $str = "WelCome to ShellGeek Tutorials!" It returns the True value after string comparison. In the above PowerShell script, we have used ToLower() method over the string object $str to convert it into lowercase and use the Contains method to check if the string contains the value. ToLower() method converts an entire string to lowercase so that it can be used while during the string comparison. To solve this case-sensitive string comparison check if a string contains a value inside the string, use ToLower() method over the string object. In the above Powershell script, Contains() method checks for word shell and it returns false as it doesn’t find it. Original string $str contains the Shell, hence string comparison will return false. Let’s consider the above to check the work shell in the given string.Ĭontains method takes a lowercase word shell to check if a string contains it. PowerShell Contains method performs a case-sensitive string comparison and returns the result.
