I am new to powershell scripting and kindly bear with my stupidity if any present. I am trying to write a script to backup selected folders from my Android phone, which shows up as a MTP device in Windows.Before copying for connecting I had found two pieces of code to connect and create a object (i think) for the phone.
Code 1
function Get-PhoneMainDir($phoneName)
{
$o = New-Object -com Shell.Application
$rootComputerDirectory = $o.NameSpace(0x11)
$phoneDirectory = $rootComputerDirectory.Items() | Where-Object {$_.Name -eq $phoneName} | select -First 1
if($phoneDirectory -eq $null)
{
throw "Not found '$phoneName' folder in This computer. Connect your phone."
}
return $phoneDirectory;
}
$phoneName = "ONEPLUS A3003"
$phoneRootDir = Get-PhoneMainDir $phoneName
Write-Host $phoneRootDir
Code 2
function Get-Phone
{
param($phoneName)
$shell = Get-ShellProxy
# 17 (0x11) = ssfDRIVES from the ShellSpecialFolderConstants (https://msdn.microsoft.com/en-us/library/windows/desktop/bb774096(v=vs.85).aspx)
# => "My Computer" — the virtual folder that contains everything on the local computer: storage devices, printers, and Control Panel.
# This folder can also contain mapped network drives.
$shellItem = $shell.NameSpace(17).self
$phone = $shellItem.GetFolder.items() | where { $_.name -eq $phoneName }
return $phone
}
function Get-ShellProxy
{
if( -not $global:ShellProxy)
{
$global:ShellProxy = new-object -com Shell.Application
}
$global:ShellProxy
}
$phoneName ="ONEPLUS A3003"
$phone = Get-Phone -phoneName $phoneName
Write-Host $phone
Write-Host $phone.GetFolder.Items()
trying to print $phoneRootDir in code 1 as well as $phone and $phone.GetFolder.Items() gives me
System.__ComObject
how do I get list the files and traverse through with this object?