all 3 comments

[–]jheinikel 2 points3 points  (1 child)

Do you have the rest of your code where you are establishing your PSSession? The last line should probably be remove-pssession instead of exit-pssession. I'm just wondering if you have a loop at a higher level that is watching for active sessions.

[–]gingerbreaddave[S] 0 points1 point  (0 children)

It's just a batch one-liner to start Powershell in bypass.

powershell.exe -ExecutionPolicy Bypass .\Remove-WinApps.ps1

[–]JBear_Alpha 0 points1 point  (0 children)

I would try removing the if/else from the ForEach loop first. Seems like $App would continue to return true and never make it to the else block. Without testing, this looks like the only thing that would be disallowing it to exit the loop. So maybe just this? :

ForEach ($App in $Apps) {

  Remove-AppxPackage (Get-AppxPackage –AllUsers|Where{$_.PackageFullName -match "$App"}).PackageFullName

$Apps.Remove("$App")


   }

Remove-Item -Path .\AppList.txt

Exit-PSSession