1

I build a script to remove Windows 10 Apps per Python. I saved the apps to remove in a String Array and save the complete command in a variable.

Then I run the command, come a Error with: The Remove-AppxPackage command is either misspelled or could not be found.

And I have coded following code:

    win10Apps = ["3d", "camera"]
       for app in win10Apps:
       psCommand = "Get-AppxPackage " + app + " | Remove-AppxPackage"
       pyautogui.press("Enter")
       os.system("powershell.exe " + psCommand)
       pyautogui.press("Enter")
jonrsharpe
  • 115,751
  • 26
  • 228
  • 437

1 Answers1

0

As JosefZ mentioned in the comments, you have to format your parameter when calling other executable.

The fixed code looks like this:

win10Apps = ["3d", "camera"]
for app in win10Apps:
    psCommand = "Get-AppxPackage " + app + " | Remove-AppxPackage"
    pyautogui.press("Enter")
    os.system('powershell.exe -c "{}"'.format( psCommand))
    pyautogui.press("Enter")

Also for special characters you need to escape. Also, here is the documentation for Get-AppxPackage and for Remove-AppxPackage.

zerocukor287
  • 555
  • 2
  • 8
  • 23