GuideProgramming + ScriptingPowershell Simple script to select the right backup drive where the drive letter may change Updated August 11 2024
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" }




©2024 - Some portions of this website are Copyrighted.
Your IP: 18.222.20.250     Referring URL:
Browser: Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Terms and Conditions, Privacy Policy, and Security Policy