I want to make PowerShell script that removes pre-installed app and I have list of those apps.
The problem is, I want to make script to run certain command first, and only if the command failed, run another command.
Like, if script failed to remove app, then it will try to disable that app. No need to try disabling app that already removed, right?
adb shell am force-stop <app> # force stop app
adb shell am kill <app> # kill app if not force-stopped
adb uninstall <app> # remove app
adb shell pm disable-user --user 0 <app> # disable app for user 0 if not removed
Yes, there are some already-answered, similar question like this. But those are not working right now.
PS > adb shell "pm uninstall com.google.android.apps.photos; echo $?"
Failure [DELETE_FAILED_INTERNAL_ERROR]
True
Even if the command failed(Failure
), echo
returns True
.
This is tested with latest(just downloaded few minutes ago) ADB and Android 11, so my information('that doesn't working!') is more 'latest' I guess.
So, how to use return code of ADB command in PowerShell?
PS. If you want what I've coded for more inspection, here it is: LINK
It has been modified not to use echo
, but still no success.