# Removing unwanted lines in file?

**URL:** <https://discourse.psappdeploytoolkit.com/t/removing-unwanted-lines-in-file/2199>\
**Category:** General Discussion\
**Created:** [October 25, 2019, 7:27am UTC](https://discourse.psappdeploytoolkit.com/t/removing-unwanted-lines-in-file/2199 "2019-10-25T07:27:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![long](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.psappdeploytoolkit.com/long/32/276_2.png) [@long](https://discourse.psappdeploytoolkit.com/u/long)\
**Post date:** [October 25, 2019, 7:27am UTC](https://discourse.psappdeploytoolkit.com/t/removing-unwanted-lines-in-file/2199/1 "2019-10-25T07:27:12Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![suprnova74](https://avatars.discourse-cdn.com/v4/letter/s/7ab992/32.png) [@suprnova74](https://discourse.psappdeploytoolkit.com/u/suprnova74)\
**Post date:** [October 28, 2019, 1:29pm UTC](https://discourse.psappdeploytoolkit.com/t/removing-unwanted-lines-in-file/2199/2 "2019-10-28T13:29:44Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![long](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.psappdeploytoolkit.com/long/32/276_2.png) [@long](https://discourse.psappdeploytoolkit.com/u/long)\
**Post date:** [October 28, 2019, 2:07pm UTC](https://discourse.psappdeploytoolkit.com/t/removing-unwanted-lines-in-file/2199/3 "2019-10-28T14:07:52Z")

</div>

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
}

```

}

---

<div class="post-metadata">

**Author:** ![That-Annoying-Guy](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.psappdeploytoolkit.com/that-annoying-guy/32/22_2.png) [@That-Annoying-Guy](https://discourse.psappdeploytoolkit.com/u/That-Annoying-Guy)\
**Post date:** [March 26, 2025, 5:32pm UTC](https://discourse.psappdeploytoolkit.com/t/removing-unwanted-lines-in-file/2199/4 "2025-03-26T17:32:35Z")

</div>


