Removing unwanted lines in file?

Hi there do you know a way to remove unused line in the : Deploy-Application.ps1
specific i want to clean it up a bit by removing these session but how would i managed that with powershell:

	## Handle Zero-Config MSI Installations
		If ($Disabled_useDefaultMsi) {
			[hashtable]$ExecuteDefaultMSISplat =  @{ Action = 'Install'; Path = $defaultMsiFile }; If ($defaultMstFile) { $ExecuteDefaultMSISplat.Add('Transform', $defaultMstFile) }
			Execute-MSI @ExecuteDefaultMSISplat; If ($defaultMspFiles) { $defaultMspFiles | ForEach-Object { Execute-MSI -Action 'Patch' -Path $_ } }
		}

	## Handle Zero-Config MSI Uninstallations
	If ($Disabled_useDefaultMsi) {
		[hashtable]$ExecuteDefaultMSISplat =  @{ Action = 'Uninstall'; Path = $defaultMsiFile }; If ($defaultMstFile) { $ExecuteDefaultMSISplat.Add('Transform', $defaultMstFile) }
		Execute-MSI @ExecuteDefaultMSISplat
	}

So any input how to handle this task?

if you’re asking how to remove those lines, you can simply delete all of those. You’ve successfully captured the full block of code that needs to be removed.

Otherwise use the powershell block comment <# #> to comment out the whole section.

I came up with something like this to do the cleanup of the file.

function Zero-ConfigCleanup ($file)
{
function LineNumber ($pattern, $file)
{
$LineNumber = Select-String -Path $file -Pattern $pattern | Select-Object -ExpandProperty LineNumber
return [int]$LineNumber
}

function del-line($start, $end, $file)
{
	$i = 0
	$start--
	$end--
	(Get-Content $file) | where {
		($i -lt $start -or $i -gt $end)
		$i++
	} | set-content $file -Encoding utf8
}

if ($(LineNumber -pattern "## Handle Zero-Config MSI Installations" -file $file))
{
	$start = LineNumber -pattern "## Handle Zero-Config MSI Installations" -file $file
	$end = $start + 5
	del-line -start $start -end $end -file $file
}

if ($(LineNumber -pattern "## Handle Zero-Config MSI Uninstallations" -file $file))
{
	$start = LineNumber -pattern "## Handle Zero-Config MSI Uninstallations" -file $file
	$end = $start + 5
	del-line -start $start -end $end -file $file
}

}