Skip to content

Instantly share code, notes, and snippets.

@theevangelista
Forked from chriskyfung/Adb-PullAppData.ps1
Created February 27, 2024 23:55
Show Gist options
  • Save theevangelista/26c88cc02684b72ff6ef1734399cd4e1 to your computer and use it in GitHub Desktop.
Save theevangelista/26c88cc02684b72ff6ef1734399cd4e1 to your computer and use it in GitHub Desktop.
A PowerShell script interactively guides you pull app data from (/sdcard/Android/data/) to your local machine via Android Debug Bridge (adb)
<#
.SYNOPSIS
Pull Android App data from the internal storage of
a device via Android Debug Bridge (adb).
.DESCRIPTION
The Adb-PullAppData.ps1 script uses interavtive prompts to guide you pull app data
from (/sdcard/Android/data/$APPNAME) to the local machine.
It will asks the port number for connecting the device, and asks whether you want
to create a new folder for storing the copied data.
.INPUTS
None. You cannot pipe objects to Adb-PullAppData.ps1.
.OUTPUTS
None. Adb-PullAppData.ps1 does not generate any output.
.EXAMPLE
PS> .\Adb-PullAppData.ps1
#>
# Specify the target Android App Package Name
$APPNAME = com.example.application
# Ask for port number of the target device
[ValidatePattern('^\d{1,4}$')]$PORT = Read-Host -Prompt "Enter the port number"
# Use adb to connect the target device
adb connect localhost:$PORT
# Get the connection status
$CONNECTED = adb devices | findstr "\<$PORT\>"
# If connected
if ($CONNECTED) {
$title = 'Confirm'
$question = 'Do you want to create a new folder?'
$choices = '&Yes', '&No'
# Ask whether create a new folder in the current directory
$ConfirmNewFolder = $Host.UI.PromptForChoice($title, $question, $choices, 1)
# If yes, ask for the new folder name, then create and change directory
if ($ConfirmNewFolder -eq 0) {
[ValidatePattern('^\d.\d$')]$FOLDERNAME = Read-Host -Prompt "Enter the app version"
New-Item -Path ".\$FOLDERNAME" -ItemType Directory
cd $FOLDERNAME
}
# Ask for confirmation before pulling the app data
$PWD = Get-Location
$question = 'Do you confirm to pull files to "' + $PWD + '"?'
$ConfirmPullData = $Host.UI.PromptForChoice($title, $question, $choices, 1)
# If yes, use adb pull command to copy the app data
if ($ConfirmPullData -eq 0) {
adb pull /sdcard/Android/data/$APPNAME .
}
# Change back to the parent directory if new folder has made
if ($ConfirmNewFolder -eq 0) {
cd ..
}
}
# Disconnect from the target device
adb disconnect localhost:$PORT
<# End of script #>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment