<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Using Replace function in PShell to modify Workspace file]]></title><description><![CDATA[<p dir="auto">I’m trying to use the below PS1 script to replace the username in each line of the Workspace file to a different username. The script works, and the text is replaced correctly, but afterwards the Workspace file no longer works in Notepad++. Is there a specific filetype or encoding I need to set in order for the formatted file to be readable/usable in Notepad++ after the script is run?</p>
<p dir="auto">Thanks.</p>
<pre><code>$path = "c:\Users\$($env:username)\Documents\Workspace File" 
(Get-Content $path) -replace "username1","username2" | out-file $path 
</code></pre>
]]></description><link>https://community.notepad-plus-plus.org/topic/24641/using-replace-function-in-pshell-to-modify-workspace-file</link><generator>RSS for Node</generator><lastBuildDate>Fri, 17 Apr 2026 19:06:55 GMT</lastBuildDate><atom:link href="https://community.notepad-plus-plus.org/topic/24641.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 28 Jun 2023 15:29:28 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Using Replace function in PShell to modify Workspace file on Thu, 29 Jun 2023 15:06:12 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/26973">@Cariboudjan</a> said in <a href="/post/87478">Using Replace function in PShell to modify Workspace file</a>:</p>
<blockquote>
<p dir="auto">Alright. Changing the encoding to UTF8 fixed the issue.</p>
</blockquote>
<p dir="auto">I am glad it seems to be working for you now.</p>
<p dir="auto">A couple of points:</p>
<ol>
<li>The encoding shown on Notepad++'s status line is an estimate based on inspecting the file. The inspection process is not perfect and so I would not load a file into Notepad++ and 100% rely on what it says the encoding of that file seems to be. I have had Notepad++ say “ANSI” for example even when the file has 3 or 4 byte long UTF-8 encoded sequences near the beginning. Figuring out the encoding of a file can be a long topic in itself.</li>
<li>In your code I’m bothered by your use of <code>-NoNewline -Encoding OEM</code>. It just seems weird and is the sort of thing that will lead to unexpected results down the road. However, this forum is about Notepad++ and so I’ll leave it at that rather than topic-drifting into encoding and PowerShell.</li>
</ol>
]]></description><link>https://community.notepad-plus-plus.org/post/87512</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/87512</guid><dc:creator><![CDATA[mkupper]]></dc:creator><pubDate>Thu, 29 Jun 2023 15:06:12 GMT</pubDate></item><item><title><![CDATA[Reply to Using Replace function in PShell to modify Workspace file on Wed, 28 Jun 2023 16:30:41 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/5329">@mkupper</a></p>
<p dir="auto">Alright. Changing the encoding to UTF8 fixed the issue. Below is the full solution:</p>
<pre><code>$path = "c:\Users\$($env:username)\Documents\Workspace File" 
(Get-Content $path) -replace "username1","username2" | out-file $path 
Set-Content -NoNewline -Encoding OEM $path -Value (Get-Content -Raw -Encoding utf8 $path)
</code></pre>
<p dir="auto">Or alternatively, with arguments:</p>
<pre><code>$replace1 = args[0]
$replace2 = args[1]
$path = $args[2]
$encoding = $args[3]

(Get-Content $path) -replace $replace1,$replace2 | out-file $path
Set-Content -NoNewline -Encoding OEM $path -Value (Get-Content -Raw -Encoding $encoding $path)
</code></pre>
]]></description><link>https://community.notepad-plus-plus.org/post/87478</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/87478</guid><dc:creator><![CDATA[Cariboudjan]]></dc:creator><pubDate>Wed, 28 Jun 2023 16:30:41 GMT</pubDate></item><item><title><![CDATA[Reply to Using Replace function in PShell to modify Workspace file on Wed, 28 Jun 2023 16:15:44 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/26973">@Cariboudjan</a> PowerShell’s <code>out-file</code> command outputs utf8NoBOM encoded files by default. From within Notepad++ first look at the right side of the status line at the bottom.  If it says <code>UTF-8</code> then the file should be displayed correctly.  If you see something other than <code>UTF-8</code> then, using the <code>Encoding</code> drop down menu try picking UTF-8 and see if that works for you.  I would not use the Convert to … options nor would I save the file from Notepad++ without first making a backup of the file.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/87476</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/87476</guid><dc:creator><![CDATA[mkupper]]></dc:creator><pubDate>Wed, 28 Jun 2023 16:15:44 GMT</pubDate></item><item><title><![CDATA[Reply to Using Replace function in PShell to modify Workspace file on Wed, 28 Jun 2023 16:12:51 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/14479">@Ekopalypse</a></p>
<p dir="auto">I receive this error when trying to load it in the Project Pane in Notepad++</p>
<p dir="auto"><img src="/assets/uploads/files/1687968640359-bf994030-7347-4604-8795-d98f368f7072-image.png" alt="bf994030-7347-4604-8795-d98f368f7072-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto"><img src="/assets/uploads/files/1687968765658-06b3d631-684c-4f6b-ba30-a6c880828502-image.png" alt="06b3d631-684c-4f6b-ba30-a6c880828502-image.png" class=" img-fluid img-markdown" /></p>
]]></description><link>https://community.notepad-plus-plus.org/post/87475</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/87475</guid><dc:creator><![CDATA[Cariboudjan]]></dc:creator><pubDate>Wed, 28 Jun 2023 16:12:51 GMT</pubDate></item><item><title><![CDATA[Reply to Using Replace function in PShell to modify Workspace file on Wed, 28 Jun 2023 16:01:05 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/26973">@Cariboudjan</a></p>
<p dir="auto">What do you mean by “workspace file” and “no longer works”?<br />
You see a different content when you open the file with npp? If so, what is different?</p>
]]></description><link>https://community.notepad-plus-plus.org/post/87474</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/87474</guid><dc:creator><![CDATA[Ekopalypse]]></dc:creator><pubDate>Wed, 28 Jun 2023 16:01:05 GMT</pubDate></item></channel></rss>