Question [Concours Scripting] Monitor-network (validé)

Plus d'informations
il y a 18 ans 2 mois #1398 par bordin
[code:1]####
#### Nom du script: monitor-network.ps1
#### Nom de l'auteur: Camille BORDIN
#### Date: 24/12/2007
#### Usage: .\monitor-network.ps1
####
#### Descritpion: Outil de surveillance graphique PS de serveurs et d'équipements informatique.
#### Affiche les serveurs d'un domaine AD, affiche les services et les process pour le serveur sélectionné.
#### En fonction des actions choisies, remonte l'état des services, des processus, des équipements réseau dans un fichier texte et l'espace disque
#### Sauvegarde la liste des services sélectionnés dans .\listeservices.txt
#### Sauvegarde la liste des processus sélectionnés dans .\listeprocess.txt
#### Sauvegarde la liste des serveurs sélectionnés dans .\listeserveurs.txt
#### Génère un fichier pour chaque action (.\check-disque.txt, .\check-reseau.txt, .\check-services.txt, .\check-process.txt)
#### Tous les fichiers sont stockés dans le répertoire courrant du script
#### Version 1.0

#Déclarations des éléments du form Monitor-network
[void][Reflection.Assembly]::LoadWithPartialName(\"System.Windows.Forms\"«»)
$RbtnLocalMode = new-object System.Windows.Forms.RadioButton # Active le mode local (.)
$RbtnServeurMode = new-object System.Windows.Forms.RadioButton # Active le mode serveur (AD)
$cbxListeServices = new-object System.Windows.Forms.CheckedListBox # Affichage des services scannés
$cbxListeProcess = new-object System.Windows.Forms.CheckedListBox # Affichage des process scannés
$dtgListeEQP = new-object System.Windows.Forms.DataGridView # affichage liste @IP équipement réseau
$gbxListeSRV = new-object System.Windows.Forms.GroupBox # groupement Liste serveur
$dtgListeServeurs = new-object System.Windows.Forms.DataGridView # Affichage liste des serveurs
$gbxActSurveillance = new-object System.Windows.Forms.GroupBox # groupement des actions à accomplir
$chbxDisque = new-object System.Windows.Forms.CheckBox # Action Scan espace disque
$chbxServices = new-object System.Windows.Forms.CheckBox # Action Scan services
$chbxReseau = new-object System.Windows.Forms.CheckBox # Action ping équipements réseau
$chbxProcess = new-object System.Windows.Forms.CheckBox # Action Scan process
$gbxActListeSRV = new-object System.Windows.Forms.GroupBox
$btnSaveSRV = new-object System.Windows.Forms.Button #Sauvegarde liste des serveurs
$BtnLoadSRV = new-object System.Windows.Forms.Button # Récupération des serveurs à partir d'AD
$gbxActScan = new-object System.Windows.Forms.GroupBox
$btnSCANPSS = new-object System.Windows.Forms.Button # Lance le scan des process
$btnSCANSRV = new-object System.Windows.Forms.Button # Lance le scan des serveurs
# $gbxGeneral = new-object System.Windows.Forms.GroupBox
$gbxListeServices = new-object System.Windows.Forms.GroupBox
$btnSaveSVC = new-object System.Windows.Forms.Button #Sauvegarde liste des services
$gbxListeProcess = new-object System.Windows.Forms.GroupBox
$btnSavePSS = new-object System.Windows.Forms.Button #Sauvegarde liste des process
$gbxListeEQP = new-object System.Windows.Forms.GroupBox
$tbxAddEQP = new-object System.Windows.Forms.TextBox #Saisie adressIP équipement réseau
$gbxActListeEQP = new-object System.Windows.Forms.GroupBox
$btnSaveEQP = new-object System.Windows.Forms.Button #Sauvegarde liste des adressIP équipement réseau
$btnSuppEQP = new-object System.Windows.Forms.Button #Suppression d'une adressIP de la liste
$btnAddEQP = new-object System.Windows.Forms.Button #Ajout d'une adressIP à la liste
$lblStatus = new-object System.Windows.Forms.Label #Affichage d'informations sur lexécution du script

$btnCHECKIT = new-object System.Windows.Forms.Button # Lance l'exécution des script d'actions

# Fonction récupération du nom du bouton de mode activé (local ou serveur)
function GetNomradioBTNMode {
($gbxActListeSRV.controls | where {$_.checked}).name}
#
# Les actions à exécuter
# Fonction Scan des services
Function CheckServices ([string]$listeservices) {
$SortieCheckServices=\".\Check-Services.txt\"
$array=@{}
get-content $listeservices | foreach {
$server, $array.$server = $_.split(\",\"«») | foreach {$_.trim()}
}
$array.keys | foreach {
$elsrv = $_
$array.$elsrv | foreach {
$elsvc = $_
Get-WmiObject -query (\"select * from win32_service where name = '\"+$elsvc+\"'\"«») -comp $elsrv
}
} |
select @{n=\"Nom_Serveur\";e={$_.__Server}},
@{n=\"Nom_Service\";e={$_.displayname}},
@{n=\"Etat\";e={$_.State}},
@{n=\"Status\";e={$_.status}} | EXPORT-CSV $SortieCheckServices -notype -force
}
#Fonction scan des disques durs
Function CheckDisques([string]$listeserveurs){
$SortieCheckStockage=\".\Check-Stockage.txt\"
get-content $listeserveurs |
foreach {
Get-WmiObject win32_logicaldisk -filter \"DriveType=3\" -computer $_ |
select @{n=\"Nom\";e={$_.__Server}},@{n=\"Volume\";e={$_.DeviceID}},@{n=\"Total\";e={[math]::round($_.Size/1MB )}}, @{n=\"Libre\";e={[math]::round($_.FreeSpace/1MB )
}}} | export-csv $SortieCheckStockage -notype -force
}
#
#Fonction Ping des equipement reseau
Function CheckReseau([string]$listeEquipement){
$SortieCheckEquipement=\".\Check-Equipement.txt\"
get-content $listeEquipement |
foreach-object {
get-wmiobject -Class Win32_PingStatus -filter (\"Address='\" + $_ + \"'\"«»)
} | select @{n=\"AddresseIP\";e={$_.ProtocolAddress}},@{n=\"Status\"; expression={
switch ($_.statuscode) {
0 {\"Succes!\"; break}
11001 {\"Buffer Too Small!\"; break}
11002 {\"Destination Net Unreachable!\"; break}
11003 {\"Destination Host Unreachable!\"; break}
11004 {\"Destination Protocol Unreachable!\"; break}
11005 {\"Destination Port Unreachable!\"; break}
11006 {\"No Resources!\"; break}
11007 {\"Bad Option!\"; break}
11008 {\"Hardware Error!\"; break}
11009 {\"Packet Too Big!\"; break}
11010 {\"Request Timed Out!\"; break}
11011 {\"Bad Request!\"; break}
11012 {\"Bad Route!\"; break}
11013 {\"TimeToLive Expired Transits!\"; break}
11014 {\"TimeToLive Expired Reassembly!\"; break}
11015 {\"Parameter Problem!\"; break}
11016 {\"Source Quench!\"; break}
11017 {\"Option Too Big!\"; break}
11018 {\"Bad Destination!\"; break}
11032 {\"Negotiating IPSEC!\"; break}
11050 {\"General Failure!\"; break}
\"\" {\"Erreur!\"; break}}}} | export-csv $SortieCheckEquipement -notype -force


}
# Fonction Scan des process
Function CheckProcess ([string]$listeprocess) {
$SortieCheckProcess=\".\Check-Process.txt\"
$array=@{}
get-content $listeprocess | foreach {
$server, $array.$server = $_.split(\",\"«») | foreach {$_.trim()}
}
$array.keys | foreach {
$elsrv = $_
$array.$elsrv | foreach {
$elpss = $_
Get-WmiObject -query (\"select * from win32_process where name = '\"+$elpss+\"'\"«») -comp $elsrv
}
} |
select @{n=\"Nom_Serveur\";e={$_.__Server}},
@{n=\"Nom_Process\";e={$_.Processname}},
@{n=\"Etat\";e={$_.Status}} | EXPORT-CSV $SortieCheckProcess -notype -force
}
# On ajoute le datagrid liste serveurs
$gbxListeSRV.Controls.Add($dtgListeServeurs)
$gbxListeSRV.Location = new-object System.Drawing.Point(12, 14)
$gbxListeSRV.Name = \"gbxListeSRV\"
$gbxListeSRV.Size = new-object System.Drawing.Size(286, 250)
$gbxListeSRV.TabIndex = 26
$gbxListeSRV.Autosize=$true
$gbxListeSRV.TabStop = $false
$gbxListeSRV.Text = \"LISTE SERVEURS\"
#
# On ajoute le texte box ajout equipement et le datagrid Liste equipement
$gbxListeEQP.Controls.Add($tbxAddEQP)
$gbxListeEQP.Controls.Add($dtgListeEQP)
$gbxListeEQP.Location = new-object System.Drawing.Point(12, 280)
$gbxListeEQP.Name = \"gbxListeEQP\"
$gbxListeEQP.Size = new-object System.Drawing.Size(286, 194)
$gbxListeEQP.AutoSize =$true
$gbxListeEQP.TabIndex = 34
$gbxListeEQP.TabStop = $false
$gbxListeEQP.Text = \"LISTE EQUIPEMENTS\"
#
# gbxActListeSRV
# On jaoute les boutons radio mode serveur, mode local, chargement des serveurs, sauvegarde liste serveurs
$gbxActListeSRV.Controls.Add($RbtnServeurMode)
$gbxActListeSRV.Controls.Add($RbtnLocalMode)
$gbxActListeSRV.Controls.Add($BtnLoadSRV)
$gbxActListeSRV.Controls.Add($BtnSaveSRV)
$gbxActListeSRV.Location = new-object System.Drawing.Point(316, 14)
$gbxActListeSRV.Name = \"gbxActListeSRV\"
$gbxActListeSRV.Size = new-object System.Drawing.Size(158, 90)
$gbxActListeSRV.TabIndex = 29
$gbxActListeSRV.TabStop = $false
$gbxActListeSRV.Text = \"ACTIONS SERVEURS\"
#
# gbxActSurveillance
# on ajoute les ckeckbox actions ckeckdisques, ckeckréseau, checkservices, checkprocess
$gbxActSurveillance.Controls.Add($chbxDisque)
$gbxActSurveillance.Controls.Add($chbxServices)
$gbxActSurveillance.Controls.Add($chbxReseau)
$gbxActSurveillance.Controls.Add($chbxProcess)
$gbxActSurveillance.Location = new-object System.Drawing.Point(316, 180)
$gbxActSurveillance.Name = \"gbxActSurveillance\"
$gbxActSurveillance.Size = new-object System.Drawing.Size(158, 110)
$gbxActSurveillance.AutoSize =$true
$gbxActSurveillance.TabIndex = 27
$gbxActSurveillance.TabStop = $false
$gbxActSurveillance.Text = \"ACTIONS MONITORS\"
#
#
# gbxActScan
# on ajoute les boutons de scan service et process
$gbxActScan.Controls.Add($btnSCANPSS)
$gbxActScan.Controls.Add($btnSCANSRV)
$gbxActScan.Location = new-object System.Drawing.Point(304, 119)
$gbxActScan.Name = \"gbxActScan\"
$gbxActScan.Size = new-object System.Drawing.Size(179, 55)
$gbxActScan.TabIndex = 30
$gbxActScan.TabStop = $false
$gbxActScan.Text = \"ACTIONS SCAN\"
#
# gbxListeServices
# on ajoute le bouton de sauvegarde liste des services et le combo liste des services
$gbxListeServices.Controls.Add($btnSaveSVC)
$gbxListeServices.Controls.Add($cbxListeServices)
$gbxListeServices.Location = new-object System.Drawing.Point(489, 14)
$gbxListeServices.Name = \"gbxListeServices\"
$gbxListeServices.Size = new-object System.Drawing.Size(497, 286)
$gbxListeServices.Autosize=$true
$gbxListeServices.TabIndex = 32
$gbxListeServices.TabStop = $false
$gbxListeServices.Text = \"LISTE DES SERVICES A SURVEILLER\"
#
# gbxActListeEQP
# on ajoute le bouton d'ajout d'un équipement, suppression, et sauvegarde liste équipement
$gbxActListeEQP.Controls.Add($btnSaveEQP)
$gbxActListeEQP.Controls.Add($btnSuppEQP)
$gbxActListeEQP.Controls.Add($btnAddEQP)
$gbxActListeEQP.Location = new-object System.Drawing.Point(316, 315)
$gbxActListeEQP.Name = \"gbxActListeEQP\"
$gbxActListeEQP.Size = new-object System.Drawing.Size(158, 112)
$gbxActListeEQP.TabIndex = 30
$gbxActListeEQP.TabStop = $false
$gbxActListeEQP.Text = \"ACTIONS EQUIPEMENTS\"
#
#
# gbxListeProcess
# on ajoute le bouton de sauvegarde liste des process et le combo liste des process
$gbxListeProcess.Controls.Add($btnSavePSS)
$gbxListeProcess.Controls.Add($cbxListeProcess)
$gbxListeProcess.Location = new-object System.Drawing.Point(489, 305)
$gbxListeProcess.Name = \"gbxListeProcess\"
$gbxListeProcess.Size = new-object System.Drawing.Size(497, 286)
$gbxListeProcess.AutoSize =$true
$gbxListeProcess.TabIndex = 33
$gbxListeProcess.TabStop = $false
$gbxListeProcess.Text = \"LISTE DES PROCESS A SURVEILLER\"
#
#
#dtgListeServeurs
#
$dtgListeServeurs.ColumnHeadersHeightSizeMode = \"AutoSize\"
$dtgListeServeurs.ScrollBars=\"Vertical\"
$dtgListeServeurs.Multiselect=$false
$dtgListeServeurs.SelectionMode=\"FullRowSelect\"
$dtgListeServeurs.EditMode=\"EditProgrammatically\"
$dtgListeServeurs.AutosizeColumnsMode=\"Fill\"
$dtgListeServeurs.Location = new-object System.Drawing.Point(6, 19)
$dtgListeServeurs.Name = \"dtgListeServeurs\"
$dtgListeServeurs.Size = new-object System.Drawing.Size(250, 200)
$dtgListeServeurs.TabIndex = 31
# on réupère le nom du serveur sélectionné dans la liste des serveurs
$dtgListeServeurs.add_CellContentClick({
$ligne=$dtgListeServeurs.selectedRows[0]
$champs = $ligne.Cells[0]
$nomSRV = $champs.Value.ToString()})
#write-host $nomSRV})
#
# cbxListeServices
# Paramètrage des propriétés de la liste des services
$cbxListeServices.FormattingEnabled = $true
$cbxListeServices.Location = new-object System.Drawing.Point(8, 19)
#$cbxListeServices.Multiline = $true
$cbxListeServices.Name = \"tbxListeServices\"
#$cbxListeServices.ScrollBars = \"Vertical\"
$cbxListeServices.Size = new-object System.Drawing.Size(417, 249)
$cbxListeServices.TabIndex = 12
#
# cbxListeProcess
# Paramètrage des propriétés de la liste des process
$cbxListeProcess.FormattingEnabled = $true
$cbxListeProcess.Location = new-object System.Drawing.Point(6, 19)
#$cbxListeProcess.Multiline = $true
$cbxListeProcess.Name = \"tbxListeProcess\"
#$cbxListeProcess.ScrollBars = \"Vertical\"
$cbxListeProcess.Size = new-object System.Drawing.Size(417, 249)
$cbxListeProcess.TabIndex = 15
#
# dtgListeEQP
# Paramètrage des propriétés de la liste des équipements
$dtgListeEQP.ColumnHeadersHeightSizeMode = \"AutoSize\"
$dtgListeEQP.ScrollBars=\"Vertical\"
$dtgListeEQP.Multiselect=$false
$dtgListeEQP.SelectionMode=\"FullRowSelect\"
$dtgListeEQP.EditMode=\"EditProgrammatically\"
$dtgListeEQP.AutosizeColumnsMode=\"Fill\"
$dtgListeEQP.Location = new-object System.Drawing.Point(6, 54)
$dtgListeEQP.Name = \"dtgListeEQP\"
$dtgListeEQP.Size = new-object System.Drawing.Size(250, 130)
$dtgListeEQP.TabIndex = 17
$dtgListeEQP.columncount=1
$dtgListeEQP.Columns[0].Name = \"Adresse IP\"
#
#
#
# tbxAddEQP
# Paramètrage des propriétés du bouton ajout d'un équipement
$tbxAddEQP.Location = new-object System.Drawing.Point(6, 28)
$tbxAddEQP.Name = \"tbxAddEQP\"
$tbxAddEQP.Size = new-object System.Drawing.Size(166, 20)
$tbxAddEQP.TabIndex = 31
$tbxAddEQP.MaxLength= 15
#
#
# chbxDisque
# Paramètrage des propriétés de l'action check disque
$chbxDisque.AutoSize = $true
$chbxDisque.Location = new-object System.Drawing.Point(9, 91)
$chbxDisque.Name = \"chbxDisque\"
$chbxDisque.Size = new-object System.Drawing.Size(91, 17)
$chbxDisque.TabIndex = 32
$chbxDisque.Text = \"Check disque\"
$chbxDisque.UseVisualStyleBackColor = $true
#
# chbxServices
# Paramètrage des propriétés de l'action check services
$chbxServices.AutoSize = $true
$chbxServices.Location = new-object System.Drawing.Point(9, 22)
$chbxServices.Name = \"chbxServices\"
$chbxServices.Size = new-object System.Drawing.Size(99, 17)
$chbxServices.TabIndex = 29
$chbxServices.Text = \"Check services\"
$chbxServices.UseVisualStyleBackColor = $true
#
# chbxReseau
# Paramètrage des propriétés de l'action check réseau
$chbxReseau.AutoSize = $true
$chbxReseau.Location = new-object System.Drawing.Point(9, 68)
$chbxReseau.Name = \"chbxReseau\"
$chbxReseau.Size = new-object System.Drawing.Size(92, 17)
$chbxReseau.TabIndex = 31
$chbxReseau.Text = \"Check reseau\"
$chbxReseau.UseVisualStyleBackColor = $true
#
# chbxProcess
# Paramètrage des propriétés de l'action check process
$chbxProcess.AutoSize = $true
$chbxProcess.Location = new-object System.Drawing.Point(9, 45)
$chbxProcess.Name = \"chbxProcess\"
$chbxProcess.Size = new-object System.Drawing.Size(97, 17)
$chbxProcess.TabIndex = 30
$chbxProcess.Text = \"Check process\"
$chbxProcess.UseVisualStyleBackColor = $true
#
#RbtnLocalMode
#Active le mode local.
Function FichierExist ([string] $path) # teste si un fichier ou un dossier existe
{
if ( Test-Path $path){ return $true}
else {Return $false}
}
#
$RbtnLocalMode.AutoSize = $true
$RbtnLocalMode.Location = new-object System.Drawing.Point(6, 19)
$RbtnLocalMode.Name = \"rbtnLocalMode\"
$RbtnLocalMode.Size = new-object System.Drawing.Size(46, 17)
$RbtnLocalMode.TabIndex = 22
$RbtnLocalMode.TabStop = $true
$RbtnLocalMode.Text = \"Mode Local\"
$RbtnLocalMode.add_click({
$BtnLoadSRV.Enabled=$False
$BtnSaveSRV.Enabled=$False
$DtgListeServeurs.Datasource= $nothing
$cbxListeServices.datasource=$nothing
$cbxListeProcess.datasource=$nothing
# On test si la liste des services existe et on informe que le mode local est actif
if (test-path .\listeServices.txt) {
new-item -path . -name ListeServices.txt -type file -force }
if (test-path .\listeProcess.txt) {
new-item -path . -name ListeProcess.txt -type file -force}
$lblStatus.text=\"Mode Local actif: Serveur = LocalHost'\"
})
#
#
#RbtnServeurMode
#Active le mode serveur (Active directory)
#
$RbtnServeurMode.AutoSize = $true
$RbtnServeurMode.Location = new-object System.Drawing.Point(6, 36)
$RbtnServeurMode.Name = \"rbtnServeurMode\"
$RbtnServeurMode.Size = new-object System.Drawing.Size(46, 17)
$RbtnServeurMode.TabIndex = 22
$RbtnServeurMode.TabStop = $true
$RbtnServeurMode.Text = \"Mode Serveur\"
$RbtnServeurMode.add_click({
$BtnLoadSRV.Enabled=$True
$BtnSaveSRV.Enabled=$True
$cbxListeServices.datasource=$nothing
$cbxListeProcess.datasource=$nothing
if (test-path .\listeServices.txt) {
new-item -path . -name ListeServices.txt -type file -force }
if (test-path .\listeProcess.txt) {
new-item -path . -name ListeProcess.txt -type file -force}
$lblStatus.text=\"Mode Serveur actif: Recuperation SRV AD\"
})
#
# btnSaveSRV
# Sauvegarde la liste des serveurs dans un fichier texte
$btnSaveSRV.Location = new-object System.Drawing.Point(6, 61)
$btnSaveSRV.Name = \"btnSaveSRV\"
$btnSaveSRV.Size = new-object System.Drawing.Size(146, 23)
$btnSaveSRV.TabIndex = 12
$btnSaveSRV.Text = \"Sauver liste SRV\"
$btnSaveSRV.UseVisualStyleBackColor = $true
$BtnSaveSRV.Enabled=$False
$SaveSRVclick={
$nbLignes=$dtgListeServeurs.Rows.count
if ($nblignes -eq 0){$lblstatus.text='\"Aucun serveur a scanner !\"'}
else {
new-item -path . -name ListeServeurs.txt -type file -force
for ($j=0;$j -le $nblignes-1;$j++){
$ligneTemp= ($dtglisteServeurs.Item(0, $J).Value)
out-file -filepath .\listeServeurs.txt -Append -InputObject $LigneTemp
}
}
}
$btnSaveSRV.add_click($saveSRVclick)
#
# BtnLoadSRV
# Se connecte à Active directory et récupère les serveurs windows 2000 et 2003
$GetSRVFromAD=
{
$ModeAppli=GetNomRadioBTNMode
switch ($ModeAppli) {
\"RbtnServeurMode\" {
$root=new-object system.directoryservices.directoryEntry(\"LDAP://rootDSE\"«»)
$domain=[ADSI](\"LDAP://\"+$root.get(\"defaultNamingContext\"«»))
if ($domain -eq $null)
{$lblStatus.text= \"Active Directory injoignable!\"}
else
{
$lblStatus.text=\"Chargement des serveurs a partir d'Active Directory\"
$search=new-object system.Directoryservices.DirectorySearcher($domain)
$search.filter='(&(objectCategory=computer)(OperatingSystem=*server*))'
$result=$search.findAll()
$array=new-object system.Collections.arrayList
$data=@($result | select @{n=\"Serveur\";e={$_.properties.cn}},@{n=\"Type OS\";e={$_.properties.operatingsystem}} | write-output)
$array.AddRange($data)
$DtgListeServeurs.Datasource= $array
$DtgListeServeurs.dock = [system.windows.forms.dockStyle]::Fill
}
}
}
}
$BtnLoadSRV.Location = new-object System.Drawing.Point(103, 31)
$BtnLoadSRV.Name = \"BtnLoadSRV\"
$BtnLoadSRV.Size = new-object System.Drawing.Size(45, 23)
$BtnLoadSRV.TabIndex = 11
$BtnLoadSRV.Text = \"Load\"
$BtnLoadSRV.UseVisualStyleBackColor = $true
$BtnLoadSRV.Enabled=$False
$BtnLoadSRV.add_click($GetSRVFromAD)
#
#
#
# btnSCANPSS
# Permet de Scanner les process du serveur sélectionné. Affiche le résultat dans une Combobox Liste process
$btnSCANPSS.Location = new-object System.Drawing.Point(83, 19)
$btnSCANPSS.Name = \"btnSCANPSS\"
$btnSCANPSS.Size = new-object System.Drawing.Size(75, 23)
$btnSCANPSS.TabIndex = 11
$btnSCANPSS.Text = \"Scan-PSS\"
$btnSCANPSS.UseVisualStyleBackColor = $true
$btnSCANPSS.add_click(
{$cbxListeprocess.datasource=$Nothing
$LesProcess=gwmi win32_process -computer $nomSRV
$data=@($LesProcess | foreach {$_.name} )
$array= new-object System.Collections.ArrayList
$array.AddRange($data)
$cbxListeprocess.datasource=$array
}
)
#
Function global:CheckServices {$args[0]}
Function global:CheckReseau {$args[0]}
Function global:Checkdisques {$args[0]}
Function global:CheckProcess {$args[0]}
# Function global:GenRapport {$args[0]}

# Fonction de récupération du nom du bouton activé
function GetNomradioBTN {
($gbxOptRapport.controls | where {$_.checked}).name}
# Fonction de récupération du nom du checkbox activé
function GetcheckboxName {
$gbxActSurveillance.Controls | where {$_.Checked} | foreach {$_.name}
}
#
# btnSCANSVC
# Permet de Scanner les services du serveur sélectionné. Affiche le résultat dans une Combobox Liste services
$btnSCANSRV.Location = new-object System.Drawing.Point(6, 19)
$btnSCANSRV.Name = \"btnSCANSRV\"
$btnSCANSRV.Size = new-object System.Drawing.Size(75, 23)
$btnSCANSRV.TabIndex = 9
$btnSCANSRV.Text = \"Scan-SVC\"
$btnSCANSRV.UseVisualStyleBackColor = $true
$btnSCANSRV.add_click(
{

$ModeAppli=GetNomRadioBTNMode
$cbxListeServices.datasource=$nothing # on efface la liste à chaque changement de mode
if ($Modeappli -eq \"RbtnLocalMode\"«») {$NomSRV=\"localhost\"}
$Lesservices=gwmi win32_service -computer $nomSRV
$data=@($Lesservices | foreach {$_.name})
$array= new-object System.Collections.ArrayList
$array.AddRange($data)
$cbxListeServices.datasource=$array
}
)
#
#
#
# btnSaveSVC
# Sauvegarde la liste des services dans un fichier texte
$btnSaveSVC.Location = new-object System.Drawing.Point(431, 137)
$btnSaveSVC.Name = \"btnSaveSVC\"
$btnSaveSVC.Size = new-object System.Drawing.Size(48, 23)
$btnSaveSVC.TabIndex = 38
$btnSaveSVC.Text = \"Save\"
$btnSaveSVC.UseVisualStyleBackColor = $true
$saveSVCclick={}
$btnsavesvc.add_click({
$CheckedServices=$cbxlisteservices.checkeditems
if ($CheckedServices.count -gt 0) {
#new-item -path . -name ListeServices.txt -type file -force
$temp=[string]::join(\",\",$checkedServices)
$chaine=$NomSRV+\",\"+$temp
out-file -filepath .\listeServices.txt -append -inputobject $chaine}})

#
#
# btnSavePSS
# Sauvegarde la liste des process dans un fichier texte
$btnSavePSS.Location = new-object System.Drawing.Point(431, 126)
$btnSavePSS.Name = \"btnSavePSS\"
$btnSavePSS.Size = new-object System.Drawing.Size(48, 23)
$btnSavePSS.TabIndex = 39
$btnSavePSS.Text = \"Save\"
$btnSavePSS.UseVisualStyleBackColor = $true
$btnsavePSS.add_click({
$CheckedProcess=$cbxlisteProcess.checkeditems
if ($CheckedProcess.count -gt 0) {
$temp=[string]::join(\",\",$checkedProcess)
$chaine=$NomSRV+\",\"+$temp
out-file -filepath .\listeProcess.txt -append -inputobject $chaine}})
#
#
#
# btnSaveEQP
# Sauvegarde la liste des équipements dans un fichier texte
$btnSaveEQP.Location = new-object System.Drawing.Point(6, 69)
$btnSaveEQP.Name = \"btnSaveEQP\"
$btnSaveEQP.Size = new-object System.Drawing.Size(146, 23)
$btnSaveEQP.TabIndex = 11
$btnSaveEQP.Text = \"Sauver liste EQP\"
$btnSaveEQP.UseVisualStyleBackColor = $true
$btnSaveEQP.add_click({
$nbLignes=$dtgListeEQP.Rows.count
if ($nblignes -eq 1){$lblstatus.text=\"Aucune adresse a sauvegarde!\"}
else {
new-item -path . -name ListeEquipement.txt -type file -force
for ($j=0;$j -le $nblignes-2;$j++){
$ligne= ($dtglisteEQP.Item(0, $J).Value)
out-file -filepath .\listeEquipement.txt -Append -InputObject $Ligne
}
}
})
#
# btnSuppEQP
# Bouton de suppression d'un équipement de la liste
$btnSuppEQP.Location = new-object System.Drawing.Point(103, 38)
$btnSuppEQP.Name = \"btnSuppEQP\"
$btnSuppEQP.Size = new-object System.Drawing.Size(44, 23)
$btnSuppEQP.TabIndex = 10
$btnSuppEQP.Text = \"Supp\"
$btnSuppEQP.UseVisualStyleBackColor = $true
#
# btnAddEQP
# bouton d'ajout d'un équipement dans la liste
$btnAddEQP.Location = new-object System.Drawing.Point(15, 38)
$btnAddEQP.Name = \"btnAddEQP\"
$btnAddEQP.Size = new-object System.Drawing.Size(44, 23)
$btnAddEQP.TabIndex = 9
$btnAddEQP.Text = \"Add\"
$btnAddEQP.UseVisualStyleBackColor = $true
$btnAddEQP.add_click({

if ($tbxAddEQP.text -eq \"\"«») {$LblStatus.text=\"Saisir une adresse IP correcte!\"}
else {$dtgListeEQP.Rows.add($tbxAddEQP.text)}
})
#
## lblStatus
# Affichage des informations
$lblStatus.AutoSize = $true
$lblStatus.Location = new-object System.Drawing.Point(9, 560)
$lblStatus.Name = \"lblStatus\"
$lblStatus.Size = new-object System.Drawing.Size(37, 13)
$lblStatus.TabIndex = 38
$lblStatus.Text = \"Status\"
$lblstatus.foreColor=\"Red\"
#
# btnCHECKIT
# bouton de Lancement des actions activés
$btnCHECKIT.Location = new-object System.Drawing.Point(322, 520)
$btnCHECKIT.Name = \"btnCHECKIT\"
$btnCHECKIT.Size = new-object System.Drawing.Size(146, 23)
$btnCHECKIT.TabIndex = 10
$btnCHECKIT.Backcolor=\"Blue\"
$btnCHECKIT.Text = \"Check-IT\"
$btnCHECKIT.UseVisualStyleBackColor = $true
$btnCheckIT.add_click({$TypeRapport=GetnomRadioBtn
$ActionsMonitors=GetcheckboxName
if ($ActionsMonitors -eq $null) {write-host \"Aucunes actions activés !!\"}
else {
Foreach ($action in $ActionsMonitors)
{switch ($action){
\"chbxServices\" {CheckServices .\listeservices.txt;break}
\"ChbxReseau\" {Checkreseau .\listeEquipement.txt;break}
\"chbxDisque\" {CheckDisques .\listeServeurs.txt;break}
\"chbxProcess\" {CheckProcess .\listeProcess.txt;break}
}
}
}})
#
$CBMON = new-object System.Windows.Forms.form
#
# Initialisation des propriétés du form
$CBMON.ClientSize = new-object System.Drawing.Size(999, 600)
$CBMON.Controls.Add($lblStatus)
$CBMON.Controls.Add($gbxActListeEQP)
$CBMON.Controls.Add($gbxListeEQP)
$CBMON.Controls.Add($gbxListeSRV)
$CBMON.Controls.Add($gbxListeProcess)
$CBMON.Controls.Add($gbxListeServices)
$CBMON.Controls.Add($gbxGeneral)
$CBMON.Controls.Add($gbxActScan)
$CBMON.Controls.Add($gbxActListeSRV)
$CBMON.Controls.Add($gbxActSurveillance)
$CBMON.Controls.Add($btnCHECKIT)
$CBMON.Cursor = \"Hand\"
$CBMON.Name = \"CBMON\"
$CBMON.Text = \"Monitor-network v1.0\"
$CBMON.ShowDialog()[/code:1]<br><br>Message édité par: robin, à: 4/01/08 13:16

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 18 ans 2 mois #1404 par Robin Lemesle
Beau travail camille :)

Nous avons beaucoup apprécié. on notera tout de même qu'une petite gestion des erreurs (comme par exemple quand un serveur est éteint) éviterait de faire planter le script. Mais ce script vaut bien 3 points.

PS : As-tu utilisé notre convertisseur de formulaire pour éditer l'interface graphique ?<br><br>Message édité par: robin, à: 4/01/08 13:15

Robin MVP PowerShell

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 18 ans 2 mois #1410 par bordin
Salut,
Merci. Je me suis décidé au dernier moment en postant ce script. :lol:
Il manque pas mal de chose! Alors j'espère pouvoir le faire évoluer (gestion d'erreurs, etc..).

J'ai utilisé au début votre script de génération de formulaire. Mais comme je remaniais l'interface assez souvent je placais les controles à la mano!!!

En tout cas j'ai beaucoup appris à vos coté!! (pas fini)

A+

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 18 ans 2 mois #1413 par Arnaud Petitjean
Bonjour Camille,

En tout cas j'ai beaucoup appris à vos coté!! (pas fini)


Tant mieux, c'est le but de notre site ;)

D'autre part, nous aussi, par le biais du forum et des différentes questions posées en apprenons tous les jours ! :side:

@++

Arnaud

MVP PowerShell et créateur de ce magnifique forum :-)
Auteur de 6 livres PowerShell aux éditions ENI
Fondateur de la société Start-Scripting
Besoin d'une formation PowerShell ?

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 18 ans 2 mois #1441 par Lemaire Patrice
Bonjour Camille,

Je me suis demandé longtemps pourquoi chez moi ça plantait quand je cliquais sur le Scan des Services. De plus le mode « Windows » n’aide pas vraiment au débogage puisqu’il (Mais peut-être est ce mon outils qui n’est pas bon) ne permet pas d’exécuter le code pas à pas quand la fenêtre est ouverte. Si vous avez un outil qui le fait sans problème je suis preneur ^^.
J’ai donc ramé un moment avant de trouver le problème et des propositions de solutions.

Genre de truc qui n’arrive qu’à moi ^^ :

Je lance ton Script.
Je choisi le mode Serveur.
Je clic sur « Load »
Je clic dans la liste pour sélectionner un serveur.
Je clic sur « Scan Services » et là c’est le drame.

La raison est simple, dans ton DataGridView il y à une colonne d’entête de ligne.
Et moi forcement ben … c’est là que je clic (Oui je sais je suis tordu mais bon …)
Résultat le nom du serveur n’est pas récupéré, et le bouton Scan Plante.

Pourrais-tu, pour éviter cela à la source, soit déclaré que les entêtes de lignes ne sont pas visibles :
[code:1]$dtgListeServeurs.RowHeadersVisible=$false[/code:1]
Ainsi plus question de cliquer à un endroit imprévu.

Soit dupliquer le code (pas beau) pour gérer le clic sur l’entête de ligne :
[code:1] $dtgListeServeurs.add_RowHeaderMouseClick({
$ligne=$dtgListeServeurs.selectedRows[0]
$champs = $ligne.Cells[0]
$nomSRV = $champs.Value.ToString()})
write-host $nomSRV})[/code:1]
Ainsi, même sur l’entête de ligne, le clic récupère le nom du serveur.

Dernière chose, quand on clic sur « Check It » ne serait-t-il pas possible plutôt, d’afficher le résultat dans un champ texte dans le formulaire, et ainsi l’avoir le résultat tout de suite sous les yeux ? Après tout, ce script ce veux visuel ^^.

Bon j’ais fini de critiquer ^^ désolé.
En espérant quand même que l’idée te plaise ^^.

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 18 ans 2 mois #1496 par bordin
Salut,
Merci pour tes remarques Spirit. Je suis preneur!
J'ai plein de nouvelles idées pour la v2.
Je ferai mieux la prochaine fois!

A+

Connexion ou Créer un compte pour participer à la conversation.

Temps de génération de la page : 0.133 secondes
Propulsé par Kunena