Files

223 lines
7.6 KiB
PowerShell

$Mail_SMTP = New-Object Net.Mail.SmtpClient($tsenv:OSDSendMailSMTPServer)
$InfosEtab = Get-InfosEtab
$NomLycee = $InfosEtab.NomLycee
#On récupère les infos WSUS sur le client
$Key = "HKLM:\SOFTWARE\Policies\Microsoft\windows\WindowsUpdate"
$TargetGroup = Get-ItemPropertyValue $Key -Name "TargetGroup"
$WUServer = Get-ItemPropertyValue $Key -Name "WUServer"
$WUStatusServer = Get-ItemPropertyValue $Key -Name "WUStatusServer"
#On récupère les infos Kaspsersky sur le client
$Key_KSC = "HKLM:\SOFTWARE\Wow6432Node\KasperskyLab\Components\34\1103\1.0.0.0\Statistics\AVState"
$KSC_IP = Get-ItemPropertyValue $Key_KSC -Name "Protection_AdmServer"
$KSC_AV = Get-ItemPropertyValue $Key_KSC -Name "Protection_AvInstalled"
if ( $KSC_AV = "1" )
{
$KSC_AV = "Oui"
}
Else
{
$KSC_AV = "Non"
}
$Mail_From = "$tsenv:OSDSENDMAILFROM"
$Mail_To = "$tsenv:OSDSendMailToPri"
$Mail_CC = "$tsenv:OSDSendMailToSec"
$MyData = Get_My_MonitoringData | Select Date, "Computer Name", DeployID, "Percent Complete", PercentNumber, "Step Name", Warnings, Errors, "Start time", "End Time", "Ellapsed time", DeployStatus
$Deployment_Date = $MyData.Date
$Deployment_ComputerName = $MyData."Computer name"
$Deployment_Status = $MyData.DeployStatus
$Deployment_LastTime = $MyData.LastTime
$Deployment_StepName = $MyData."Step Name"
$Deployment_Warnings = $MyData.Warnings
$Deployment_Errors = $MyData.Errors
$Deployment_Percent_Complete = $MyData."Percent Complete"
$Deployment_Start_time = $MyData."Start time"
$Deployment_End_time = $MyData."End Time"
$Deployment_Ellapsedtime = $MyData."Ellapsed time"
# COPIER LE SCRIPT DE NOTIFICATION ICI
# SCRIPT DE NOTIFICATION MAIL
If ($tsenv:OSDSendMailIncludeBDDLog -eq "YES")
{
$AttachToMail001 = new-object Net.Mail.Attachment($tsenv:LOGPATH + "\BDD.log")
#$NewMsg.Attachments.Add($AttachToMail001)
}
If ($Deployment_Status -eq 4) # deployment unresponsive
{
$Body = "<p>
<span>Bonjour,<br><br>
Déploiement de Système d'Exploitation <strong><span style=color:red>ne réponds pas</span></strong> depuis l'ordinateur: <span style=color:blue><strong>$Deployment_ComputerName</strong></span> - $(get-date)
<br><br>
<span style=color:black>
Voir ci-dessous quelques informations sur votre déploiement :
<br><br>
<strong>Lycée: </strong>$NomLycee
<br>
<strong>Computer name: </strong>$Deployment_ComputerName
<br>
<strong>TaskSequenceName: </strong>$TSEnv:TASKSEQUENCENAME
<br>
<strong>Vendor: </strong>$TSEnv:Make
<br>
<strong>Model: </strong>$TSEnv:Model
<br>
<strong>Lenovo Model: </strong>$TSEnv:LenovoModel
<br>
<strong>Memory: </strong>$TSEnv:Memory Megabyte
<br>
<strong>SerialNumber: </strong>$TSEnv:SerialNumber
<br>
<strong>AssetTag: </strong>$TSEnv:AssetTag
<br>
<strong>Start time: </strong>$Deployment_Start_time
<br>
<strong>Last time: </strong>$Deployment_LastTime
<br>
<strong>Warning: </strong>$Deployment_Warnings
<br>
<strong>Error: </strong>$Deployment_Errors
<br>
<strong>Step name: </strong>$Deployment_StepName
<br>
<strong>Percent: </strong>$Deployment_Percent_Complete
<br>
<strong>Groupe WSUS: </strong>$TargetGroup
<br>
<strong>WUServer: </strong>$WUServer
<br>
<strong>WUStatusServer: </strong>$WUStatusServer
<br>
<strong>Serveur Kaspsersky: </strong>$KSC_IP
<br>
<strong>Antivirus Installé: </strong>$KSC_AV
<br><br>
Meilleures salutations.
</span>
</span></p>
"
send-mailmessage -from "$Mail_From" -to "$Mail_To" -cc "$Mail_CC" -subject "MDT Monitoring status: Unresponsive - On $Deployment_ComputerName" -body $Body -BodyAsHtml -priority Normal -Attachments "$AttachToMail001" -smtpServer $Mail_SMTP
break
}
ElseIf ($Deployment_Status -eq 3) # Deployment success
{
$Body = "<p>
<span>Bonjour,<br><br>
Déploiement de Système d'Exploitation <strong><span style=color:green>completed successfully</span></strong> on the computer: <span style=color:blue><strong>$Deployment_ComputerName</strong></span> - $(get-date)
<br><br>
<span style=color:black>
Voir ci-dessous quelques informations sur votre déploiement :
<br><br>
<strong>Lycée: </strong>$NomLycee
<br>
<strong>Computer name: </strong>$Deployment_ComputerName
<br>
<strong>TaskSequenceName: </strong>$TSEnv:TASKSEQUENCENAME
<br>
<strong>Vendor: </strong>$TSEnv:Make
<br>
<strong>Model: </strong>$TSEnv:Model
<br>
<strong>Lenovo Model: </strong>$TSEnv:LenovoModel
<br>
<strong>Memory: </strong>$TSEnv:Memory Megabyte
<br>
<strong>SerialNumber: </strong>$TSEnv:SerialNumber
<br>
<strong>AssetTag: </strong>$TSEnv:AssetTag
<br>
<strong>Start time: </strong>$Deployment_Start_time
<br>
<strong>End time: </strong>$Deployment_End_time
<br>
<strong>Elapsed time: </strong>$Deployment_Ellapsedtime
<br>
<strong>Warning: </strong>$Deployment_Warnings
<br>
<strong>Error: </strong>$Deployment_Errors
<br>
<strong>Groupe WSUS: </strong>$TargetGroup
<br>
<strong>WUServer: </strong>$WUServer
<br>
<strong>WUStatusServer: </strong>$WUStatusServer
<br>
<strong>Serveur Kaspsersky: </strong>$KSC_IP
<br>
<strong>Antivirus Installé: </strong>$KSC_AV
<br><br>
Meilleures salutations.
</span>
</span></p>
"
send-mailmessage -from "$Mail_From" -to "$Mail_To" -cc "$Mail_CC" -subject "MDT Monitoring status: Success - On $Deployment_ComputerName" -body $Body -BodyAsHtml -priority Normal -Attachments "$AttachToMail001" -smtpServer $Mail_SMTP
break
}
ElseIf ($Deployment_Status -eq 2) # Deployment failed
{
$Body = "<p>
<span>Bonjour,<br><br>
Déploiement de Système d'Exploitation <strong><span style=color:red>failed</span></strong> on the computer: <span style=color:blue><strong>$Deployment_ComputerName</strong></span> - $(get-date)
<br><br>
<span style=color:black>
Voir ci-dessous quelques informations sur votre déploiement :
<br><br>
<strong>Lycée: </strong>$NomLycee
<br>
<strong>Computer name: </strong>$Deployment_ComputerName
<br>
<strong>TaskSequenceName: </strong>$TSEnv:TASKSEQUENCENAME
<br>
<strong>Vendor: </strong>$TSEnv:Make
<br>
<strong>Model: </strong>$TSEnv:Model
<br>
<strong>Lenovo Model: </strong>$TSEnv:LenovoModel
<br>
<strong>Memory: </strong>$TSEnv:Memory Megabyte
<br>
<strong>SerialNumber: </strong>$TSEnv:SerialNumber
<br>
<strong>AssetTag: </strong>$TSEnv:AssetTag
<br>
<strong>Start time: </strong>$Deployment_Start_time
<br>
<strong>Last time: </strong>$Deployment_End_time
<br>
<strong>Warning: </strong>$Deployment_Warnings
<br>
<strong>Error: </strong>$Deployment_Errors
<br>
<strong>Step name: </strong>$Deployment_StepName
<br>
<strong>Percent: </strong>$Deployment_Percent_Complete
<br>
<strong>Groupe WSUS: </strong>$TargetGroup
<br>
<strong>WUServer: </strong>$WUServer
<br>
<strong>WUStatusServer: </strong>$WUStatusServer
<br>
<strong>Serveur Kaspsersky: </strong>$KSC_IP
<br>
<strong>Antivirus Installé: </strong>$KSC_AV
<br><br>
Meilleures salutations.
</span>
</span></p>
"
send-mailmessage -from "$Mail_From" -to "$Mail_To" -Cc "$Mail_CC" -subject "MDT Monitoring status: Failed - On $Deployment_ComputerName" -body $Body -BodyAsHtml -priority Normal -Attachments "$AttachToMail001" -smtpServer $Mail_SMTP
break
}
write-host "Deployment finished"