<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.technet.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Use PowerShell to Replace Text in Strings</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2011/03/21/use-powershell-to-replace-text-in-strings.aspx</link><description>Summary : The Scripting Wife learns how to use Windows PowerShell and regular expressions to replace text in strings. 
 Microsoft Scripting Guy, Ed Wilson, here. I just finished a meeting with the Microsoft TechEd people about doing a series of five</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>re: Use PowerShell to Replace Text in Strings</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2011/03/21/use-powershell-to-replace-text-in-strings.aspx#3569973</link><pubDate>Tue, 30 Apr 2013 15:45:24 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3569973</guid><dc:creator>Sofi</dc:creator><description>&lt;p&gt;Great story man!&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3569973" width="1" height="1"&gt;</description></item><item><title>re: Use PowerShell to Replace Text in Strings</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2011/03/21/use-powershell-to-replace-text-in-strings.aspx#3549951</link><pubDate>Fri, 01 Feb 2013 20:06:09 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3549951</guid><dc:creator>JV</dc:creator><description>&lt;p&gt;Test if a replacement occurred:&lt;/p&gt;
&lt;p&gt;if( ($s -replace &amp;#39;b&amp;#39;,&amp;#39;c&amp;#39;) -ne $s){&amp;#39;string replaced&amp;#39;}else{&amp;#39;not replaced&amp;#39;}&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3549951" width="1" height="1"&gt;</description></item><item><title>re: Use PowerShell to Replace Text in Strings</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2011/03/21/use-powershell-to-replace-text-in-strings.aspx#3549945</link><pubDate>Fri, 01 Feb 2013 19:43:39 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3549945</guid><dc:creator>lucid_data</dc:creator><description>&lt;p&gt;@Dan r.e. &amp;quot;What&amp;#39;s all that about!?!? No relevance whatsoever. Not even funny.&amp;quot;&lt;/p&gt;
&lt;p&gt;Lighten up, Francis.&lt;/p&gt;
&lt;p&gt;I found the article informative; I appreciate the authors efforts.&lt;/p&gt;
&lt;p&gt;Whether funny or just a bit silly the dialogue was effective at explaining some subtle points.&lt;/p&gt;
&lt;p&gt;@Scott:&lt;/p&gt;
&lt;p&gt;r.e. telling if replace actually replaced anything without comparing old/new strings&lt;/p&gt;
&lt;p&gt;Yeah, I wish PowerShell could do that.&lt;/p&gt;
&lt;p&gt;Looks like Perl got that one right. &amp;nbsp;I am finding this to be a very helpful overview btw:&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;www.johndcook.com/regex.html&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3549945" width="1" height="1"&gt;</description></item><item><title>re: Use PowerShell to Replace Text in Strings</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2011/03/21/use-powershell-to-replace-text-in-strings.aspx#3548381</link><pubDate>Fri, 25 Jan 2013 14:54:53 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3548381</guid><dc:creator>Dan</dc:creator><description>&lt;p&gt;&amp;quot;“Yoo hoo, Scripting Wife,” I said with a rather loud voice.&lt;/p&gt;
&lt;p&gt;I waited for a seemingly long time, with my ears straining for the slightest sound.&lt;/p&gt;
&lt;p&gt;“Hmm…where did she go?” I said to myself. “Where are you, my dear?”&lt;/p&gt;
&lt;p&gt;Without warning, she was standing in the doorway of my home office. I do not know how she does that. At times, it seems that she floats silently through the house.&lt;/p&gt;
&lt;p&gt;“Did you bellow?” she asked mockingly.&lt;/p&gt;
&lt;p&gt;“I am not certain ‘bellow’ is the correct word—perhaps ‘discretely inquire’ would be better,” I suggested.&lt;/p&gt;
&lt;p&gt;“I am not your blog that you can edit. I said bellow,” she stated matter-of-factly.&lt;/p&gt;
&lt;p&gt;“Well then…I ‘bellowed.’ You need to learn some more regular expressions if you expect to compete in this year’s Windows PowerShell Scripting Games,” I said.&lt;/p&gt;
&lt;p&gt;“Instruct me, oh my magnificent fount of scripting knowledge,” I imagined her saying.&lt;/p&gt;
&lt;p&gt;“Show me, Script Monkey,” she actually said.&amp;quot;&lt;/p&gt;
&lt;p&gt;What&amp;#39;s all that about!?!? No relevance whatsoever. Not even funny.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3548381" width="1" height="1"&gt;</description></item><item><title>re: Use PowerShell to Replace Text in Strings</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2011/03/21/use-powershell-to-replace-text-in-strings.aspx#3511202</link><pubDate>Fri, 27 Jul 2012 13:11:24 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3511202</guid><dc:creator>jrv</dc:creator><description>&lt;p&gt;@Keith&lt;/p&gt;
&lt;p&gt;$anchor_address=$user_address -replace $email_domain,$anchor_domain)&lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="http://social.technet.microsoft.com/Forums/en-us/ITCG/threads"&gt;social.technet.microsoft.com/.../threads&lt;/a&gt;&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3511202" width="1" height="1"&gt;</description></item><item><title>re: Use PowerShell to Replace Text in Strings</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2011/03/21/use-powershell-to-replace-text-in-strings.aspx#3511151</link><pubDate>Fri, 27 Jul 2012 04:54:32 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3511151</guid><dc:creator>Keith</dc:creator><description>&lt;p&gt;This is great, just what I was looking for for a script pack I&amp;#39;m working on for Exchange 2010 cross-forest migrations with preflight validation goodness.&lt;/p&gt;
&lt;p&gt;One problem though, I&amp;#39;m using an INI file to define global variables (reading in data from the INI into globals works fine).&lt;/p&gt;
&lt;p&gt;I end up with two string variables, lets call them $email_domain and $anchor_domain. &amp;nbsp;If the users address is in $user_address and I want to replace the user domain with the anchor domain, I then run this:&lt;/p&gt;
&lt;p&gt;$anchor_address = $user_address.replace($email_domain,$anchor_domain)&lt;/p&gt;
&lt;p&gt;Problem is it doesn&amp;#39;t seem to work, it&amp;#39;s like it isn&amp;#39;t finding the $email_domain string value. &amp;nbsp;If I replace it with a literal it works fine. &amp;nbsp;Ideas? &amp;nbsp;Do I need to cast it or something?&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3511151" width="1" height="1"&gt;</description></item><item><title>re: Use PowerShell to Replace Text in Strings</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2011/03/21/use-powershell-to-replace-text-in-strings.aspx#3507281</link><pubDate>Tue, 03 Jul 2012 18:41:21 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3507281</guid><dc:creator>Jose Lopez</dc:creator><description>&lt;p&gt;Doug,&lt;/p&gt;
&lt;p&gt;You are missing the comma in the last statement. &amp;nbsp;It should read:&lt;/p&gt;
&lt;p&gt;$a = $a -replace &amp;quot;something&amp;quot;, $b&lt;/p&gt;
&lt;p&gt;Regards.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3507281" width="1" height="1"&gt;</description></item><item><title>re: Use PowerShell to Replace Text in Strings</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2011/03/21/use-powershell-to-replace-text-in-strings.aspx#3507264</link><pubDate>Tue, 03 Jul 2012 17:40:59 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3507264</guid><dc:creator>Doug</dc:creator><description>&lt;p&gt;Is there a way to use variables in the -replace option (e.g. &lt;/p&gt;
&lt;p&gt;$a = &amp;quot;I want to be doing something else.&amp;quot;&lt;/p&gt;
&lt;p&gt;$b = &amp;quot;anything&amp;quot;&lt;/p&gt;
&lt;p&gt;$a = $a -replace &amp;quot;something&amp;quot; $b&lt;/p&gt;
&lt;p&gt;This gives an error in PS. Can it be done in some way?&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3507264" width="1" height="1"&gt;</description></item><item><title>re: Use PowerShell to Replace Text in Strings</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2011/03/21/use-powershell-to-replace-text-in-strings.aspx#3498135</link><pubDate>Tue, 15 May 2012 16:33:41 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3498135</guid><dc:creator>Scott</dc:creator><description>&lt;p&gt;Is there any way to tell if the replace actually happened without comparing the result with the original string? &amp;nbsp;It would be nice if $Matches or $0 were set, but they don&amp;#39;t appear to be. &amp;nbsp;Are there any other automatic variables set on a replace? &amp;nbsp;I&amp;#39;ve even tried using a [regex] object and hoping something is set in that object, but I could not find anything.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3498135" width="1" height="1"&gt;</description></item><item><title>re: Use PowerShell to Replace Text in Strings</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2011/03/21/use-powershell-to-replace-text-in-strings.aspx#3415502</link><pubDate>Thu, 24 Mar 2011 03:38:28 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3415502</guid><dc:creator>IamMred</dc:creator><description>&lt;p&gt;@Steve yes you have to save it back.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3415502" width="1" height="1"&gt;</description></item></channel></rss>