Copy to Clipboard
# 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"
}
|