Update supervision_v4.0.ps1
This commit is contained in:
@@ -5,21 +5,47 @@ Interface de supervision des machines virtuelles du service support
|
|||||||
Auteur : Maxime Tertrais
|
Auteur : Maxime Tertrais
|
||||||
Date creation : 27/11/2023
|
Date creation : 27/11/2023
|
||||||
/Dernier modificateur : Maxime Tertrais
|
/Dernier modificateur : Maxime Tertrais
|
||||||
Date derniere modification :
|
Date derniere modification :04/12/2023
|
||||||
Ce script permet de superviser les machines virtuelles du service support:
|
Ce script permet de superviser les machines virtuelles du service support:
|
||||||
- gestion des machines:
|
- gestion des machines:
|
||||||
- démarrer, arréter les machines
|
- démarrer, arréter, rebooter les machines
|
||||||
- renommer les machines (attention le renommage ne concerne que le nom dans l'hyper-V, l'ID du serveur au niveau du domaine ne change pas)
|
- renommer les machines (attention le renommage ne concerne que le nom dans l'hyper-V, l'ID du serveur au niveau du domaine ne change pas)
|
||||||
-
|
- Ajouter une machine à la liste des machine à tester
|
||||||
legende :
|
- Supprimer une machine de l'hyper-V et de la liste des machines à tester
|
||||||
|
- Gestion des snapshots des machines
|
||||||
|
- listing, création, renommage, suppression des snapshots
|
||||||
|
- restauration de snapshots
|
||||||
|
- Reboot du service jetty (operis) de la machine sélectionnée
|
||||||
|
Pré-requis :
|
||||||
|
- Droit d'accès:
|
||||||
|
- l'utilisateur doit faire partis du groupe de sécurité GSG-Administrateur_hyper-V (=> voir avec le service infra pour ajouter un utilisateur au groupe)
|
||||||
|
- rendre disponible l'optional feature de windows Hyper-V:
|
||||||
|
- dans la recherche windows : fonctionnalitées facultatives
|
||||||
|
- cliquer sur "plus de fonctionnalités windows" (en bas de la liste)
|
||||||
|
- se loguer en admin local (au minimum)
|
||||||
|
- chercher dans le pop-up le module hyper-v pour powershell
|
||||||
|
- Hyper-V
|
||||||
|
- Outils d'administration Hyper-V
|
||||||
|
- Module Hyper-V pour Windows Powershell
|
||||||
|
- cocher la case correspondante et valider sur ok, un redémarrage est peut-être nécessaire
|
||||||
|
|
||||||
|
Legende :
|
||||||
# : ligne de commentaire
|
# : ligne de commentaire
|
||||||
### : ligne de debug (les logs)
|
### : ligne de debug (les logs)
|
||||||
|
|
||||||
.EXAMPLE
|
|
||||||
exemple1 : .\supervision
|
|
||||||
.NOTES
|
.NOTES
|
||||||
|
Fonctionnement du script en mode fenètré.
|
||||||
|
|
||||||
Des améliorations pourraient etre apportées :
|
Des améliorations pourraient etre apportées :
|
||||||
-
|
- Gestion de l'installation du module PowerShell Hyper-V par GPO.
|
||||||
|
- Arrêt du défilement des résultats de tests.
|
||||||
|
|
||||||
|
Les datagrid ne permettent de sélectionner qu'une seule ligne à la fois, donc on ne peut effectuer des actions que sur un objet à la fois.
|
||||||
|
Ceci-dit, toutes les actions suite à clics commencent par un "foreach" pour permettre de réaliser les actions sur plusieurs ligne des datagrids si on souhaite autoriser cette manipulation.
|
||||||
|
Attention, un ajustement des requètes / affichage sera peut-être nécessaire.
|
||||||
|
|
||||||
|
.EXAMPLE
|
||||||
|
N.A
|
||||||
#>
|
#>
|
||||||
|
|
||||||
################################################################################################################################################
|
################################################################################################################################################
|
||||||
@@ -54,37 +80,23 @@ try {
|
|||||||
$assemblyLoaded = $loadedAssemblies.FullName -contains $assembly
|
$assemblyLoaded = $loadedAssemblies.FullName -contains $assembly
|
||||||
if ($null -ne $assemblyLoaded) {
|
if ($null -ne $assemblyLoaded) {
|
||||||
$logassembly = "L'assembly '$assembly' est chargé correctement."
|
$logassembly = "L'assembly '$assembly' est chargé correctement."
|
||||||
WriteToLogFile0 $logassembly
|
###WriteToLogFile0 $logassembly
|
||||||
} else {
|
} else {
|
||||||
$logassembly = "L'assembly '$assembly' n'est pas chargé correctement."
|
$logassembly = "L'assembly '$assembly' n'est pas chargé correctement."
|
||||||
WriteToLogFile0 $logassembly
|
###WriteToLogFile0 $logassembly
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$loaded_assembly_list = [System.AppDomain]::CurrentDomain.GetAssemblies()| Select-Object -Property FullName
|
$loaded_assembly_list = [System.AppDomain]::CurrentDomain.GetAssemblies()| Select-Object -Property FullName
|
||||||
foreach ($loaded_assembly in $loaded_assembly_list)
|
foreach ($loaded_assembly in $loaded_assembly_list)
|
||||||
{
|
{
|
||||||
$logloadedassembly = "L'assembly suivante est chargé: '$loaded_assembly'"
|
$logloadedassembly = "L'assembly suivante est chargé: '$loaded_assembly'"
|
||||||
WriteToLogFile0 $logloadedassembly
|
###WriteToLogFile0 $logloadedassembly
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
$logwpf = "ligne 55 - une exeption s'est produite $_.Exception.Message "
|
$logwpf = "ligne 55 - une exeption s'est produite $_.Exception.Message "
|
||||||
WriteToLogFile0 $logwpf
|
###WriteToLogFile0 $logwpf
|
||||||
}
|
}
|
||||||
################################################################################################################################################
|
|
||||||
################################################################################################################################################
|
|
||||||
############################################################### prérequis ######################################################################
|
|
||||||
################################################################################################################################################
|
|
||||||
################################################################################################################################################
|
|
||||||
|
|
||||||
## rendre disponible l'optional feature de windows Hyper-V:
|
|
||||||
# => dans la recherche windows : fonctionnalitées facultatives
|
|
||||||
# => se loguer en admin local
|
|
||||||
# => chercher dans le pop-up le module hyper-v pour powershell
|
|
||||||
# => Hyper-V
|
|
||||||
# =>Outils d'administration Hyper-V
|
|
||||||
# => Module Hyper-V pour Windows Powershell
|
|
||||||
# => cocher la case correspondante et valider sur ok, un redémarrage est peut-être nécessaire
|
|
||||||
|
|
||||||
|
|
||||||
################################################################################################################################################
|
################################################################################################################################################
|
||||||
@@ -99,15 +111,15 @@ try {
|
|||||||
# test de la bonne création de la table de hachage synchronisé
|
# test de la bonne création de la table de hachage synchronisé
|
||||||
if ($syncHash -is [System.Collections.Hashtable] -and $syncHash -is [System.Collections.ICollection]) {
|
if ($syncHash -is [System.Collections.Hashtable] -and $syncHash -is [System.Collections.ICollection]) {
|
||||||
$loghashtabl = "La création de l'hashtable synchronisé s'est déroulée correctement."
|
$loghashtabl = "La création de l'hashtable synchronisé s'est déroulée correctement."
|
||||||
WriteToLogFile0 $loghashtabl
|
###WriteToLogFile0 $loghashtabl
|
||||||
} else {
|
} else {
|
||||||
$loghashtabl = "Il y a eu un problème lors de la création de l'hashtable synchronisé."
|
$loghashtabl = "Il y a eu un problème lors de la création de l'hashtable synchronisé."
|
||||||
WriteToLogFile0 $loghashtabl
|
###WriteToLogFile0 $loghashtabl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
$loghashtabl = "ligne 93 - une exeption s'est produite $_.Exception.Message "
|
$loghashtabl = "ligne 93 - une exeption s'est produite $_.Exception.Message "
|
||||||
WriteToLogFile0 $loghashtabl
|
###WriteToLogFile0 $loghashtabl
|
||||||
}
|
}
|
||||||
|
|
||||||
################################################################################################################################################
|
################################################################################################################################################
|
||||||
@@ -125,33 +137,33 @@ try {
|
|||||||
if ($newRunspace.ApartmentState -like "STA")
|
if ($newRunspace.ApartmentState -like "STA")
|
||||||
{
|
{
|
||||||
$logrunspace1 = "le runspace créé avec un ApartmentState correct en STA ."
|
$logrunspace1 = "le runspace créé avec un ApartmentState correct en STA ."
|
||||||
WriteToLogFile0 $logrunspace1
|
###WriteToLogFile0 $logrunspace1
|
||||||
}else {
|
}else {
|
||||||
$logrunspace1 = "le runspace créé avec un ApartmentState incorrect ."
|
$logrunspace1 = "le runspace créé avec un ApartmentState incorrect ."
|
||||||
WriteToLogFile0 $logrunspace1
|
###WriteToLogFile0 $logrunspace1
|
||||||
}
|
}
|
||||||
if ($newRunspace.ThreadOptions -like "ReuseThread")
|
if ($newRunspace.ThreadOptions -like "ReuseThread")
|
||||||
{
|
{
|
||||||
$logrunspace2 = "le runspace créé avec un ThreadOptions correct en ReuseThread ."
|
$logrunspace2 = "le runspace créé avec un ThreadOptions correct en ReuseThread ."
|
||||||
WriteToLogFile0 $logrunspace2
|
###WriteToLogFile0 $logrunspace2
|
||||||
}else {
|
}else {
|
||||||
$logrunspace2 = "le runspace créé avec un ThreadOptions incorrect ."
|
$logrunspace2 = "le runspace créé avec un ThreadOptions incorrect ."
|
||||||
WriteToLogFile0 $logrunspace2
|
###WriteToLogFile0 $logrunspace2
|
||||||
}
|
}
|
||||||
# vérification de la variable sesion state proxy
|
# vérification de la variable sesion state proxy
|
||||||
$testSessionStateProxy = $newRunspace.SessionStateProxy.GetVariable("syncHash")
|
$testSessionStateProxy = $newRunspace.SessionStateProxy.GetVariable("syncHash")
|
||||||
if ($null -ne $testSessionStateProxy)
|
if ($null -ne $testSessionStateProxy)
|
||||||
{
|
{
|
||||||
$logrunspace3 = "le runspace créé avec un SessionStateProxy correct en associé à synchash ."
|
$logrunspace3 = "le runspace créé avec un SessionStateProxy correct en associé à synchash ."
|
||||||
WriteToLogFile0 $logrunspace3
|
###WriteToLogFile0 $logrunspace3
|
||||||
}else {
|
}else {
|
||||||
$logrunspace3 = "le runspace créé avec un SessionStateProxy incorrect ."
|
$logrunspace3 = "le runspace créé avec un SessionStateProxy incorrect ."
|
||||||
WriteToLogFile0 $logrunspace3
|
###WriteToLogFile0 $logrunspace3
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
$logdeclarunspace = "ligne 137 - une exeption s'est produite $_.Exception.Message "
|
$logdeclarunspace = "ligne 137 - une exeption s'est produite $_.Exception.Message "
|
||||||
WriteToLogFile0 $logdeclarunspace
|
###WriteToLogFile0 $logdeclarunspace
|
||||||
}
|
}
|
||||||
|
|
||||||
$psCmd = [PowerShell]::Create().AddScript({
|
$psCmd = [PowerShell]::Create().AddScript({
|
||||||
@@ -171,9 +183,9 @@ $psCmd = [PowerShell]::Create().AddScript({
|
|||||||
<StackPanel Name="SP_Contenu1" Orientation="Vertical" Width="654">
|
<StackPanel Name="SP_Contenu1" Orientation="Vertical" Width="654">
|
||||||
<StackPanel Name="SP_Buttons1" Orientation="Horizontal" Margin="0,10,412,0" >
|
<StackPanel Name="SP_Buttons1" Orientation="Horizontal" Margin="0,10,412,0" >
|
||||||
<Button Name="Start" Content="Demarrer les Tests" HorizontalAlignment="Center" Margin="20,0,0,0" VerticalAlignment="Top" Width="100" Height="25" />
|
<Button Name="Start" Content="Demarrer les Tests" HorizontalAlignment="Center" Margin="20,0,0,0" VerticalAlignment="Top" Width="100" Height="25" />
|
||||||
<Button Name="Stop" Content="Arreter les Test" HorizontalAlignment="Center" Margin="10,0,0,0" VerticalAlignment="Top" Width="100" Height="25" />
|
<Button Name="Stop" Content="Arreter les Tests" HorizontalAlignment="Center" Margin="10,0,0,0" VerticalAlignment="Top" Width="100" Height="25" />
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
<GroupBox Header="Qui que c'est qu'est réveillé?" BorderBrush="CornFlowerBlue" Margin="4,0,-104,0" Height="281">
|
<GroupBox Header="On Fait l'appel!!" BorderBrush="CornFlowerBlue" Margin="4,0,-104,0" Height="281">
|
||||||
<DataGrid SelectionMode="Single" Name="ConnexionGrid" ItemsSource="{Binding}" Margin="0,0,115,3">
|
<DataGrid SelectionMode="Single" Name="ConnexionGrid" ItemsSource="{Binding}" Margin="0,0,115,3">
|
||||||
<DataGrid.Columns>
|
<DataGrid.Columns>
|
||||||
<DataGridTextColumn Header="Serveur" Binding="{Binding Serveur}"/>
|
<DataGridTextColumn Header="Serveur" Binding="{Binding Serveur}"/>
|
||||||
@@ -213,20 +225,20 @@ $psCmd = [PowerShell]::Create().AddScript({
|
|||||||
</StackPanel>
|
</StackPanel>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
<StackPanel Name="partiedroite" HorizontalAlignment="Right" VerticalAlignment="Top">
|
<StackPanel Name="partiedroite" HorizontalAlignment="Right" VerticalAlignment="Top">
|
||||||
<StackPanel x:Name="SP_Contenu2" Orientation="Vertical" Width="100" Margin="0,20,20,0" RenderTransformOrigin="0.49,2.067">
|
<StackPanel x:Name="SP_Contenu2" Orientation="Vertical" Width="110" Margin="0,20,20,0" RenderTransformOrigin="0.49,2.067">
|
||||||
<StackPanel x:Name="SP_Buttons3" Orientation="Vertical" Width="100" Margin="0,40,0,0">
|
<StackPanel x:Name="SP_Buttons3" Orientation="Vertical" Width="110" Margin="0,40,0,0">
|
||||||
<Button x:Name="Start_machine" Content="Start Machine" HorizontalAlignment="Left" Margin="0,0,0,0" VerticalAlignment="Top" Width="100" Height="25" />
|
<Button x:Name="Start_machine" Content="Start Machine" HorizontalAlignment="Left" Margin="0,0,0,0" VerticalAlignment="Top" Width="110" Height="25" />
|
||||||
<Button x:Name="Reboot_machine" Content="Reboot Machine" HorizontalAlignment="Left" Margin="0,10,0,0" VerticalAlignment="Top" Width="100" Height="25" />
|
<Button x:Name="Reboot_machine" Content="Reboot Machine" HorizontalAlignment="Left" Margin="0,10,0,0" VerticalAlignment="Top" Width="110" Height="25" />
|
||||||
<Button x:Name="Rename_machine" Content="Rename Machine" HorizontalAlignment="Left" Margin="0,10,0,0" VerticalAlignment="Top" Width="100" Height="25" />
|
<Button x:Name="Rename_machine" Content="Rename Machine" HorizontalAlignment="Left" Margin="0,10,0,0" VerticalAlignment="Top" Width="110" Height="25" />
|
||||||
<Button x:Name="shutdown_machine" Content="Arrêt Machine" HorizontalAlignment="Left" Margin="0,10,0,0" VerticalAlignment="Top" Width="100" Height="25" />
|
<Button x:Name="shutdown_machine" Content="Arrêt Machine" HorizontalAlignment="Left" Margin="0,10,0,0" VerticalAlignment="Top" Width="110" Height="25" />
|
||||||
<Button x:Name="ajout_machine" Content="Ajouter Machine" HorizontalAlignment="Left" Margin="0,10,0,0" VerticalAlignment="Top" Width="100" Height="25" />
|
<Button x:Name="ajout_machine" Content="Ajouter Machine" HorizontalAlignment="Left" Margin="0,10,0,0" VerticalAlignment="Top" Width="110" Height="25" />
|
||||||
<Button x:Name="Remove_machine" Content="Effacer Machine" HorizontalAlignment="Left" Margin="0,10,0,0" VerticalAlignment="Top" Width="100" Height="25" />
|
<Button x:Name="Remove_machine" Content="Effacer Machine" HorizontalAlignment="Left" Margin="0,10,0,0" VerticalAlignment="Top" Width="110" Height="25" />
|
||||||
<Button x:Name="Reboot_service" Content="Reboot Service" HorizontalAlignment="Left" Margin="0,10,0,0" VerticalAlignment="Top" Width="100" Height="25" />
|
<Button x:Name="Reboot_service" Content="Reboot Service" HorizontalAlignment="Left" Margin="0,10,0,0" VerticalAlignment="Top" Width="110" Height="25" />
|
||||||
<Button x:Name="list_snap" Content="Lister Snapshot" HorizontalAlignment="Left" Margin="0,40,0,0" VerticalAlignment="Top" Width="100" Height="25" />
|
<Button x:Name="list_snap" Content="Lister Snapshot" HorizontalAlignment="Left" Margin="0,40,0,0" VerticalAlignment="Top" Width="110" Height="25" />
|
||||||
<Button x:Name="faire_snap" Content="Faire Snapshot" HorizontalAlignment="Left" Margin="0,10,0,0" VerticalAlignment="Top" Width="100" Height="25" />
|
<Button x:Name="faire_snap" Content="Faire Snapshot" HorizontalAlignment="Left" Margin="0,10,0,0" VerticalAlignment="Top" Width="110" Height="25" />
|
||||||
<Button x:Name="restore_snap" Content="Restorer Snapshot" HorizontalAlignment="Left" Margin="0,10,0,0" VerticalAlignment="Top" Width="100" Height="25" />
|
<Button x:Name="restore_snap" Content="Restaurer Snapshot" HorizontalAlignment="Left" Margin="0,10,0,0" VerticalAlignment="Top" Width="110" Height="25" />
|
||||||
<Button x:Name="suppr_snap" Content="Effacer Snapshot" HorizontalAlignment="Left" Margin="0,10,0,0" VerticalAlignment="Top" Width="100" Height="25" />
|
<Button x:Name="suppr_snap" Content="Effacer Snapshot" HorizontalAlignment="Left" Margin="0,10,0,0" VerticalAlignment="Top" Width="110" Height="25" />
|
||||||
<Button x:Name="rename_snap" Content="Rename Snapshot" HorizontalAlignment="Left" Margin="0,10,0,0" VerticalAlignment="Top" Width="100" Height="25" />
|
<Button x:Name="rename_snap" Content="Rename Snapshot" HorizontalAlignment="Left" Margin="0,10,0,0" VerticalAlignment="Top" Width="110" Height="25" />
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
@@ -244,13 +256,8 @@ $psCmd = [PowerShell]::Create().AddScript({
|
|||||||
################################################## initialisation des variables nécessaires ####################################################
|
################################################## initialisation des variables nécessaires ####################################################
|
||||||
################################################################################################################################################
|
################################################################################################################################################
|
||||||
################################################################################################################################################
|
################################################################################################################################################
|
||||||
|
|
||||||
## déclaration des variables windows
|
## déclaration des variables de connexion Linux
|
||||||
$username_win = "operis.champlan\admin_dom_mts"
|
|
||||||
$password_win = ConvertTo-SecureString "Alemax1803!!" -AsPlainText -Force
|
|
||||||
$cred_win = New-Object System.Management.Automation.PSCredential($Username_win, $Password_win)
|
|
||||||
|
|
||||||
## déclaration des variables windows
|
|
||||||
$username_debian = "root"
|
$username_debian = "root"
|
||||||
$password_debian = "Operis!2023#"
|
$password_debian = "Operis!2023#"
|
||||||
|
|
||||||
@@ -376,16 +383,16 @@ $psCmd = [PowerShell]::Create().AddScript({
|
|||||||
}
|
}
|
||||||
|
|
||||||
function test_jetty_win {
|
function test_jetty_win {
|
||||||
Invoke-Command -ComputerName $nom_machine -ScriptBlock {Get-Service -Name *operis* } -Credential $cred_win
|
Invoke-Command -ComputerName $nom_machine -ScriptBlock {Get-Service -Name *operis* }
|
||||||
}
|
}
|
||||||
|
|
||||||
function redemarrage_jetty_windows {
|
function redemarrage_jetty_windows {
|
||||||
$test_jetty_init = test_jetty_win
|
$test_jetty_init = test_jetty_win
|
||||||
if ($null -ne $test_jetty_init) {
|
if ($null -ne $test_jetty_init) {
|
||||||
Invoke-Command -ComputerName $nom_machine -ScriptBlock {Get-Service -Name *operis* |Stop-Service } -Credential $cred_win |Out-Null
|
Invoke-Command -ComputerName $nom_machine -ScriptBlock {Get-Service -Name *operis* |Stop-Service } |Out-Null
|
||||||
$test_arret_jetty = test_jetty_win
|
$test_arret_jetty = test_jetty_win
|
||||||
if ($test_arret_jetty.Status -like "Stopped") {
|
if ($test_arret_jetty.Status -like "Stopped") {
|
||||||
Invoke-Command -ComputerName $nom_machine -ScriptBlock {Get-Service -Name *operis* |Start-Service } -Credential $cred_win
|
Invoke-Command -ComputerName $nom_machine -ScriptBlock {Get-Service -Name *operis* |Start-Service }
|
||||||
$test_reboot_jetty = test_jetty_win
|
$test_reboot_jetty = test_jetty_win
|
||||||
if ($test_reboot_jetty.Status -like "running") {
|
if ($test_reboot_jetty.Status -like "running") {
|
||||||
[System.Windows.Forms.MessageBox]::Show('Redemarrage jetty réussi', 'Warning', 'ok', 'Warning')
|
[System.Windows.Forms.MessageBox]::Show('Redemarrage jetty réussi', 'Warning', 'ok', 'Warning')
|
||||||
@@ -403,6 +410,7 @@ $psCmd = [PowerShell]::Create().AddScript({
|
|||||||
function stop_process {
|
function stop_process {
|
||||||
Stop-Process -Id $monPID -Force
|
Stop-Process -Id $monPID -Force
|
||||||
}
|
}
|
||||||
|
|
||||||
################################################################################################################################################
|
################################################################################################################################################
|
||||||
################################################################################################################################################
|
################################################################################################################################################
|
||||||
######################################################### Fermeture de la fenètre ##############################################################
|
######################################################### Fermeture de la fenètre ##############################################################
|
||||||
@@ -410,7 +418,7 @@ $psCmd = [PowerShell]::Create().AddScript({
|
|||||||
################################################################################################################################################
|
################################################################################################################################################
|
||||||
$syncHash.Window.Add_Closing({
|
$syncHash.Window.Add_Closing({
|
||||||
$_.Cancel = $true
|
$_.Cancel = $true
|
||||||
$Resultat = [System.Windows.Forms.MessageBox]::Show('Voulez-vous fermer lapplication ?', 'Warning', 'YesNo', 'Warning')
|
$Resultat = [System.Windows.Forms.MessageBox]::Show("C'est fini ?", 'Warning', 'YesNo', 'Warning')
|
||||||
If ($Resultat -eq 'Yes')
|
If ($Resultat -eq 'Yes')
|
||||||
{
|
{
|
||||||
$_.Cancel = $false
|
$_.Cancel = $false
|
||||||
@@ -440,11 +448,10 @@ $psCmd = [PowerShell]::Create().AddScript({
|
|||||||
$MAJ_GUIRunspace.SessionStateProxy.SetVariable("syncHash",$syncHash)
|
$MAJ_GUIRunspace.SessionStateProxy.SetVariable("syncHash",$syncHash)
|
||||||
###WriteToLogFile1 "ouverture runspace enfant ok"
|
###WriteToLogFile1 "ouverture runspace enfant ok"
|
||||||
$psScript = [PowerShell]::Create().AddScript({
|
$psScript = [PowerShell]::Create().AddScript({
|
||||||
## Corps du runspace
|
# Corps du runspace
|
||||||
function WriteToLogFile2 ($message) {
|
function WriteToLogFile2 ($message) {
|
||||||
(Get-Date).ToString() +" - "+ $message >> $global:syncHash.logfilepath
|
(Get-Date).ToString() +" - "+ $message >> $global:syncHash.logfilepath
|
||||||
}
|
}
|
||||||
#$todaysdate = Get-Date -Format "dd/mm/yyyy-hh-mm-ss"
|
|
||||||
$MachinesXML = [xml](get-content $syncHash.Liste_vm )
|
$MachinesXML = [xml](get-content $syncHash.Liste_vm )
|
||||||
$Liste_Machines = $MachinesXML.Machine.Serveur
|
$Liste_Machines = $MachinesXML.Machine.Serveur
|
||||||
while ($syncHash.tests_en_cours -like $true) {
|
while ($syncHash.tests_en_cours -like $true) {
|
||||||
@@ -802,7 +809,7 @@ $psCmd = [PowerShell]::Create().AddScript({
|
|||||||
$label = New-Object System.Windows.Forms.Label
|
$label = New-Object System.Windows.Forms.Label
|
||||||
$label.Location = New-Object System.Drawing.Point(10,20)
|
$label.Location = New-Object System.Drawing.Point(10,20)
|
||||||
$label.Size = New-Object System.Drawing.Size(280,20)
|
$label.Size = New-Object System.Drawing.Size(280,20)
|
||||||
$label.Text = "Arrêts VM: $nom_machine"
|
$label.Text = "Arrêt de la VM $nom_machine ?"
|
||||||
$form.Controls.Add($label)
|
$form.Controls.Add($label)
|
||||||
|
|
||||||
$form.Topmost = $True
|
$form.Topmost = $True
|
||||||
@@ -970,7 +977,10 @@ $psCmd = [PowerShell]::Create().AddScript({
|
|||||||
foreach ($selected_item in $global:syncHash.Datagrid_Connexion.SelectedItems)
|
foreach ($selected_item in $global:syncHash.Datagrid_Connexion.SelectedItems)
|
||||||
{
|
{
|
||||||
$nom_machine = $selected_item.Serveur
|
$nom_machine = $selected_item.Serveur
|
||||||
|
###WriteToLogFile1 "Demande redémarrage jetty sur le serveur : $nom_machine"
|
||||||
$OS_machine = $selected_item.OS
|
$OS_machine = $selected_item.OS
|
||||||
|
###WriteToLogFile1 "OS du serveur sélectionné: $OS_machine"
|
||||||
|
|
||||||
}
|
}
|
||||||
## début définition pop-up de suppression machine ##
|
## début définition pop-up de suppression machine ##
|
||||||
Add-Type -AssemblyName System.Windows.Forms
|
Add-Type -AssemblyName System.Windows.Forms
|
||||||
@@ -1000,7 +1010,7 @@ $psCmd = [PowerShell]::Create().AddScript({
|
|||||||
$label = New-Object System.Windows.Forms.Label
|
$label = New-Object System.Windows.Forms.Label
|
||||||
$label.Location = New-Object System.Drawing.Point(10,20)
|
$label.Location = New-Object System.Drawing.Point(10,20)
|
||||||
$label.Size = New-Object System.Drawing.Size(360,20)
|
$label.Size = New-Object System.Drawing.Size(360,20)
|
||||||
$label.Text = "redémarrage service jetty (java) de la vm $nom_machine ?"
|
$label.Text = "Redémarrage service jetty (java) de la VM $nom_machine ?"
|
||||||
$form_Remove_machine.Controls.Add($label)
|
$form_Remove_machine.Controls.Add($label)
|
||||||
|
|
||||||
$form_Remove_machine.Topmost = $True
|
$form_Remove_machine.Topmost = $True
|
||||||
@@ -1062,7 +1072,7 @@ $psCmd = [PowerShell]::Create().AddScript({
|
|||||||
$list_snap = Get-VMSnapshot -ComputerName $syncHash.serveur_vm -VMName $nom_machine | Select-Object -Property CreationTime,Name,VMName
|
$list_snap = Get-VMSnapshot -ComputerName $syncHash.serveur_vm -VMName $nom_machine | Select-Object -Property CreationTime,Name,VMName
|
||||||
$nbr_snap = $list_snap.Count
|
$nbr_snap = $list_snap.Count
|
||||||
###WriteToLogFile1 "$nbr_snap snap sur la vm $nom_machine"
|
###WriteToLogFile1 "$nbr_snap snap sur la vm $nom_machine"
|
||||||
if ($nbr_snap -lt 2 )
|
if ($nbr_snap -lt 2 ) #=> check du nombre max de snapshots
|
||||||
{
|
{
|
||||||
foreach ($selected_item in $global:syncHash.Datagrid_Connexion.SelectedItems)
|
foreach ($selected_item in $global:syncHash.Datagrid_Connexion.SelectedItems)
|
||||||
{
|
{
|
||||||
@@ -1130,7 +1140,7 @@ $psCmd = [PowerShell]::Create().AddScript({
|
|||||||
|
|
||||||
################################################################################################################################################
|
################################################################################################################################################
|
||||||
################################################################################################################################################
|
################################################################################################################################################
|
||||||
######################################################### Restorer Snapshot ####################################################################
|
######################################################### Restaurer Snapshot ####################################################################
|
||||||
################################################################################################################################################
|
################################################################################################################################################
|
||||||
################################################################################################################################################
|
################################################################################################################################################
|
||||||
$syncHash.BTN_restore_snap.add_click({
|
$syncHash.BTN_restore_snap.add_click({
|
||||||
@@ -1175,7 +1185,7 @@ $psCmd = [PowerShell]::Create().AddScript({
|
|||||||
$label2 = New-Object System.Windows.Forms.Label
|
$label2 = New-Object System.Windows.Forms.Label
|
||||||
$label2.Location = New-Object System.Drawing.Point(10,40)
|
$label2.Location = New-Object System.Drawing.Point(10,40)
|
||||||
$label2.Size = New-Object System.Drawing.Size(380,20)
|
$label2.Size = New-Object System.Drawing.Size(380,20)
|
||||||
$label2.Text = "réaliser le $date_Snap"
|
$label2.Text = "Réaliser le $date_Snap"
|
||||||
$form_restore_snap.Controls.Add($label2)
|
$form_restore_snap.Controls.Add($label2)
|
||||||
|
|
||||||
$form_restore_snap.Topmost = $True
|
$form_restore_snap.Topmost = $True
|
||||||
@@ -1183,7 +1193,7 @@ $psCmd = [PowerShell]::Create().AddScript({
|
|||||||
## fin définition pop-up de restauration Snapshot ##
|
## fin définition pop-up de restauration Snapshot ##
|
||||||
if ($result -eq [System.Windows.Forms.DialogResult]::OK)
|
if ($result -eq [System.Windows.Forms.DialogResult]::OK)
|
||||||
{
|
{
|
||||||
###WriteToLogFile1 "retour au snapchot $nom_Snap demandé sur la vm : $VM_Snap"
|
###WriteToLogFile1 "retour au snapshot $nom_Snap demandé sur la vm : $VM_Snap"
|
||||||
# arrêt machine pour éviter un freeze de l'application lors de la restauration du snapshot
|
# arrêt machine pour éviter un freeze de l'application lors de la restauration du snapshot
|
||||||
Stop-VM -computername $syncHash.serveur_vm -name $nom_machine -Force
|
Stop-VM -computername $syncHash.serveur_vm -name $nom_machine -Force
|
||||||
# restauration du snapshot
|
# restauration du snapshot
|
||||||
@@ -1245,7 +1255,7 @@ $psCmd = [PowerShell]::Create().AddScript({
|
|||||||
$label2 = New-Object System.Windows.Forms.Label
|
$label2 = New-Object System.Windows.Forms.Label
|
||||||
$label2.Location = New-Object System.Drawing.Point(10,40)
|
$label2.Location = New-Object System.Drawing.Point(10,40)
|
||||||
$label2.Size = New-Object System.Drawing.Size(380,20)
|
$label2.Size = New-Object System.Drawing.Size(380,20)
|
||||||
$label2.Text = "réaliser le $date_Snap"
|
$label2.Text = "Réaliser le $date_Snap"
|
||||||
$form_suppr_snap.Controls.Add($label2)
|
$form_suppr_snap.Controls.Add($label2)
|
||||||
|
|
||||||
$form_suppr_snap.Topmost = $True
|
$form_suppr_snap.Topmost = $True
|
||||||
@@ -1283,7 +1293,7 @@ $psCmd = [PowerShell]::Create().AddScript({
|
|||||||
Add-Type -AssemblyName System.Drawing
|
Add-Type -AssemblyName System.Drawing
|
||||||
|
|
||||||
$form_rename_snap = New-Object System.Windows.Forms.Form
|
$form_rename_snap = New-Object System.Windows.Forms.Form
|
||||||
$form_rename_snap.Text = "Suppression Snapshot - Support"
|
$form_rename_snap.Text = "Changement nom Snapshot"
|
||||||
$form_rename_snap.Size = New-Object System.Drawing.Size(300,150)
|
$form_rename_snap.Size = New-Object System.Drawing.Size(300,150)
|
||||||
$form_rename_snap.StartPosition = "CenterScreen"
|
$form_rename_snap.StartPosition = "CenterScreen"
|
||||||
|
|
||||||
@@ -1334,9 +1344,8 @@ $psCmd = [PowerShell]::Create().AddScript({
|
|||||||
###WriteToLogFile1 "Echec renommage snapshot sur la vm $VM_Snap - Aucun snapshot sélectionné"
|
###WriteToLogFile1 "Echec renommage snapshot sur la vm $VM_Snap - Aucun snapshot sélectionné"
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
$syncHash.Window.ShowDialog() | Out-Null
|
$syncHash.Window.ShowDialog() | Out-Null
|
||||||
|
|
||||||
})
|
})
|
||||||
try {
|
try {
|
||||||
$psCmd.Runspace = $newRunspace
|
$psCmd.Runspace = $newRunspace
|
||||||
|
|||||||
Reference in New Issue
Block a user