antivirusstate

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentes Révision précédente
Prochaine révision
Révision précédente
antivirusstate [2019/04/08 16:41] – [Script principal] nekanantivirusstate [2021/03/05 16:13] (Version actuelle) nekan
Ligne 1: Ligne 1:
 ====== Get-AntiVirusState - Connaître l'état des antivirus d'un parc ====== ====== Get-AntiVirusState - Connaître l'état des antivirus d'un parc ======
 +<label type="info">Création</label> --- //[[nekan@shyrkasystem.com|Nicolas THOREZ]] 2019/02/19 19:58//
  
 Connaître l'état de protection de l'ensemble des PC dans un domaine est très important pour un administrateur afin de garantir la sécurité d'un parc informatique. Dans le cas où les antivirus sont gérés de manière centralisée par un logiciel tel que Kaspersky Security Center, cela est assez facile. Dans les cas où on n'a pas ce genre d'outil, cela devient légèrement plus compliqué. On pourrait faire régulièrement le tour de chaque poste mais cela coûte énormément en temps et en moyen surtout si la structure est imposante. Partons donc sur le principe que "Un administrateur qui n'a pas recours à des scripts est condamné à refaire sans cesse les mêmes choses". Connaître l'état de protection de l'ensemble des PC dans un domaine est très important pour un administrateur afin de garantir la sécurité d'un parc informatique. Dans le cas où les antivirus sont gérés de manière centralisée par un logiciel tel que Kaspersky Security Center, cela est assez facile. Dans les cas où on n'a pas ce genre d'outil, cela devient légèrement plus compliqué. On pourrait faire régulièrement le tour de chaque poste mais cela coûte énormément en temps et en moyen surtout si la structure est imposante. Partons donc sur le principe que "Un administrateur qui n'a pas recours à des scripts est condamné à refaire sans cesse les mêmes choses".
Ligne 9: Ligne 10:
 ===== Script principal ===== ===== Script principal =====
  
-<code:ps1># Ligne rajoutée pour permettre la coloration syntaxique. A supprimer.+<sxh powershell>
 <# <#
 .SYNOPSIS .SYNOPSIS
 +
 +
 +    ███████╗██╗  ██╗██╗   ██╗██████╗ ██╗  ██╗ █████╗                 
 +    ██╔════╝██║  ██║╚██╗ ██╔╝██╔══██╗██║ ██╔╝██╔══██╗                
 +    ███████╗███████║ ╚████╔╝ ██████╔╝█████╔╝ ███████║                
 +    ╚════██║██╔══██║  ╚██╔╝  ██╔══██╗██╔═██╗ ██╔══██║                
 +    ███████║██║  ██║   ██║   ██║  ██║██║  ██╗██║  ██║                
 +    ╚══════╝╚═╝  ╚═╝   ╚═╝   ╚═╝  ╚═╝╚═╝  ╚═╝╚═╝  ╚═╝                
 +                                                                 
 +                ███████╗██╗   ██╗███████╗████████╗███████╗███╗   ███╗
 +                ██╔════╝╚██╗ ██╔╝██╔════╝╚══██╔══╝██╔════╝████╗ ████║
 +                ███████╗ ╚████╔╝ ███████╗   ██║   █████╗  ██╔████╔██║
 +                ╚════██║  ╚██╔╝  ╚════██║   ██║   ██╔══╝  ██║╚██╔╝██║
 +                ███████║   ██║   ███████║   ██║   ███████╗██║ ╚═╝ ██║
 +                ╚══════╝   ╚═╝   ╚══════╝   ╚═╝   ╚══════╝╚═╝     ╚═╝
 +                                                                 
 +
  
 ############################################################################################################# #############################################################################################################
Ligne 71: Ligne 89:
 NOM :      Get-AntiVirusState.ps1 NOM :      Get-AntiVirusState.ps1
 AUTEUR :   Nicolas THOREZ AUTEUR :   Nicolas THOREZ
-VERSION :  1.2+VERSION :  1.3
  
 HISTORIQUE : HISTORIQUE :
Ligne 88: Ligne 106:
 1.2     2019-03-26      Modification du mode verbeux 1.2     2019-03-26      Modification du mode verbeux
  
 +1.3     2019-04-08      Optimisation du code
  
 #> #>
