first commit
This commit is contained in:
commit
1f2722fa8a
136
Copy-Revit2Egnyte.ps1
Normal file
136
Copy-Revit2Egnyte.ps1
Normal file
@ -0,0 +1,136 @@
|
||||
<#
|
||||
Copy all files in this folder structure to Egnyte.
|
||||
Each folder should contain a path.txt file with the Egnyte Path where these files live.
|
||||
|
||||
This script will copy these files to Egnyte nightly. It will email helpdesk@mpe.ca with any folders that do NOT contain a PATH.TXT file, as well as any failures.
|
||||
|
||||
|
||||
|
||||
#>
|
||||
|
||||
$Local_Revit_Root = "R:\"
|
||||
$OnPrem_DataCollector = "\\192.168.2.75\scache\Shared\"
|
||||
$ErrorMessage = @()
|
||||
|
||||
## Email Values
|
||||
$smtpserver = 'mail.mpe.ca'
|
||||
$smtpport = 25
|
||||
$From = "helpdesk@mpe.ca"
|
||||
$send_to = "eeckert@mpe.ca"
|
||||
$subject_line = "Errors: Revit to Egnyte Sync"
|
||||
|
||||
function Send-Email {
|
||||
# Basic Send Email function
|
||||
param (
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string]$To,
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string]$Subject,
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string]$Body,
|
||||
[Parameter(Mandatory = $false)]
|
||||
[string[]]$AttachmentPaths
|
||||
)
|
||||
|
||||
# Create a new MailMessage object
|
||||
$MailMessage = New-Object System.Net.Mail.MailMessage
|
||||
$MailMessage.From = $From
|
||||
$MailMessage.To.Add($To)
|
||||
$MailMessage.Subject = $Subject
|
||||
$MailMessage.Body = $Body
|
||||
$MailMessage.IsBodyHtml = $true
|
||||
|
||||
# Add attachments to the MailMessage
|
||||
foreach ($AttachmentPath in $AttachmentPaths) {
|
||||
if (Test-Path $AttachmentPath) {
|
||||
$Attachment = New-Object System.Net.Mail.Attachment($AttachmentPath)
|
||||
$MailMessage.Attachments.Add($Attachment)
|
||||
}
|
||||
else {
|
||||
Write-Host "Attachment not found: $AttachmentPath"
|
||||
}
|
||||
}
|
||||
|
||||
# Configure SMTP client
|
||||
$SMTPClient = New-Object System.Net.Mail.SmtpClient($SMTPServer, $SMTPPort)
|
||||
# $SMTPClient.EnableSsl = $true
|
||||
# $SMTPClient.Credentials = New-Object System.Net.NetworkCredential($Username, $Password)
|
||||
|
||||
# Send the email
|
||||
try {
|
||||
$SMTPClient.Send($MailMessage)
|
||||
Write-Host "Email sent successfully to $To"
|
||||
}
|
||||
catch {
|
||||
Write-Host "Error sending email: $_"
|
||||
}
|
||||
}
|
||||
|
||||
$Local_Folder_List = get-childitem -path $Local_Revit_Root -Depth 0 -Directory
|
||||
|
||||
foreach ($folder in $Local_Folder_List) {
|
||||
if ($folder.Name -eq "!TEMPLATE") {
|
||||
# Do nothing
|
||||
}
|
||||
else {
|
||||
$FolderName = $folder.Name
|
||||
$path_to_pathtxt = $folder.FullName + "\path.txt"
|
||||
$PAthTXT_Exists = Test-Path $path_to_pathtxt
|
||||
|
||||
|
||||
if ($PAthTXT_Exists) {
|
||||
$NumberofLines = get-content $path_to_pathtxt | measure -Line
|
||||
$Egnyte_Path = get-content $path_to_pathtxt
|
||||
$OnPrem_DC_Path = $Egnyte_Path.Replace("M:\", $OnPrem_DataCollector)
|
||||
$OnPrem_DataCollector_up = Test-Path $OnPrem_DC_Path
|
||||
|
||||
if ($OnPrem_DataCollector_up) {
|
||||
# Validate Egnyte Path
|
||||
if (!(Test-Path $Egnyte_Path)) {
|
||||
$Egnyte_Path_Valid = $false
|
||||
$ErrorMessage += $FolderName + ": Path.txt error: Egnyte Path Doesn't Exist.<br />"
|
||||
}
|
||||
else {
|
||||
$Egnyte_Path_Valid = $true
|
||||
}
|
||||
if (!($NumberofLines.Lines -eq 1)) {
|
||||
$Egnyte_Path_Valid = $false
|
||||
$ErrorMessage += $FolderName + ": Path.txt must specify only one path.<br />"
|
||||
|
||||
}
|
||||
else {
|
||||
$Egnyte_Path_Valid = $true
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
# copy files to Egnyte
|
||||
if ($Egnyte_Path_Valid) {
|
||||
Write-Output "Copying $foldername to Egnyte"
|
||||
# $Source_Path = $folder.FullName + "\*"
|
||||
$Source_Path = $folder.FullName
|
||||
robocopy.exe $Source_Path $OnPrem_DC_Path /MT:5 /w:5 /r:5 /XO /COPY:DAT
|
||||
# Copy-Item $Source_Path $OnPrem_DC_Path -Force -Recurse
|
||||
}
|
||||
} else {
|
||||
$ErrorMessage += $FolderName + ": On Premise Path not Valid: $OnPrem_DC_Path. <font color='red'>Is the server up?</font><br />"
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
else {
|
||||
$ErrorMessage += $FolderName + ": Path.txt error: Path.txt doesn't exist.<br />"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($ErrorMessage) {
|
||||
#If we have errors, send an email to be handled.
|
||||
$email_body = "<html><body><H2>Errors reported during the Revit Sync Process</h2><br /><br />$ErrorMessage</body></html>"
|
||||
Send-Email -To $send_to -Subject $subject_line -Body $email_body
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user