<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="https://wiki.twig.es/skins/common/feed.css?303"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://wiki.twig.es/index.php?action=history&amp;feed=atom&amp;title=Powershell_string_contains</id>
		<title>Powershell string contains - Revision history</title>
		<link rel="self" type="application/atom+xml" href="https://wiki.twig.es/index.php?action=history&amp;feed=atom&amp;title=Powershell_string_contains"/>
		<link rel="alternate" type="text/html" href="https://wiki.twig.es/index.php?title=Powershell_string_contains&amp;action=history"/>
		<updated>2026-05-06T14:58:11Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.23.0</generator>

	<entry>
		<id>https://wiki.twig.es/index.php?title=Powershell_string_contains&amp;diff=1537&amp;oldid=prev</id>
		<title>George2: Created page with &quot;&lt;source lang=&quot;text&quot;&gt;  When folks are exploring the operators available in PowerShell (help about_comparison_operators), they'll often run across two similar-seeming, but drast...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.twig.es/index.php?title=Powershell_string_contains&amp;diff=1537&amp;oldid=prev"/>
				<updated>2014-12-08T15:48:27Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot;&amp;lt;source lang=&amp;quot;text&amp;quot;&amp;gt;  When folks are exploring the operators available in PowerShell (help about_comparison_operators), they&amp;#039;ll often run across two similar-seeming, but drast...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;source lang=&amp;quot;text&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When folks are exploring the operators available in PowerShell (help about_comparison_operators), they'll often run across two similar-seeming, but drastically different, operators - and get confused by them.&lt;br /&gt;
&lt;br /&gt;
I'll often see someone try this:&lt;br /&gt;
if ($string -contains '*win*') { }&lt;br /&gt;
&lt;br /&gt;
They're trying to see if $string contains the letters &amp;quot;win,&amp;quot; but unfortunately that's not what -contains does. What they really want to use is the -like operator:&lt;br /&gt;
if ($string -like '*win*') { }&lt;br /&gt;
&lt;br /&gt;
I know it doesn't read as nicely when you say it out loud. Sounds kinda Valley Girl, I suppose. &amp;quot;If, like, this variable, like, is like, you know, this wildcard, omigod, like really?&amp;quot; But -like is the correct operator for this task.&lt;br /&gt;
&lt;br /&gt;
The -contains operator is a bit trickier. It's designed to tell you if a collection of objects includes ('contains') a particular object. Now, if your collection of object is a bunch of strings, this is pretty straightforward.&lt;br /&gt;
$coll = &amp;quot;one','two','three','four'&lt;br /&gt;
if ($coll -contains 'one') { }&lt;br /&gt;
&lt;br /&gt;
It gets harder when the collection contains complex objects. This won't work like you might think:&lt;br /&gt;
$coll = Get-Service&lt;br /&gt;
if ($coll -contains 'BITS') { }&lt;br /&gt;
&lt;br /&gt;
The variable $coll does not contain the string &amp;quot;BITS;&amp;quot; what it contains is a service object whose Name property is BITS. You can't really use -contains in this fashion, because it compares the entire object. For example:&lt;br /&gt;
# Get all processes&lt;br /&gt;
$procs = Get-Process&lt;br /&gt;
&lt;br /&gt;
# Get just one process&lt;br /&gt;
$proc = Get-Process | Select -first 1&lt;br /&gt;
&lt;br /&gt;
# Check it&lt;br /&gt;
$procs -contains $proc&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>George2</name></author>	</entry>

	</feed>