Forum Discussion
vivek10688
Jul 26, 2022Copper Contributor
Comment Or Un-Comment Multiple Lines In PowerShell Script
Problem Statement: I have a PowerShell script and before executing it I want to comment multiple lines using PowerShell command Series Of Steps Need To Performed 1. Comment multiple lines in Power...
vivek10688
Jul 26, 2022Copper Contributor
Hi ,
Thanks for answering. However, that is not the use case, I want to do the same thing but through power shell script like using Get-content and loop over through lines and dynamically find out if block start & it's end and then commented out.
Thanks for answering. However, that is not the use case, I want to do the same thing but through power shell script like using Get-content and loop over through lines and dynamically find out if block start & it's end and then commented out.
farismalaeb
Jul 26, 2022Iron Contributor
Another question, You have 3 If block, how the script knows which block should be commented?
- vivek10688Jul 27, 2022Copper ContributorHi ,
Let say you have the content of powershell script in variable called $filecontent and then you do iteration in foreach loop where you do match string like 'RestartNumber -le 1' of if block and then gets line number and insert '<#' before the linenumber and eventually using same logic to get the line number of end of the if block and insert '#>' after the linenumber. This way the second if block will be commented out and will not be executed during execution of powershell script The purpose is simple comment the if block which you do not want to get it execute but not manually instead through powershell script.
Thanks
Vivek