I found the below code to search a Window 7 workstation for any USB Removable Drive (a memory stick really) on the internet years ago. I still don't fully understand the "/F", "tokens=1*", "tokens=3", "in (fsutil fsinfo drives)" and "in (fsutil fsinfo drivetype %%c)".
Now I have a new Windows 10 workstation and need to convert to PowerShell 5. Can anyone help me get started on how to convert this .bat to .ps1?
I am on...
Major 5
Minor 1
Build 16299
Revision 98
@echo off
echo Workstation backup
:tryAgain
set isUSBfound=false
for /F "tokens=1*" %%a in ('fsutil fsinfo drives') do (
for %%c in (%%b) do (
for /F "tokens=3" %%d in ('fsutil fsinfo drivetype %%c') do (
if %%d equ Removable (
echo Drive %%c is Removable (USB^)
call "F:\scripts\backups\Backup.bat" %%c
set isUSBfound=true
)
)
)
)
if not %isUSBfound%==true (
echo USB drive not found. Enter USB drive and press enter to try again.
pause
goto tryAgain
)
date /t
time /t
pause