I’ve tried today on a test system.
- The coding doesn’t work in my region. I suggest too replace
STRING
withALTSTRING
.
2. But even if the encoding is fixed, theTest-Path
could never gets a $true
I remember darkly there was a issue with Test-Path and removeable devices, but I cannot remember the details.
My debugging code so far:
$CopyFrom = "C:\Windows\System32\calc.exe"; $CopyTo = "copy"
$FindMe = "gfhnubkw.txt"; $f = $false
While (-not $f) {
Foreach ($USBDrive in (Get-WmiObject -Class Win32_Volume -Filter {DriveType=2}).Name) {
If (Test-Path (Join-Path -Path $USBDrive -ChildPath $FindMe)) {
$f = $true; Write-Host "Copying... $(((Get-ChildItem $CopyFrom | Measure-Object -Sum Length).Sum)/1MB) MB to $USBDrive, where $(((Get-Volume -DriveLetter $USBDrive.Substring(0,1)).SizeRemaining)/1MB) MB are remaining"
Copy-Item -Path $CopyFrom -Destination $USBDrive\$CopyTo -Recurse -ErrorAction SilentlyContinue } #;Exit }
Continue }} #Exit
Is my Win10 (Up to date) the only one, which does not work?
(Join-Path -Path $USBDrive -ChildPath $FindMe)
gives the correct result, but the If is always $false. If I perform this on a harddrive by changing the variables, it works.
Also with Test-Path
instead of [System.IO.File]::Exists()
, I just playes with other know functions.
Edit: Make Code more compact.