If (!(Get-PSDrive R -PSProvider FileSystem -ErrorAction SilentlyContinue)) {
#this function checks for the latest exe of google drive. Then tries to start it.
Import-Module C:\Tasks\Modules\Find-LatestFileVersion\Find-LatestFileVersion.psm1
$GdfsPath = Find-LatestFileVersion -fileName "GoogleDriveFS.exe" -filePath "$Env:Programfiles\Google"
Try {
Start-Process $GdfsPath.FilePath | Wait-Process -Timeout 30
}
Catch {
Write-Warning "Drive R to Google Drive can't be mapped. $Email failed to record seperation."
$mailBody = "Drive R to Google Drive can't be mapped. $Email failed to record seperation."
$mailSubject = "Drive R to Google Drive can't be mapped. $Email failed to record seperation."
Send-MailMessage @MailArguments -to $ENV:BUILD_USER_EMAIL -Subject $mailSubject -Body $mailBody
throw "Drive R to Google Drive can't be mapped. $Email failed to record seperation."
}
Finally {
If (!(Get-PSDrive R -PSProvider FileSystem -ErrorAction SilentlyContinue)) {
Write-Warning "Drive R to Google Drive can't be mapped. $Email failed to record seperation."
$mailBody = "Drive R to Google Drive can't be mapped. $Email failed to record seperation."
$mailSubject = "Drive R to Google Drive can't be mapped. $Email failed to record seperation."
Send-MailMessage @MailArguments -to $ENV:BUILD_USER_EMAIL -Subject $mailSubject -Body $mailBody
throw "Drive R to Google Drive can't be mapped. $Email failed to record seperation."
}
}
}
Above tests if the drive is mapped. If not tries to start Google Drive and then tests again.
The big issue is the assumption that google drive is the R: drive. There does not seem to be a command line that will start google drive with a drive letter or a means to test if a drive letter is a google drive.
Thoughts?