obtener_estado_de_robocopy_discos_vbr_y_enviar_como_mail_html
- VBR_report.ps1
$toSend = "C:\Temp\logFile.txt" $rcLog = "C:\Temp\rcLog.txt" $cimInstanceLog = "C:\Temp\cimInstanceLog.txt" $foreachOutput = "C:\Temp\VBROutput.txt" # sincronizar el repositorio con el disco externo # Run robocopy and save the output to a file robocopy F:\Backups E:\Backups /MIR > $rcLog # Read the file content $robocopyOutput = Get-Content $rcLog -Raw # Save the HTML content to a file $htmlContent | Out-File -FilePath $toSend -Encoding UTF8 # anexar el estado de los discos Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DriveType= 3" | Select-Object DeviceID, @{Name="Size (GB)"; Expression={"{0:N2}" -f ($_.Size / 1GB)}}, @{Name="Free Space (GB)"; Expression={"{0:N2}" -f ($_.FreeSpace / 1GB)}}, @{Name="Free Space (%)"; Expression={"{0:P2}" -f ($_.FreeSpace / $_.Size)}} > $cimInstanceLog # Read the file content $cimInstanceOutput = Get-Content $cimInstanceLog -Raw Import-Module Veeam.Backup.Powershell $repos = Get-VBRBackupRepository $htmlFragment = foreach ($repo in $repos) { $container = $repo.GetContainer() [PSCustomObject]@{ RepositoryName = $repo.Name CachedTotalSpace = $container.CachedTotalSpace CachedFreeSpace = $container.CachedFreeSpace UsagePercent = [math]::Round(($container.CachedFreeSpace / $container.CachedTotalSpace) * 100) } } # Convert the objects to HTML table $htmlTable = $htmlFragment | ConvertTo-Html -As Table -Fragment # Build the HTML content $htmlContent = @" <h2>Sincronizar repositorio</h2> <pre>$robocopyOutput</pre> <h2>Discos locales</h2> <pre>$cimInstanceOutput</pre> <h2>Repositorios Veeam Backup</h2> $htmlTable "@ # Save the HTML content to a file $htmlContent | Out-File -FilePath $toSend -Encoding UTF8 #Configuration for email sending $emailFrom = "[email protected]" $subject = "Veeam Report" $emailTo = "[email protected]" $body = Get-Content $toSend | Out-String $smtpServer = "smtp.example.com" $smtpPort = xx $username = "[email protected]" $password = "********" # Create a secure string from the plain text password $securePassword = ConvertTo-SecureString -String $password -AsPlainText -Force # Create a PSCredential object with the username and secure password $credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $username, $securePassword # Send the email using Send-MailMessage with authentication Send-MailMessage -From $emailFrom -To $emailTo -Subject $subject -BodyAsHtml -Body $body ` -SmtpServer $smtpServer -Port $smtpPort -Credential $credential
obtener_estado_de_robocopy_discos_vbr_y_enviar_como_mail_html.txt · Last modified: 2024/10/17 21:42 by 127.0.0.1
