Creating Powershell Task

Hello All,
I am trying to remove some preinstalled apps on my computers.
I found Powershell Script to do that.
When trying to run it as a task , i receive Complete status but nothing gets removed.
I tried to create a PS1 file and run it, same thing
are there additional commands I need to add , for this to work??
Thank you in advance

$apps=@(
“E046963F.LenovoCompanion” #Vantage
"Microsoft.549981C3F5F10" #Cortana
"Microsoft.BingWeather" #Bing
#“Microsoft.GetHelp” #Microsoft Help
"Microsoft.Getstarted" #Get Started Hub
"Microsoft.Microsoft3DViewer" #3D Viewer
#“Microsoft.MicrosoftEdge.Stable” #Edge
"Microsoft.MicrosoftOfficeHub" #Office 2016 Hub
"Microsoft.MicrosoftSolitaireCollection" #Solitaire
)

foreach ($app in $apps) {
Write-Output $app
Get-AppxPackage -Name $app -AllUsers | Remove-AppxPackage
Get-AppXProvisionedPackage -Online | where DisplayName -EQ $app | Remove-AppxProvisionedPackage -Online

$appPath="$Env:LOCALAPPDATA\Packages\$app*"
Remove-Item $appPath -Recurse -Force -ErrorAction 0

}

Hi Igor,

Which version of BigFix are you running? BigFix 10 has native powershell support now within a fixlet so you could execute it there.

In terms of your current scripting and if you are not running BF10 you have curly braces so they need to be escaped in the action script. To escape them, for each open curly brace in the powershell, replace it with two open curly braces. { becomes {{

createfile until end
$apps=@(
“E046963F.LenovoCompanion” #Vantage
"Microsoft.549981C3F5F10" #Cortana
"Microsoft.BingWeather" #Bing
#“Microsoft.GetHelp” #Microsoft Help
"Microsoft.Getstarted" #Get Started Hub
"Microsoft.Microsoft3DViewer" #3D Viewer
#“Microsoft.MicrosoftEdge.Stable” #Edge
"Microsoft.MicrosoftOfficeHub" #Office 2016 Hub
"Microsoft.MicrosoftSolitaireCollection" #Solitaire
)

foreach ($app in $apps) {{
Write-Output $app
Get-AppxPackage -Name $app -AllUsers | Remove-AppxPackage
Get-AppXProvisionedPackage -Online | where DisplayName -EQ $app | Remove-AppxProvisionedPackage -Online

$appPath="$Env:LOCALAPPDATA\Packages\$app*"
Remove-Item $appPath -Recurse -Force -ErrorAction 0
}
end
delete C:\file.ps1
copy __createfile C:\file.ps1

waithidden powershell.exe C:\file.ps1

I have BigFix 10.0.4 patch
I know that it supposed to work directly by pasting the script
Unfortunately , it fails every time. I tried your version too. I receive a complete status, but nothing is being executed

With BF10, if you plan to run native PS then you need to select it from the dropdown list otherwise it will run as action script.

If it’s still failing, I’d advise to enable debug logging on the endpoint to get more information on where it’s falling down and perhaps writing some exit codes into your powershell too.

I’m no powershell expert, in fact I am really poor with it but I can see you have declared a variable $app however it’s not defined anywhere.

1 Like

Thank you for your Help
I decided to try again this solution , and it worked
I’m Attaching the full script that worked for me
Maybe somebody else need it too :
action uses wow64 redirection {not x64 of operating system}
folder create "C:\vss"
createfile until end
#Windows 10 Default App Removal Script

#--------------------------------------------------------------------------------------
$apps=@(
“E046963F.LenovoCompanion” #Vantage
"Microsoft.549981C3F5F10" #Cortana
"Microsoft.BingWeather" #Bing
#“Microsoft.GetHelp” #Microsoft Help
"Microsoft.Getstarted" #Get Started Hub
"Microsoft.Microsoft3DViewer" #3D Viewer
#“Microsoft.MicrosoftEdge.Stable” #Edge
"Microsoft.MicrosoftOfficeHub" #Office 2016 Hub
"Microsoft.MicrosoftSolitaireCollection" #Solitaire
#“Microsoft.MicrosoftStickyNotes” #Sticky Notes
"Microsoft.MixedReality.Portal" #VR Module
#“Microsoft.MSPaint” #Paint
"Microsoft.Office.OneNote" #One Note
"Microsoft.People" #People Hub
#“Microsoft.ScreenSketch” #Snipping Tool
"Microsoft.SkypeApp" #Skype
#“Microsoft.StorePurchaseApp” #Microsoft Store
#“Microsoft.Wallet” #Wallet
#“Microsoft.Windows.Photos” #Photos Hub
#“Microsoft.WindowsAlarms” #Alarms and Clock
#“Microsoft.WindowsCalculator” #Calculator
#“Microsoft.WindowsCamera” #Camera
"microsoft.windowscommunicationsapps" #Default Mail and Calendar Apps
"Microsoft.WindowsFeedbackHub" #Feedback Hub
"Microsoft.WindowsMaps" #Maps
"Microsoft.WindowsSoundRecorder" #Recorder
#“Microsoft.WindowsStore” #App Store – DO NOT REMOVE
"Microsoft.Xbox.TCUI" #Xbox
"Microsoft.XboxApp" #Xbox
"Microsoft.XboxGameOverlay" #Xbox
"Microsoft.XboxGamingOverlay" #Xbox
"Microsoft.XboxIdentityProvider" #Xbox
"Microsoft.XboxSpeechToTextOverlay" #Xbox
"Microsoft.YourPhone" #Windows Phone Connector
"Microsoft.ZuneMusic" #Zune or Groove Music
"Microsoft.ZuneVideo" #Zune Video or Groove Video
)

foreach ($app in $apps) {{
Write-Output $app
Get-AppxPackage -Name $app -AllUsers | Remove-AppxPackage
Get-AppXProvisionedPackage -Online | where DisplayName -EQ $app | Remove-AppxProvisionedPackage -Online

$appPath="$Env:LOCALAPPDATA\Packages\$app*"
Remove-Item $appPath -Recurse -Force -ErrorAction 0

}

#Get-AppxPackage -Name “Microsoft.WindowsStore” -AllUsers | Remove-AppxPackage #This is the benign way to remove App Store without unprovisioning… so you can get it back.
#Get-AppXProvisionedPackage -online | Select DisplayName
#Get-AppxPackage | Select Name, PackageFullName

end
delete "C:\vss\vss.ps1"
move __createfile "C:\vss\vss.ps1"
waithidden powershell.exe -executionpolicy bypass -file “C:\vss\vss.ps1”

1 Like