Ligne 94: Ligne 113:
  
 Param( Param(
-    [String[]]$PC='All',+    [String[]]$PC="All",
     [Switch]$Nagios,     [Switch]$Nagios,
     [Switch]$Verbose     [Switch]$Verbose
Ligne 101: Ligne 120:
 # Déclaration des variables # Déclaration des variables
  
-If ($PC -eq 'All')+If ($PC -eq "All")
     {     {
         $ListPC = (Get-ADComputer -SearchBase "OU=PC Fixe,OU=Ordinateurs,DC=TEST,DC=LOCAL" -Filter *).Name         $ListPC = (Get-ADComputer -SearchBase "OU=PC Fixe,OU=Ordinateurs,DC=TEST,DC=LOCAL" -Filter *).Name
Ligne 126: Ligne 145:
 $PCWithFaultyRT = "n/a" $PCWithFaultyRT = "n/a"
 $PCWithObsoleteBase = "n/a" $PCWithObsoleteBase = "n/a"
-$Domaine = 'TEST' +$Domaine = "TEST" 
-$FQDN = 'test.local'+$FQDN = "test.local"
 $Report = "$Path\Report.dat" $Report = "$Path\Report.dat"
  
Ligne 148: Ligne 167:
         Else         Else
             {             {
-                $CheckTime = Get-Date -Format 'G'+                $CheckTime = Get-Date -Format G
                 If ($Verbose)                 If ($Verbose)
                     {                     {
Ligne 232: Ligne 251:
                 $PCOnline += 1                 $PCOnline += 1
                 #On vérifie le nombre d'antivirus                 #On vérifie le nombre d'antivirus
-                $AntiVirusCount = (Get-WmiObject -Namespace "root\SecurityCenter2" -Class AntiVirusProduct  -ComputerName $PC).Count 
                 $AntiVirusProduct = Get-WmiObject -Namespace "root\SecurityCenter2" -Class AntiVirusProduct  -ComputerName $PC                 $AntiVirusProduct = Get-WmiObject -Namespace "root\SecurityCenter2" -Class AntiVirusProduct  -ComputerName $PC
 +                $AntiVirusCount = $AntiVirusProduct.Count
  
                 If ($AntiVirusCount.Count -gt 2)                 If ($AntiVirusCount.Count -gt 2)
Ligne 253: Ligne 272:
                     {                     {
                         # Filtre pour supprimer Windows Defender qui doit être désactivé et création de la liste d'état de l'antivirus présent                         # Filtre pour supprimer Windows Defender qui doit être désactivé et création de la liste d'état de l'antivirus présent
-                        $AntiVirusProduct = Get-WmiObject -Namespace "root\SecurityCenter2" -Class AntiVirusProduct  -ComputerName $PC | Where-Object {$_.displayname -ne "Windows Defender"}+                        $AntiVirusProduct = Get-WmiObject -Namespace "root\SecurityCenter2" -Class AntiVirusProduct -ComputerName $PC | Where-Object {$_.displayname -ne "Windows Defender"}
                     }                     }
                 If ($AntiVirusProduct -eq '')                 If ($AntiVirusProduct -eq '')
Ligne 279: Ligne 298:
    
                 # Conversion en hexadecimal (avec ajout de 0 si nécessaire pour avoir une chaîne de 6 caractères)                  # Conversion en hexadecimal (avec ajout de 0 si nécessaire pour avoir une chaîne de 6 caractères) 
-                $Hexa = [Convert]::ToString($productState, 16).PadLeft(6,'0'+                $Hexa = [Convert]::ToString($productState, 16).PadLeft(6,"0"
  
                 # Séparation des indicateurs (les 2 premiers caractères puis les 2 suivants et enfin les 2 derniers)                 # Séparation des indicateurs (les 2 premiers caractères puis les 2 suivants et enfin les 2 derniers)
Ligne 287: Ligne 306:
  
                 # Création de la valeur correspondant au type de protection                 # Création de la valeur correspondant au type de protection
-                $Provider = ""+                $Provider = ''
                 While ($WSC_SECURITY_PROVIDER)                 While ($WSC_SECURITY_PROVIDER)
                     {                     {
Ligne 299: Ligne 318:
                             {                             {
                                 [Int]$WSC_SECURITY_PROVIDER = [Int]$WSC_SECURITY_PROVIDER - 32                                 [Int]$WSC_SECURITY_PROVIDER = [Int]$WSC_SECURITY_PROVIDER - 32
-                                If ($Provider -eq "")+                                If ($Provider -eq '')
                                     {                                     {
                                         $Provider += "User Controlled"                                         $Provider += "User Controlled"
Ligne 312: Ligne 331:
                             {                             {
                                 [Int]$WSC_SECURITY_PROVIDER = [Int]$WSC_SECURITY_PROVIDER - 16                                 [Int]$WSC_SECURITY_PROVIDER = [Int]$WSC_SECURITY_PROVIDER - 16
-                                If ($Provider -eq "")+                                If ($Provider -eq '')
                                     {                                     {
                                         $Provider += "Internet Settings"                                         $Provider += "Internet Settings"
Ligne 325: Ligne 344:
                             {                             {
                                 [Int]$WSC_SECURITY_PROVIDER = [Int]$WSC_SECURITY_PROVIDER - 8                                 [Int]$WSC_SECURITY_PROVIDER = [Int]$WSC_SECURITY_PROVIDER - 8
-                                If ($Provider -eq "")+                                If ($Provider -eq '')
                                     {                                     {
                                         $Provider += "AntiSpyware"                                         $Provider += "AntiSpyware"
Ligne 338: Ligne 357:
                             {                             {
                                 [Int]$WSC_SECURITY_PROVIDER = [Int]$WSC_SECURITY_PROVIDER - 4                                 [Int]$WSC_SECURITY_PROVIDER = [Int]$WSC_SECURITY_PROVIDER - 4
-                                If ($Provider -eq "")+                                If ($Provider -eq '')
                                     {                                     {
                                         $Provider += "Antivirus"                                         $Provider += "Antivirus"
Ligne 351: Ligne 370:
                             {                             {
                                 [Int]$WSC_SECURITY_PROVIDER = [Int]$WSC_SECURITY_PROVIDER - 2                                 [Int]$WSC_SECURITY_PROVIDER = [Int]$WSC_SECURITY_PROVIDER - 2
-                                If ($Provider -eq "")+                                If ($Provider -eq '')
                                     {                                     {
                                         $Provider += "AutoUpdate"                                         $Provider += "AutoUpdate"
Ligne 364: Ligne 383:
                             {                             {
                                 [Int]$WSC_SECURITY_PROVIDER = [Int]$WSC_SECURITY_PROVIDER - 1                                 [Int]$WSC_SECURITY_PROVIDER = [Int]$WSC_SECURITY_PROVIDER - 1
-                                If ($Provider -eq "")+                                If ($Provider -eq '')
                                     {                                     {
                                         $Provider += "FireWall"                                         $Provider += "FireWall"
Ligne 375: Ligne 394:
                             }                             }
                     }                     }
-                If ($Provider -eq "")+                If ($Provider -eq '')
                     {                     {
                         $Provider = "None"                         $Provider = "None"
Ligne 572: Ligne 591:
         $ReportData | Export-Csv -Path 'C:\Scripts\AntivirusState\Report.dat' -Delimiter ';'         $ReportData | Export-Csv -Path 'C:\Scripts\AntivirusState\Report.dat' -Delimiter ';'
     }     }
- +</sxh>
- +
-</code>+
  
 ===== Script d'interprétation Nagios ===== ===== Script d'interprétation Nagios =====
  
-<code:ps1>+<sxh powershell>
 ############################################################################################################# #############################################################################################################
 #                                                                                                           # #                                                                                                           #
Ligne 597: Ligne 614:
 [String]$NoAV = $Report.NoAV [String]$NoAV = $Report.NoAV
  
-$Output = "" +$Output = '' 
-$OutputMessage = ""+$OutputMessage = ''
 $ExitCode = 3 $ExitCode = 3
  
Ligne 610: Ligne 627:
     {     {
         $Output = "Critical"         $Output = "Critical"
-        If ($OutputMessage -eq "")+        If ($OutputMessage -eq '')
             {             {
                 $OutputMessage = "PC with too many AV : $TooMany"                 $OutputMessage = "PC with too many AV : $TooMany"
Ligne 623: Ligne 640:
     {     {
         $Output = "Critical"         $Output = "Critical"
-        If ($OutputMessage -eq "")+        If ($OutputMessage -eq '')
             {             {
                 $OutputMessage = "PC without activated RealTime Protection : $RTFail"                 $OutputMessage = "PC without activated RealTime Protection : $RTFail"
Ligne 635: Ligne 652:
 If ($Obsolete -ne "n/a") If ($Obsolete -ne "n/a")
     {     {
-        If ($Output -eq "")+        If ($Output -eq '')
             {             {
                 $Output = "Warning"                 $Output = "Warning"
                 $ExitCode = 1                 $ExitCode = 1
             }             }
-        If ($OutputMessage -eq "")+        If ($OutputMessage -eq '')
             {             {
                 $OutputMessage = "PC with obsolete virus definitions bases : $Obsolete"                 $OutputMessage = "PC with obsolete virus definitions bases : $Obsolete"
Ligne 665: Ligne 682:
         exit $ExitCode         exit $ExitCode
     }     }
-</code> +</sxh>
- +
- --- //[[nekan@shyrkasystem.com|Nicolas THOREZ]] 2019/02/19 19:58//+
  
 ~~DISCUSSION~~ ~~DISCUSSION~~
  
  
  • antivirusstate.1554734503.txt.gz
  • Dernière modification : 2019/04/08 14:41
  • (modification externe)