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."
}
}
}
以上测试驱动器是否已映射。如果没有尝试启动 Google Drive,然后再次测试。
最大的问题是假设谷歌驱动器是 R: 驱动器。似乎没有命令行可以使用驱动器号启动 google 驱动器或测试驱动器号是否为 google 驱动器的方法。
想法?