# comment command lines

**URL:** <https://forums.powershell.org/t/comment-command-lines/879>\
**Category:** PowerShell Help\
**Created:** [December 31, 2011, 6:30pm UTC](https://forums.powershell.org/t/comment-command-lines/879 "2011-12-31T18:30:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![archives](https://avatars.discourse-cdn.com/v4/letter/a/bb73d2/32.png) [@archives](https://forums.powershell.org/u/archives)\
**Post date:** [December 31, 2011, 6:30pm UTC](https://forums.powershell.org/t/comment-command-lines/879/1 "2011-12-31T18:30:00Z")

</div>

by willbs at 2013-04-19 08:30:38

> i want to comment out some command lines in a group of powershell scripts but the conversion is not happening, i’m sure it has to do with my handling of the # in $newfile3, here is my code  
>   
> $Folder = ‘C:\PowerShell\PS\_Star\*.\*’  
> $file3 = ‘Invoke-Item $global:OutputReportFile’  
> $newfile3 = ‘#Invoke-Item $global:OutputReportFile’  
>   
> Get-ChildItem $Folder | Where {$\_ -IS [IO.FileInfo]} |   
> % {  
>   
> (Get-Content $_.FullName) -replace $file3,$newfile3 | Set-Content $_.FullName  
>   
> Write-Host "Processed: " + $_.FullName_  
>   
> _}_  
>   
>   
> _any ideas?_

_by sstranger at 2013-04-19 13:04:00_

_> You have placed the # between the single quotes. PowerShell takes everything between single quotes literrally.   
>   
> Stefan Stranger [Microsoft]_

_by willbs at 2013-04-19 15:19:15_

_> that’s what i thought too but the code doesn’t perform the remove and replace_

_by ArtB0514 at 2013-04-22 06:12:52_

> _The use of the single quote marks in your replacement text looks correct to me. Your problem is elsewhere._  
>   
> _To start debugging, I would just process the first file found and break up the pipeline to see which step fails. NOTE: this scriptlet assumes PowerShell V3. (Replace "-File" with "| Where-Object {-not $_.PSIsContainter}" for V2)  
>   
> `Get-ChildItem $Folder -File | Select-Object -First 1 | Foreach-Object { $NewContent = (Get-Content $.FullName) -replace $file3,$newfile3 $NewContent | Set-Content "$($.DirectoryName)$($.BaseName).TST"Write-Host "Processed: " + $.FullName}`  
>   
> This will leave you with a variable ($NewContent) that you can examine, plus the original file and the new file with the extension changed to ".TST" that you can compare. I’d check to see if the -Replace is actually working against the whole file, or if you might need to run it against each line separately.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:58pm UTC](https://forums.powershell.org/t/comment-command-lines/879/2 "2024-05-16T20:58:09Z")

</div>


