#Variables
$logfile = "\\hermamora\Public\Plex Backup\Logs\Plex_Backup_Log_$(get-date -format "yyyyMMdd").txt"
function log($string, $color)
{
if ($Color -eq $null) {$color = "white"}
Write-Host $string -ForegroundColor $color
$string | Out-File -Filepath $logfile -Append
}
function Main {
robocopy Q:\ L:\ /v /mir /z /r:1 /w:5
}
$main = Main
#Arguments for Email
$From = "FROMADDRESS"
$To = "TOADDRESS"
#$Attachment = $logfile
$Subject = "Plex Backup Success"
$Body = "Here is the log of the Plex DB Backup, It was able to complete successfully"
$SMTPServer = "smtp.gmail.com"
$SMTPPort = "587"
$login = "USERNAME"
$password = "PASSWORD" | ConvertTo-SecureString -AsPlainText -Force
$credentials = New-Object System.Management.Automation.Pscredential -Argumentlist $login,$password
#Main Script
#Sets up Drives for Easy copy
subst L: "\\hermamora\Public\Plex Backup\Backup"
subst Q: "C:\Users\ztownes\AppData\Local\Plex Media Server"
#Stops Plex and Copies DB
taskkill /IM "Plex Media Server.exe"
Start-Sleep -Seconds 15
log $main
Start-Sleep -Seconds 15
Start-process "C:\Program Files (x86)\Plex\Plex Media Server\Plex Media Server.exe"
#Removes Drives for unclutering
subst /d L:
subst /d Q:
Start-Sleep -Seconds 5
#Sends Email
Send-MailMessage -From $From -To $To -Cc $Cc -Subject $Subject -Body $Body -SmtpServer $SMTPServer -Port $SMTPPort -UseSsl -Credential $credentials -Attachments $logfile
Start-Sleep -Seconds 5
每当我尝试运行此代码时,都无法找到驱动器L:和Q:for robocopy
。我能够在Windows资源管理器中看到驱动器。我有一个几乎完全相同的PowerShell脚本运行它没有问题。出于明显的安全原因,我已从电子邮件参数中删除了电子邮件地址和密码。