I have a simple script to make file transfers between a local directory and an MTP device. For the MTP device, I created a ComObject and traversed to the desired directory. Then, I use the CopyHere function to copy, using the option 20 which is supposed to suppress the progress bar and say yes to any dialog.
however, I find that all dialogs are still there including a confirmation for replacing the file:

I also tried deleting the files first as seen in the code, but then I get this:

param ([string]$ListFile = "C:\Users\benriveraflores\Documents\Projects\Switch Saves Sync\Save Directories.txt")
$shell = New-Object -ComObject Shell.Application
$root = $shell.NameSpace(0x11).self
Get-Content $ListFile | ForEach-Object {
if ($_ -match '^\s*$' -or $_ -match '^\s*#') { return }
$parts = $_ -split "`t", 2
if ($parts.Count -ne 2) { return }
$src = $parts[0].Trim()
$dest = $parts[1].Trim()
$destParts = $dest.Split('\')
$destDevice = $destParts[1]
$destPath = $destParts[2..($destParts.Count - 1)] -join '\'
$destDeviceObj = $root.GetFolder.Items() | Where-Object { $_.Name -eq $destDevice }
$destFolder = $destDeviceObj.GetFolder
$destPath.Split('\') | ForEach-Object {
$folderName = $_
$nextItem = $destFolder.Items() | Where-Object { $_.Name -eq $folderName }
$destFolder = $nextItem.GetFolder
}
Get-ChildItem -Path $src -File | ForEach-Object {
$fileName = $_.Name
$fileToDelete = $destFolder.Items() | Where-Object { $_.Name -eq $fileName }
$fileToDelete.InvokeVerbEx('delete', 20)
}
Get-ChildItem -Path $src | ForEach-Object {
$destFolder.CopyHere($_.FullName, 20)
}
}
All I want is to suppress all the dialogs.
Does anyone know how to fix it? If not, is there any other more reliable way to interface with MTP devices for scripting?
adbis a great way but is limited to Android. Since (I assume) you are interacting with a Switch here, you may check out the MediaDevices library. I can post an example of using that library with Powershell if you would like.