Categories:
  🠪  General

Email
  🠪  Servers
  🠪  Testing
  🠪  Tips

Hardware
  🠪  3D Printing
  🠪  Apple
  🠪  Batteries
  🠪  Drives
  🠪  Edgerouter
  🠪  Electronics
  🠪  Laptop
  🠪  Modems
  🠪  Phone
  🠪  Printers
  🠪  Raspberry Pi
  🠪  Tablets
  🠪  Testing
  🠪  Virtualization

hidden
  🠪  General

Links
  🠪  Interesting
  🠪  Media

Network
  🠪  Data
  🠪  Testing
  🠪  VPN

Scripts
  🠪  Batch
  🠪  Linux
  🠪  Powershell

Servers
  🠪  Databases
  🠪  Misc
  🠪  Website

Software
  🠪  Other

Utilities
  🠪  Backup
  🠪  Fix Issues
  🠪  Recovery

Video
  🠪  Editing

Websites
  🠪  HTML
  🠪  Testing

Windows
  🠪  Adjustments
  🠪  Issues
  🠪  Remote Desktop
  🠪  Security
  🠪  Slow
  🠪  Software
  🠪  Startup

Submit Entry
Airin's Notes

Category: Scripts 🠪 Powershell
Simple script to select the right backup drive where the drive letter may change
November 27, 2023

# This lets you create a file in the root of a backup drive, then this script will search all drive letters for it
# It will then start a batch file passing the drive letter to the batch file
# The batch file will only be called if the backup drive is found


$Drives = Get-PSDrive
$DriveLetter = ""
$MatchFilePath = "BackupA.txt"
$BackupScript = "D:\Temp\test.bat"
# $BackupScript will be called with a plain drive letter like this: cmd.exe /c c:\BackupScript.bat E

foreach ( $Drive in $Drives ){
if ( $Drive.Provider.Name -eq "FileSystem" ){
if ( Test-Path "$($Drive.Root)$($MatchFilePath)" ){
$DriveLetter = $Drive.Name
}
}
}

If ( $DriveLetter.Length -gt 0 ){
Write-Host "Found backup drive $($DriveLetter):, starting script $BackupScript"

Start-Process -FilePath "cmd.exe" -ArgumentList @("/B", "/C", $BackupScript, $DriveLetter);

}else{
Write-Host "Backup drive not found"
}





This site is meant to be used as a reference for myself, although others may find it useful. I use it to keep track of certain fixes, software, and other solutions which I may need while assisting customers. The page layout is pure HTML/CSS and is kept simple to optimize loading time and fast results.

Return to Airin's Computers