######################################## # Config strings, def, includes, funciones, etc ######################################## $prod="C:\WebSites\STING" $back="C:\Temporal\Backups_Pasajes\STING_Backups" $uat="\\bccdmz02\STING_UAT" set-alias 7z "$env:ProgramFiles\7-Zip\7z.exe" $7zSource = "$back\rollback" $7zTarget = "$back\STING_$((Get-Date).ToString('yyyy-MM-dd'))" $logFile = "C:\Scripts\Pase a Prod\log.txt" Import-Module WebAdministration # Self-elevate the script if required if (-Not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator')) { if ([int](Get-CimInstance -Class Win32_OperatingSystem | Select-Object -ExpandProperty BuildNumber) -ge 6000) { $CommandLine = "-File `"" + $MyInvocation.MyCommand.Path + "`" " + $MyInvocation.UnboundArguments Start-Process -FilePath PowerShell.exe -Verb Runas -ArgumentList $CommandLine Exit } } function Send-ToEmail([string]$email, [string]$body){ $message = new-object Net.Mail.MailMessage; $message.From = "bccba.Sistemas@bccba.org.ar"; $message.To.Add($email); $message.Subject = "*** Finalizado *** Mantenimiento STING - $((Get-Date).ToString('dd/MM/yyyy'))"; $message.Body = $body; $smtp = new-object Net.Mail.SmtpClient("smtp.bccba.org.ar", "25"); $smtp.EnableSSL = $false; $smtp.send($message); write-host "Mail Sent"; } (Get-Date).ToString('dd/MM/yyyy') | Tee-Object -FilePath $logfile -Append ######################################## # Backup current version ######################################## $do = @("/COPYALL","/B","/SEC","/MIR") $options = @("/R:1","/W:5","/NFL","/NDL") $cmdArgs = @("$prod","$back\rollback",$do,$options) robocopy @cmdArgs >| Tee-Object -FilePath $logfile -Append ######################################## # Stop Site. Delete current version, save Web.config ######################################## Stop-WebSite 'STING' rm -r $prod\* -Exclude "Web.config" >| Tee-Object -FilePath $logfile -Append ######################################## # Copy STING:latest from QA ######################################## robocopy $uat $prod /COPYALL /B /SEC /MIR /R:1 /W:5 /NFL /NDL /XF Web.config >| Tee-Object -FilePath $logfile -Append ######################################## # Start Website. ######################################## Start-WebSite 'STING' ######################################## # Compress the folder which contains the old version, and save it for archiving purposes... ######################################## 7z a -mx=3 $7zTarget $7zSource >| Tee-Object -FilePath $logfile -Append ######################################## # Send email ######################################## $bodyContent = Get-Content $logFile -Raw Send-ToEmail -email "bccba.Sistemas@bccba.org.ar" -body $bodyContent