1360 lines
81 KiB
PowerShell
1360 lines
81 KiB
PowerShell
<#
|
|
.SYNOPSIS
|
|
Interface de supervision des machines virtuelles du service support
|
|
.DESCRIPTION
|
|
Auteur : Maxime Tertrais
|
|
Date creation : 27/11/2023
|
|
/Dernier modificateur : Maxime Tertrais
|
|
Date derniere modification :04/12/2023
|
|
Ce script permet de superviser les machines virtuelles du service support:
|
|
- gestion des 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)
|
|
- Ajouter une machine à la liste des machine à tester
|
|
- 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 debug (les logs)
|
|
|
|
.NOTES
|
|
Fonctionnement du script en mode fenètré.
|
|
|
|
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
|
|
#>
|
|
|
|
################################################################################################################################################
|
|
################################################################################################################################################
|
|
###################################################### Définition variable pour les logs #######################################################
|
|
################################################################################################################################################
|
|
################################################################################################################################################
|
|
$logfilepath = ".\Logs_supervision_vm_v4.0.log"
|
|
function WriteToLogFile0 ($message) {
|
|
(Get-Date).ToString() +" - "+ $message >> $logfilepath
|
|
}
|
|
|
|
if(Test-Path $logfilepath)
|
|
{
|
|
Remove-Item $logfilepath
|
|
}
|
|
###WriteToLogFile0 "Id du process ouvert $monPID "
|
|
|
|
################################################################################################################################################
|
|
################################################################################################################################################
|
|
################################################# Assembly nécessaire pour la fenêtre graphique ################################################
|
|
################################################################################################################################################
|
|
################################################################################################################################################
|
|
try {
|
|
$assembly_list = "PresentationFramework","System.Windows.Forms","PresentationCore","WindowsBase","System.Xaml","UIAutomationClient","UIAutomationTypes","WindowsFormsIntegration","System","System.Core","mscorlib","System.Management.Automation","System.Threading"
|
|
foreach ($assembly in $assembly_list)
|
|
{
|
|
# Chargement des assemblies
|
|
Add-Type -AssemblyName $assembly
|
|
# Test des assemblies chargées
|
|
$loadedAssemblies = [System.AppDomain]::CurrentDomain.GetAssemblies()| Where-Object { $_.GetName().Name -eq $assembly }
|
|
$assemblyLoaded = $loadedAssemblies.FullName -contains $assembly
|
|
if ($null -ne $assemblyLoaded) {
|
|
$logassembly = "L'assembly '$assembly' est chargé correctement."
|
|
###WriteToLogFile0 $logassembly
|
|
} else {
|
|
$logassembly = "L'assembly '$assembly' n'est pas chargé correctement."
|
|
###WriteToLogFile0 $logassembly
|
|
}
|
|
}
|
|
$loaded_assembly_list = [System.AppDomain]::CurrentDomain.GetAssemblies()| Select-Object -Property FullName
|
|
foreach ($loaded_assembly in $loaded_assembly_list)
|
|
{
|
|
$logloadedassembly = "L'assembly suivante est chargé: '$loaded_assembly'"
|
|
###WriteToLogFile0 $logloadedassembly
|
|
}
|
|
}
|
|
catch {
|
|
$logwpf = "ligne 55 - une exeption s'est produite $_.Exception.Message "
|
|
###WriteToLogFile0 $logwpf
|
|
}
|
|
|
|
|
|
################################################################################################################################################
|
|
################################################################################################################################################
|
|
############################## Déclaration de la Hash table qui sera synchronisée entre les différents runspaces ###############################
|
|
################################################################################################################################################
|
|
################################################################################################################################################
|
|
|
|
try {
|
|
# création de la table de hachage synchronisé
|
|
$syncHash = [hashtable]::Synchronized(@{})
|
|
# test de la bonne création de la table de hachage synchronisé
|
|
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."
|
|
###WriteToLogFile0 $loghashtabl
|
|
} else {
|
|
$loghashtabl = "Il y a eu un problème lors de la création de l'hashtable synchronisé."
|
|
###WriteToLogFile0 $loghashtabl
|
|
}
|
|
}
|
|
catch {
|
|
$loghashtabl = "ligne 93 - une exeption s'est produite $_.Exception.Message "
|
|
###WriteToLogFile0 $loghashtabl
|
|
}
|
|
|
|
################################################################################################################################################
|
|
################################################################################################################################################
|
|
############################################ Déclaration du premier runspace pour l'interface graphique ########################################
|
|
################################################################################################################################################
|
|
################################################################################################################################################
|
|
try {
|
|
$newRunspace =[runspacefactory]::CreateRunspace()
|
|
$newRunspace.ApartmentState = "STA" ## Le STA est là pour l'interface en WPF
|
|
$newRunspace.ThreadOptions = "ReuseThread"
|
|
$newRunspace.Open()
|
|
$newRunspace.SessionStateProxy.SetVariable("syncHash",$syncHash)
|
|
# vérification création du Runspace
|
|
if ($newRunspace.ApartmentState -like "STA")
|
|
{
|
|
$logrunspace1 = "le runspace créé avec un ApartmentState correct en STA ."
|
|
###WriteToLogFile0 $logrunspace1
|
|
}else {
|
|
$logrunspace1 = "le runspace créé avec un ApartmentState incorrect ."
|
|
###WriteToLogFile0 $logrunspace1
|
|
}
|
|
if ($newRunspace.ThreadOptions -like "ReuseThread")
|
|
{
|
|
$logrunspace2 = "le runspace créé avec un ThreadOptions correct en ReuseThread ."
|
|
###WriteToLogFile0 $logrunspace2
|
|
}else {
|
|
$logrunspace2 = "le runspace créé avec un ThreadOptions incorrect ."
|
|
###WriteToLogFile0 $logrunspace2
|
|
}
|
|
# vérification de la variable sesion state proxy
|
|
$testSessionStateProxy = $newRunspace.SessionStateProxy.GetVariable("syncHash")
|
|
if ($null -ne $testSessionStateProxy)
|
|
{
|
|
$logrunspace3 = "le runspace créé avec un SessionStateProxy correct en associé à synchash ."
|
|
###WriteToLogFile0 $logrunspace3
|
|
}else {
|
|
$logrunspace3 = "le runspace créé avec un SessionStateProxy incorrect ."
|
|
###WriteToLogFile0 $logrunspace3
|
|
}
|
|
}
|
|
catch {
|
|
$logdeclarunspace = "ligne 137 - une exeption s'est produite $_.Exception.Message "
|
|
###WriteToLogFile0 $logdeclarunspace
|
|
}
|
|
|
|
$psCmd = [PowerShell]::Create().AddScript({
|
|
################################################################################################################################################
|
|
################################################################################################################################################
|
|
############################################ Déclaration du code XAML de l'interface graphique WPF #############################################
|
|
################################################################################################################################################
|
|
################################################################################################################################################
|
|
[xml]$Fenetre_principale = @"
|
|
<Window
|
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
|
x:Name="Window_principale" Title="Supervision VM - Support" Height="560" Width="780" ResizeMode="NoResize">
|
|
|
|
<Grid x:Name="LayoutRoot" Background="#FFC1C3CB">
|
|
<StackPanel Name="partieguauche" HorizontalAlignment="Left" VerticalAlignment="Top">
|
|
<StackPanel Name="SP_Contenu1" Orientation="Vertical" Width="654">
|
|
<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="Stop" Content="Arreter les Tests" HorizontalAlignment="Center" Margin="10,0,0,0" VerticalAlignment="Top" Width="100" Height="25" />
|
|
</StackPanel>
|
|
<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.Columns>
|
|
<DataGridTextColumn Header="Serveur" Binding="{Binding Serveur}"/>
|
|
<DataGridTextColumn Header="Ip" Binding="{Binding Ip}"/>
|
|
<DataGridTextColumn Header="Status" Binding="{Binding State}"/>
|
|
<DataGridTextColumn Header="OS" Binding="{Binding OS}"/>
|
|
<DataGridTextColumn Header="Modele BDD" Binding="{Binding BDD}"/>
|
|
<DataGridTextColumn Header="DDC" Binding="{Binding DDC}"/>
|
|
<DataGridTextColumn Header="Oxalis" Binding="{Binding Oxalis}"/>
|
|
<DataGridTextColumn Header="Gnau" Binding="{Binding Gnau}"/>
|
|
<DataGridTextColumn Header="Gnaubo" Binding="{Binding Gnaubo}"/>
|
|
</DataGrid.Columns>
|
|
<DataGrid.RowStyle>
|
|
<Style TargetType="DataGridRow">
|
|
<Setter Property="IsHitTestVisible" Value="True"/>
|
|
<Style.Triggers>
|
|
<DataTrigger Binding="{Binding State}" Value="Off">
|
|
<Setter Property="Background" Value="#E14D57"></Setter>
|
|
</DataTrigger>
|
|
<DataTrigger Binding="{Binding State}" Value="Running">
|
|
<Setter Property="Background" Value="#71B37C"></Setter>
|
|
</DataTrigger>
|
|
</Style.Triggers>
|
|
</Style>
|
|
</DataGrid.RowStyle>
|
|
</DataGrid>
|
|
</GroupBox>
|
|
<GroupBox Header="on à fait une erreur???" BorderBrush="CornFlowerBlue" Margin="4,0,-104,0" Height="192">
|
|
<DataGrid SelectionMode="Single" Name="SnapeshotGrid" ItemsSource="{Binding }" Margin="0,0,116,3" AutoGenerateColumns="True">
|
|
<DataGrid.Columns>
|
|
<DataGridTextColumn Header="Machine" Binding="{Binding VM_snapshot}"/>
|
|
<DataGridTextColumn Header="Date" Binding="{Binding date_snapshot}"/>
|
|
<DataGridTextColumn Header="Nom" Binding="{Binding nom_snapshot}"/>
|
|
</DataGrid.Columns>
|
|
</DataGrid>
|
|
</GroupBox>
|
|
</StackPanel>
|
|
</StackPanel>
|
|
<StackPanel Name="partiedroite" HorizontalAlignment="Right" VerticalAlignment="Top">
|
|
<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="110" Margin="0,40,0,0">
|
|
<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="110" 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="110" 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="110" 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="110" 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="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="110" 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>
|
|
</Grid>
|
|
</Window>
|
|
"@
|
|
|
|
##Intégration du code XAML à la hash table
|
|
$FormFenetre_principale = (New-Object System.Xml.XmlNodeReader $Fenetre_principale)
|
|
$global:syncHash.Window = [Windows.Markup.XamlReader]::Load($FormFenetre_principale)
|
|
|
|
|
|
################################################################################################################################################
|
|
################################################################################################################################################
|
|
################################################## initialisation des variables nécessaires ####################################################
|
|
################################################################################################################################################
|
|
################################################################################################################################################
|
|
|
|
## déclaration des variables de connexion Linux
|
|
$username_debian = "root"
|
|
$password_debian = "Operis!2023#"
|
|
|
|
## déclaration des contrôles
|
|
$global:syncHash.Datagrid_Connexion = $global:syncHash.Window.FindName("ConnexionGrid")
|
|
$global:syncHash.Datagrid_Snapshot = $global:syncHash.Window.FindName("SnapeshotGrid")
|
|
|
|
$global:syncHash.BTN_Start = $global:syncHash.Window.FindName("Start")
|
|
$global:syncHash.BTN_Stop = $global:syncHash.Window.FindName("Stop")
|
|
$global:syncHash.BTN_Start_machine = $global:syncHash.Window.FindName("Start_machine")
|
|
$global:syncHash.BTN_reboot_machine = $global:syncHash.Window.FindName("Reboot_machine")
|
|
$global:syncHash.BTN_rename_machine = $global:syncHash.Window.FindName("Rename_machine")
|
|
$global:syncHash.BTN_shutdown_machine = $global:syncHash.Window.FindName("shutdown_machine")
|
|
$global:syncHash.BTN_ajout_machine = $global:syncHash.Window.FindName("ajout_machine")
|
|
$global:syncHash.BTN_Remove_machine = $global:syncHash.Window.FindName("Remove_machine")
|
|
$global:syncHash.BTN_Reboot_service = $global:syncHash.Window.FindName("Reboot_service")
|
|
$global:syncHash.BTN_list_snap = $global:syncHash.Window.FindName("list_snap")
|
|
$global:syncHash.BTN_faire_snap = $global:syncHash.Window.FindName("faire_snap")
|
|
$global:syncHash.BTN_restore_snap = $global:syncHash.Window.FindName("restore_snap")
|
|
$global:syncHash.BTN_suppr_snap = $global:syncHash.Window.FindName("suppr_snap")
|
|
$global:syncHash.BTN_rename_snap = $global:syncHash.Window.FindName("rename_snap")
|
|
|
|
## déclaration des variables
|
|
$global:syncHash.serveur_vm = "srvvm3","srvvm4"
|
|
$global:syncHash.Liste_vm = ".\Liste_VM.xml"
|
|
$global:syncHash.BTN_Start.IsEnabled =$true
|
|
$global:syncHash.BTN_Stop.IsEnabled = $false
|
|
$global:syncHash.tests_en_cours = $false
|
|
$global:syncHash.logfilepath = ".\Logs_supervision_vm_v4.0.log"
|
|
$global:syncHash.todaysdate = Get-Date -Format "MM-dd-yyyy-hh-mm-ss"
|
|
$monPID = $PID
|
|
|
|
#Déclaration de fonctions
|
|
function WriteToLogFile1 ($message) {
|
|
(Get-Date).ToString() +" - "+ $message >> $global:syncHash.logfilepath
|
|
}
|
|
|
|
function Hide-Console {
|
|
$consolePtr = [Console.Window]::GetConsoleWindow()
|
|
[Console.Window]::ShowWindow($consolePtr, 0)
|
|
}
|
|
Hide-Console
|
|
|
|
function refresh_liste_snapshot {
|
|
$syncHash.Datagrid_Snapshot.Items.Clear() #=> vidange du datagrid avant chaque requète
|
|
$syncHash.Datagrid_Snapshot.Items.Refresh() #=> vidange du datagrid avant chaque requète
|
|
foreach ($selected_item in $syncHash.Datagrid_Connexion.SelectedItems)
|
|
{
|
|
$nom_machine = $selected_item.Serveur
|
|
###WriteToLogFile1 "Le serveur sélectionné:$nom_machine"
|
|
$list_snap = Get-VMSnapshot -ComputerName $global:syncHash.serveur_vm -VMName $nom_machine | Select-Object -Property CreationTime,Name,VMName
|
|
$num_snap = 0
|
|
ForEach ($Snap in $list_snap)
|
|
{
|
|
$num_snap = $num_snap + 1
|
|
$nom_snap = $Snap.Name
|
|
###WriteToLogFile1 "snapshot n° $num_snap détecté : $nom_snap"
|
|
$Snap_Valeur = New-Object PSObject
|
|
$Snap_Valeur = $Snap_Valeur | Add-Member NoteProperty VM_snapshot $Snap.VMName -passthru
|
|
$Snap_Valeur = $Snap_Valeur | Add-Member NoteProperty date_snapshot $Snap.CreationTime -passthru
|
|
$Snap_Valeur = $Snap_Valeur | Add-Member NoteProperty nom_snapshot $Snap.Name -passthru
|
|
$syncHash.Datagrid_Snapshot.Items.Add($Snap_Valeur) > $null
|
|
###WriteToLogFile1 "MàJ Datagrid_Snapshot ok"
|
|
}
|
|
}
|
|
}
|
|
|
|
function suppression_VM_dans_list {
|
|
# Chargement du fichier XML
|
|
[xml] $MaJ_Liste_vm = (Get-Content -Path $syncHash.Liste_vm)
|
|
|
|
# Suppression des éléments liés à la machine suprimmées
|
|
$VM_effacee = $MaJ_Liste_vm.Machine.Serveur | Where-Object {$PSItem.Address -eq $nom_machine} #=>récupération des infos de la VM suprimmée
|
|
$MaJ_Liste_vm.Machine.removeChild($VM_effacee)
|
|
|
|
# Sauvegarde des modifications dans le fichier XML
|
|
$MaJ_Liste_vm.Save($syncHash.Liste_vm)
|
|
}
|
|
|
|
function arret_service {
|
|
$stop_jetty = "kill -9 $resultat "
|
|
$arret_service = {plink.exe -ssh $username_debian@$nom_machine -pw $password_debian $stop_jetty}
|
|
Write-Output y | Invoke-command -ScriptBlock $arret_service
|
|
}
|
|
|
|
function status_service {
|
|
$status_jetty = "pgrep java"
|
|
$verif_status = {plink.exe -ssh $username_debian@$nom_machine -pw $password_debian $status_jetty}
|
|
Write-Output y | Invoke-command -ScriptBlock $verif_status
|
|
}
|
|
|
|
function start_service {
|
|
$start_jetty = "/etc/init.d/operis-9.4.8 start"
|
|
$start_service = {plink.exe -ssh $username_debian@$nom_machine -pw $password_debian $start_jetty}
|
|
Write-Output y | Invoke-command -ScriptBlock $start_service
|
|
}
|
|
|
|
function redemarrage_jetty_debian {
|
|
$status_init_service = status_service
|
|
if ($null -ne $status_init_service)
|
|
{
|
|
foreach ($resultat in $status_init_service)
|
|
{
|
|
arret_service
|
|
}
|
|
$status_arret_service = status_service
|
|
if ($null -eq $status_arret_service)
|
|
{
|
|
start_service
|
|
$status_restart_service = status_service
|
|
if ($null -ne $status_restart_service)
|
|
{
|
|
[System.Windows.Forms.MessageBox]::Show('Redemarrage jetty réussi', 'Warning', 'ok', 'Warning')
|
|
}else {
|
|
[System.Windows.Forms.MessageBox]::Show('Echec redemarrage jetty', 'Warning', 'ok', 'Warning')
|
|
}
|
|
}else {
|
|
[System.Windows.Forms.MessageBox]::Show('Echec arret jetty', 'Warning', 'ok', 'Warning')
|
|
}
|
|
}else {
|
|
[System.Windows.Forms.MessageBox]::Show('Jetty non démarré', 'Warning', 'ok', 'Warning')
|
|
}
|
|
}
|
|
|
|
function test_jetty_win {
|
|
Invoke-Command -ComputerName $nom_machine -ScriptBlock {Get-Service -Name *operis* }
|
|
}
|
|
|
|
function redemarrage_jetty_windows {
|
|
$test_jetty_init = test_jetty_win
|
|
if ($null -ne $test_jetty_init) {
|
|
Invoke-Command -ComputerName $nom_machine -ScriptBlock {Get-Service -Name *operis* |Stop-Service } |Out-Null
|
|
$test_arret_jetty = test_jetty_win
|
|
if ($test_arret_jetty.Status -like "Stopped") {
|
|
Invoke-Command -ComputerName $nom_machine -ScriptBlock {Get-Service -Name *operis* |Start-Service }
|
|
$test_reboot_jetty = test_jetty_win
|
|
if ($test_reboot_jetty.Status -like "running") {
|
|
[System.Windows.Forms.MessageBox]::Show('Redemarrage jetty réussi', 'Warning', 'ok', 'Warning')
|
|
}else {
|
|
[System.Windows.Forms.MessageBox]::Show('Echec redemarrage jetty', 'Warning', 'ok', 'Warning')
|
|
}
|
|
}else {
|
|
[System.Windows.Forms.MessageBox]::Show('Echec arret jetty', 'Warning', 'ok', 'Warning')
|
|
}
|
|
}else {
|
|
[System.Windows.Forms.MessageBox]::Show('Jetty non démarré', 'Warning', 'ok', 'Warning')
|
|
}
|
|
}
|
|
|
|
function stop_process {
|
|
Stop-Process -Id $monPID -Force
|
|
}
|
|
|
|
################################################################################################################################################
|
|
################################################################################################################################################
|
|
######################################################### Fermeture de la fenètre ##############################################################
|
|
################################################################################################################################################
|
|
################################################################################################################################################
|
|
$syncHash.Window.Add_Closing({
|
|
$_.Cancel = $true
|
|
$Resultat = [System.Windows.Forms.MessageBox]::Show("C'est fini ?", 'Warning', 'YesNo', 'Warning')
|
|
If ($Resultat -eq 'Yes')
|
|
{
|
|
$_.Cancel = $false
|
|
$syncHash.Window.Close()
|
|
stop_process
|
|
}
|
|
})
|
|
|
|
|
|
################################################################################################################################################
|
|
################################################################################################################################################
|
|
############################################## Ajout du second runspace au bouton Start ########################################################
|
|
################################################################################################################################################
|
|
################################################################################################################################################
|
|
$syncHash.BTN_Start.add_click({
|
|
###WriteToLogFile1 "clik start fait"
|
|
$syncHash.BTN_Start.IsEnabled=$false
|
|
$syncHash.BTN_Stop.IsEnabled=$true
|
|
###WriteToLogFile1 "switch bouton start/stop ok"
|
|
$global:syncHash.tests_en_cours = $true
|
|
###WriteToLogFile1 "variable test_en_cours => true"
|
|
# Déclaration du second runspace #
|
|
$MAJ_GUIRunspace =[runspacefactory]::CreateRunspace()
|
|
$MAJ_GUIRunspace.ApartmentState = "MTA"
|
|
$MAJ_GUIRunspace.ThreadOptions = "ReuseThread"
|
|
$MAJ_GUIRunspace.Open()
|
|
$MAJ_GUIRunspace.SessionStateProxy.SetVariable("syncHash",$syncHash)
|
|
###WriteToLogFile1 "ouverture runspace enfant ok"
|
|
$psScript = [PowerShell]::Create().AddScript({
|
|
# Corps du runspace
|
|
function WriteToLogFile2 ($message) {
|
|
(Get-Date).ToString() +" - "+ $message >> $global:syncHash.logfilepath
|
|
}
|
|
$MachinesXML = [xml](get-content $syncHash.Liste_vm )
|
|
$Liste_Machines = $MachinesXML.Machine.Serveur
|
|
while ($syncHash.tests_en_cours -like $true) {
|
|
$global:syncHash.Window.Dispatcher.invoke([action]{
|
|
$syncHash.Datagrid_Connexion.Items.Clear()
|
|
$syncHash.Datagrid_Connexion.Items.Refresh()
|
|
})
|
|
###$log_raz_datagrid = "RAZ Datagrid_Connexion ok"
|
|
###WriteToLogFile2 $log_raz_datagrid
|
|
###$log_lancement_boucle = "lancement boucle de test"
|
|
###WriteToLogFile2 $log_lancement_boucle
|
|
ForEach ($Machine in $Liste_Machines)
|
|
{
|
|
$Test = Get-VM -ComputerName $syncHash.serveur_vm -Name $Machine.Address
|
|
|
|
$Machine_Valeur = New-Object PSObject
|
|
$Machine_Valeur = $Machine_Valeur | Add-Member NoteProperty Serveur $Machine.Address -passthru
|
|
$Machine_Valeur = $Machine_Valeur | Add-Member NoteProperty Ip $Machine.Ip -passthru
|
|
$Machine_Valeur = $Machine_Valeur | Add-Member NoteProperty OS $Machine.OS -passthru
|
|
$Machine_Valeur = $Machine_Valeur | Add-Member NoteProperty State $Test.State -passthru
|
|
$Machine_Valeur = $Machine_Valeur | Add-Member NoteProperty BDD $Machine.BDD -passthru
|
|
$Machine_Valeur = $Machine_Valeur | Add-Member NoteProperty DDC $Machine.DDC -passthru
|
|
$Machine_Valeur = $Machine_Valeur | Add-Member NoteProperty Oxalis $Machine.Oxalis -passthru
|
|
$Machine_Valeur = $Machine_Valeur | Add-Member NoteProperty Gnau $Machine.Gnau -passthru
|
|
$Machine_Valeur = $Machine_Valeur | Add-Member NoteProperty Gnaubo $Machine.Gnaubo -passthru
|
|
$global:syncHash.Window.Dispatcher.invoke([action]{
|
|
$syncHash.Datagrid_Connexion.Items.Add($Machine_Valeur) > $null
|
|
})
|
|
}
|
|
Start-Sleep -Seconds 5
|
|
}
|
|
})
|
|
$psScript.Runspace = $MAJ_GUIRunspace
|
|
$psScript.BeginInvoke() | Out-Null
|
|
})
|
|
|
|
################################################################################################################################################
|
|
################################################################################################################################################
|
|
#################################################### Arrêt des tests de dispo VM ###############################################################
|
|
################################################################################################################################################
|
|
################################################################################################################################################
|
|
$syncHash.BTN_Stop.add_click({
|
|
$syncHash.BTN_Start.IsEnabled=$true
|
|
$syncHash.BTN_Stop.IsEnabled=$false
|
|
$global:syncHash.tests_en_cours = $false
|
|
$psScript.Runspace = $MAJ_GUIRunspace
|
|
$psScript.EndInvoke($null)
|
|
$MAJ_GUIRunspace.Close()
|
|
###WriteToLogFile1 "arrêt des tests"
|
|
})
|
|
|
|
################################################################################################################################################
|
|
################################################################################################################################################
|
|
######################################################### Reboot machine #######################################################################
|
|
################################################################################################################################################
|
|
################################################################################################################################################
|
|
$syncHash.BTN_reboot_machine.add_click({
|
|
if ($global:syncHash.Datagrid_Connexion.SelectedIndex -ne "-1")
|
|
{
|
|
foreach ($selected_item in $global:syncHash.Datagrid_Connexion.SelectedItems)
|
|
{
|
|
$nom_machine = $selected_item.Serveur
|
|
Restart-VM -ComputerName $syncHash.serveur_vm -Name $nom_machine -Force
|
|
###WriteToLogFile1 "restart $nom_machine demandé"
|
|
}
|
|
}else
|
|
{
|
|
[System.Windows.Forms.MessageBox]::Show('Aucune VM de sélectionné', 'Warning', 'ok', 'Warning')
|
|
###WriteToLogFile1 "Echec reboot vm - Aucune selection"
|
|
|
|
}
|
|
})
|
|
|
|
|
|
################################################################################################################################################
|
|
################################################################################################################################################
|
|
########################################################## Ajout machine #######################################################################
|
|
################################################################################################################################################
|
|
################################################################################################################################################
|
|
$syncHash.BTN_ajout_machine.add_click({
|
|
## début définition pop-up d'ajout machine à la liste de test ##
|
|
Add-Type -AssemblyName System.Windows.Forms
|
|
Add-Type -AssemblyName System.Drawing
|
|
|
|
$form_ajout_vm = New-Object System.Windows.Forms.Form
|
|
$form_ajout_vm.Text = "Ajout VM - Support"
|
|
$form_ajout_vm.Size = New-Object System.Drawing.Size(310,370)
|
|
$form_ajout_vm.StartPosition = "CenterScreen"
|
|
|
|
$label = New-Object System.Windows.Forms.Label
|
|
$label.Location = New-Object System.Drawing.Point(15,15)
|
|
$label.Size = New-Object System.Drawing.Size(290,20)
|
|
$label.Font = [System.Drawing.Font]::new("Arial", 11, [System.Drawing.FontStyle]::Bold)
|
|
$label.Text = "Merci de préciser le pédigré de la Bête"
|
|
$form_ajout_vm.Controls.Add($label)
|
|
|
|
$label_nom_vm = New-Object System.Windows.Forms.Label
|
|
$label_nom_vm.Location = New-Object System.Drawing.Point(10,49)
|
|
$label_nom_vm.Size = New-Object System.Drawing.Size(96,23)
|
|
$label_nom_vm.Text = "Nom de la VM : "
|
|
$form_ajout_vm.Controls.Add($label_nom_vm)
|
|
$textbox_nom_vm = New-Object System.Windows.Forms.TextBox
|
|
$textbox_nom_vm.Location = New-Object System.Drawing.Point(111,49)
|
|
$textbox_nom_vm.Size = New-Object System.Drawing.Size(171,23)
|
|
$textbox_nom_vm.Text = "SRV-VRM-XXX-XXX"
|
|
$form_ajout_vm.Controls.Add($textbox_nom_vm)
|
|
|
|
$label_IP_vm = New-Object System.Windows.Forms.Label
|
|
$label_IP_vm.Location = New-Object System.Drawing.Point(10,78)
|
|
$label_IP_vm.Size = New-Object System.Drawing.Size(96,23)
|
|
$label_IP_vm.Text = "IP de la VM : "
|
|
$form_ajout_vm.Controls.Add($label_IP_vm)
|
|
$textbox_IP_vm = New-Object System.Windows.Forms.TextBox
|
|
$textbox_IP_vm.Location = New-Object System.Drawing.Point(111,78)
|
|
$textbox_IP_vm.Size = New-Object System.Drawing.Size(171,23)
|
|
$textbox_IP_vm.Text = "XXX.XXX.XXX.XXX"
|
|
$form_ajout_vm.Controls.Add($textbox_IP_vm)
|
|
|
|
$label_OS_vm = New-Object System.Windows.Forms.Label
|
|
$label_OS_vm.Location = New-Object System.Drawing.Point(10,106)
|
|
$label_OS_vm.Size = New-Object System.Drawing.Size(96,23)
|
|
$label_OS_vm.Text = "OS de la VM : "
|
|
$form_ajout_vm.Controls.Add($label_OS_vm)
|
|
$combobox_os_vm = New-Object System.Windows.Forms.ComboBox
|
|
$combobox_os_vm.Location = New-Object System.Drawing.Point(111,106)
|
|
$combobox_os_vm.Size = New-Object System.Drawing.Size(171,23)
|
|
$combobox_os_vm.Items.Add("Debian 12")
|
|
$combobox_os_vm.Items.Add("Windows Server 2022")
|
|
$combobox_os_vm.Items.Add("Oracle-linux 8.8")
|
|
$form_ajout_vm.Controls.Add($combobox_os_vm)
|
|
|
|
$label_BDD_vm = New-Object System.Windows.Forms.Label
|
|
$label_BDD_vm.Location = New-Object System.Drawing.Point(10,134)
|
|
$label_BDD_vm.Size = New-Object System.Drawing.Size(130,23)
|
|
$label_BDD_vm.Text = "Type de BDD : "
|
|
$form_ajout_vm.Controls.Add($label_BDD_vm)
|
|
$combobox_BDD_vm = New-Object System.Windows.Forms.ComboBox
|
|
$combobox_BDD_vm.Location = New-Object System.Drawing.Point(146,134)
|
|
$combobox_BDD_vm.Size = New-Object System.Drawing.Size(136,23)
|
|
$combobox_BDD_vm.Items.Add("Oracle 21 xe")
|
|
$combobox_BDD_vm.Items.Add("Postgres 13")
|
|
$combobox_BDD_vm.Items.Add("N.A")
|
|
$combobox_BDD_vm.selection("")
|
|
$form_ajout_vm.Controls.Add($combobox_BDD_vm)
|
|
|
|
$label_DDC_vm = New-Object System.Windows.Forms.Label
|
|
$label_DDC_vm.Location = New-Object System.Drawing.Point(10,162)
|
|
$label_DDC_vm.Size = New-Object System.Drawing.Size(130,23)
|
|
$label_DDC_vm.Text = "DDC installé?"
|
|
$form_ajout_vm.Controls.Add($label_DDC_vm)
|
|
$combobox_DDC_vm = New-Object System.Windows.Forms.ComboBox
|
|
$combobox_DDC_vm.Location = New-Object System.Drawing.Point(146,162)
|
|
$combobox_DDC_vm.Size = New-Object System.Drawing.Size(136,23)
|
|
$combobox_DDC_vm.Items.Add("oui")
|
|
$combobox_DDC_vm.Items.Add("non")
|
|
$form_ajout_vm.Controls.Add($combobox_DDC_vm)
|
|
|
|
$label_Oxalis_vm = New-Object System.Windows.Forms.Label
|
|
$label_Oxalis_vm.Location = New-Object System.Drawing.Point(10,190)
|
|
$label_Oxalis_vm.Size = New-Object System.Drawing.Size(130,23)
|
|
$label_Oxalis_vm.Text = "Oxalis installé?"
|
|
$form_ajout_vm.Controls.Add($label_Oxalis_vm)
|
|
$combobox_Oxalis_vm = New-Object System.Windows.Forms.ComboBox
|
|
$combobox_Oxalis_vm.Location = New-Object System.Drawing.Point(146,190)
|
|
$combobox_Oxalis_vm.Size = New-Object System.Drawing.Size(136,23)
|
|
$combobox_Oxalis_vm.Items.Add("oui")
|
|
$combobox_Oxalis_vm.Items.Add("non")
|
|
$form_ajout_vm.Controls.Add($combobox_Oxalis_vm)
|
|
|
|
$label_GNAU_vm = New-Object System.Windows.Forms.Label
|
|
$label_GNAU_vm.Location = New-Object System.Drawing.Point(10,218)
|
|
$label_GNAU_vm.Size = New-Object System.Drawing.Size(130,23)
|
|
$label_GNAU_vm.Text = "GNAU installé?"
|
|
$form_ajout_vm.Controls.Add($label_GNAU_vm)
|
|
$combobox_GNAU_vm = New-Object System.Windows.Forms.ComboBox
|
|
$combobox_GNAU_vm.Location = New-Object System.Drawing.Point(146,218)
|
|
$combobox_GNAU_vm.Size = New-Object System.Drawing.Size(136,23)
|
|
$combobox_GNAU_vm.Items.Add("oui")
|
|
$combobox_GNAU_vm.Items.Add("non")
|
|
$form_ajout_vm.Controls.Add($combobox_GNAU_vm)
|
|
|
|
$label_GNAUBO_vm = New-Object System.Windows.Forms.Label
|
|
$label_GNAUBO_vm.Location = New-Object System.Drawing.Point(10,246)
|
|
$label_GNAUBO_vm.Size = New-Object System.Drawing.Size(130,23)
|
|
$label_GNAUBO_vm.Text = "GNAUBO installé?"
|
|
$form_ajout_vm.Controls.Add($label_GNAUBO_vm)
|
|
$combobox_GNAUBO_vm = New-Object System.Windows.Forms.ComboBox
|
|
$combobox_GNAUBO_vm.Location = New-Object System.Drawing.Point(146,246)
|
|
$combobox_GNAUBO_vm.Size = New-Object System.Drawing.Size(136,23)
|
|
$combobox_GNAUBO_vm.Items.Add("oui")
|
|
$combobox_GNAUBO_vm.Items.Add("non")
|
|
$form_ajout_vm.Controls.Add($combobox_GNAUBO_vm)
|
|
|
|
$boutton_ajout_vm = New-Object System.Windows.Forms.Button
|
|
$boutton_ajout_vm.Location = New-Object System.Drawing.Point(10,285)
|
|
$boutton_ajout_vm.Size = New-Object System.Drawing.Size(130,23)
|
|
$boutton_ajout_vm.Text = "Ajouter à la liste"
|
|
$boutton_ajout_vm.DialogResult = [System.Windows.Forms.DialogResult]::OK
|
|
$form_ajout_vm.AcceptButton = $boutton_ajout_vm
|
|
$form_ajout_vm.Controls.Add($boutton_ajout_vm)
|
|
|
|
$boutton_annuler = New-Object System.Windows.Forms.Button
|
|
$boutton_annuler.Location = New-Object System.Drawing.Point(152,285)
|
|
$boutton_annuler.Size = New-Object System.Drawing.Size(130,23)
|
|
$boutton_annuler.Text = "Annuler"
|
|
$boutton_annuler.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
|
|
$form_ajout_vm.AcceptButton = $boutton_annuler
|
|
$form_ajout_vm.Controls.Add($boutton_annuler)
|
|
|
|
$form_ajout_vm.Topmost = $True
|
|
|
|
$result = $form_ajout_vm.ShowDialog()
|
|
## fin définition pop-up d'ajout machine à la liste de test ##
|
|
if ($result -eq [System.Windows.Forms.DialogResult]::OK)
|
|
{
|
|
$Address_new_vm = $textbox_nom_vm.Text
|
|
$IP_new_vm = $textbox_IP_vm.Text
|
|
$OS_new_vm = $combobox_os_vm.SelectedItem
|
|
$BDD_new_vm = $combobox_BDD_vm.SelectedItem
|
|
$DDC_new_vm = $combobox_DDC_vm.SelectedItem
|
|
$Oxalis_new_vm = $combobox_Oxalis_vm.SelectedItem
|
|
$GNAU_new_vm = $combobox_GNAU_vm.SelectedItem
|
|
$GNAUBO_new_vm = $combobox_GNAUBO_vm.SelectedItem
|
|
|
|
[xml]$listing_vm = Get-Content $syncHash.Liste_vm
|
|
$nouvelle_vm=$listing_vm.Machine.AppendChild($listing_vm.CreateElement("Serveur")); #=> création du noeud "Serveur"
|
|
|
|
$Address_vm = $nouvelle_vm.AppendChild($listing_vm.CreateElement("Address")); #=> création de l'élément Address
|
|
$Address_vm_Value = $Address_vm.AppendChild($listing_vm.CreateTextNode($Address_new_vm)); #=> ajout de l'information liée à l'adresse
|
|
$IP_vm = $nouvelle_vm.AppendChild($listing_vm.CreateElement("Ip"));
|
|
$IP_vm_Value = $IP_vm.AppendChild($listing_vm.CreateTextNode($IP_new_vm));
|
|
$OS_vm = $nouvelle_vm.AppendChild($listing_vm.CreateElement("OS"));
|
|
$OS_vm_Value = $OS_vm.AppendChild($listing_vm.CreateTextNode($OS_new_vm));
|
|
$BDD_vm= $nouvelle_vm.AppendChild($listing_vm.CreateElement("BDD"));
|
|
$BDD_vm_Value = $BDD_vm.AppendChild($listing_vm.CreateTextNode($BDD_new_vm));
|
|
$DDC_vm = $nouvelle_vm.AppendChild($listing_vm.CreateElement("DDC"));
|
|
$DDC_vm_Value = $DDC_vm.AppendChild($listing_vm.CreateTextNode($DDC_new_vm));
|
|
$Oxalis_vm = $nouvelle_vm.AppendChild($listing_vm.CreateElement("oxalis"));
|
|
$Oxalis_vm_Value = $Oxalis_vm.AppendChild($listing_vm.CreateTextNode($Oxalis_new_vm));
|
|
$GNAU_vm = $nouvelle_vm.AppendChild($listing_vm.CreateElement("gnau"));
|
|
$GNAU_vm_Value = $GNAU_vm.AppendChild($listing_vm.CreateTextNode($GNAU_new_vm));
|
|
$GNAUBO_vm = $nouvelle_vm.AppendChild($listing_vm.CreateElement("gnaubo"));
|
|
$GNAUBO_vm_Value = $GNAUBO_vm.AppendChild($listing_vm.CreateTextNode($GNAUBO_new_vm));
|
|
$nouvelle_vm.setattribute("Serveur",$Address_new_vm)
|
|
|
|
$listing_vm.Save($syncHash.Liste_vm) #=> enregistrement nouvelle vm
|
|
[System.Windows.Forms.MessageBox]::Show("Nouvelle VM ajoutée à la liste des machines à tester. Pour créer la machine dans la vrai vie véritable, connecter vous à l'hyper-v sur le serveur correspondant. Si tu le connais, pas, va voir l'infra!", 'Warning', 'ok', 'Warning')
|
|
###WriteToLogFile1 "création vm $Address_vm faite"
|
|
}
|
|
else
|
|
{
|
|
[System.Windows.Forms.MessageBox]::Show('Ajout nouvelle VM annulé', 'Warning', 'ok', 'Warning')
|
|
###WriteToLogFile1 "création vm annulée"
|
|
}
|
|
})
|
|
|
|
|
|
################################################################################################################################################
|
|
################################################################################################################################################
|
|
######################################################## Démarrer machine ######################################################################
|
|
################################################################################################################################################
|
|
################################################################################################################################################
|
|
$syncHash.BTN_Start_machine.add_click({
|
|
if ($global:syncHash.Datagrid_Connexion.SelectedIndex -ne "-1")
|
|
{
|
|
foreach ($selected_item in $global:syncHash.Datagrid_Connexion.SelectedItems)
|
|
{
|
|
$nom_machine = $selected_item.Serveur
|
|
}
|
|
## début définition pop-up de démarrage Machine ##
|
|
Add-Type -AssemblyName System.Windows.Forms
|
|
Add-Type -AssemblyName System.Drawing
|
|
|
|
$form = New-Object System.Windows.Forms.Form
|
|
$form.Text = "Démarrage VM - Support"
|
|
$form.Size = New-Object System.Drawing.Size(300,150)
|
|
$form.StartPosition = "CenterScreen"
|
|
|
|
$OKButton = New-Object System.Windows.Forms.Button
|
|
$OKButton.Location = New-Object System.Drawing.Point(70,60)
|
|
$OKButton.Size = New-Object System.Drawing.Size(75,23)
|
|
$OKButton.Text = "OK"
|
|
$OKButton.DialogResult = [System.Windows.Forms.DialogResult]::OK
|
|
$form.AcceptButton = $OKButton
|
|
$form.Controls.Add($OKButton)
|
|
|
|
$CancelButton = New-Object System.Windows.Forms.Button
|
|
$CancelButton.Location = New-Object System.Drawing.Point(155,60)
|
|
$CancelButton.Size = New-Object System.Drawing.Size(75,23)
|
|
$CancelButton.Text = "Cancel"
|
|
$CancelButton.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
|
|
$form.CancelButton = $CancelButton
|
|
$form.Controls.Add($CancelButton)
|
|
|
|
$label = New-Object System.Windows.Forms.Label
|
|
$label.Location = New-Object System.Drawing.Point(10,20)
|
|
$label.Size = New-Object System.Drawing.Size(280,20)
|
|
$label.Text = "Démarrage VM: $nom_machine"
|
|
$form.Controls.Add($label)
|
|
|
|
$form.Topmost = $True
|
|
|
|
$result = $form.ShowDialog()
|
|
## fin définition pop-up de démarrage Machine ##
|
|
if ($result -eq [System.Windows.Forms.DialogResult]::OK)
|
|
{
|
|
Start-VM -computername $syncHash.serveur_vm -name $nom_machine -Confirm:$false -AsJob
|
|
###WriteToLogFile1 "demande démarrage VM $nom_machine"
|
|
}
|
|
}else
|
|
{
|
|
[System.Windows.Forms.MessageBox]::Show('Aucune VM de sélectionné', 'Warning', 'ok', 'Warning')
|
|
###WriteToLogFile1 "Echec démarrage VM - Aucune VM séléctionnée"
|
|
}
|
|
})
|
|
|
|
|
|
################################################################################################################################################
|
|
################################################################################################################################################
|
|
########################################################## Arrêt machine #######################################################################
|
|
################################################################################################################################################
|
|
################################################################################################################################################
|
|
$syncHash.BTN_shutdown_machine.add_click({
|
|
if ($global:syncHash.Datagrid_Connexion.SelectedIndex -ne "-1")
|
|
{
|
|
foreach ($selected_item in $global:syncHash.Datagrid_Connexion.SelectedItems)
|
|
{
|
|
$nom_machine = $selected_item.Serveur
|
|
}
|
|
## début définition pop-up d'arrêt Machine ##
|
|
Add-Type -AssemblyName System.Windows.Forms
|
|
Add-Type -AssemblyName System.Drawing
|
|
|
|
$form = New-Object System.Windows.Forms.Form
|
|
$form.Text = "Arrêt VM - Support"
|
|
$form.Size = New-Object System.Drawing.Size(300,150)
|
|
$form.StartPosition = "CenterScreen"
|
|
|
|
$OKButton = New-Object System.Windows.Forms.Button
|
|
$OKButton.Location = New-Object System.Drawing.Point(70,60)
|
|
$OKButton.Size = New-Object System.Drawing.Size(75,23)
|
|
$OKButton.Text = "OK"
|
|
$OKButton.DialogResult = [System.Windows.Forms.DialogResult]::OK
|
|
$form.AcceptButton = $OKButton
|
|
$form.Controls.Add($OKButton)
|
|
|
|
$CancelButton = New-Object System.Windows.Forms.Button
|
|
$CancelButton.Location = New-Object System.Drawing.Point(155,60)
|
|
$CancelButton.Size = New-Object System.Drawing.Size(75,23)
|
|
$CancelButton.Text = "Cancel"
|
|
$CancelButton.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
|
|
$form.CancelButton = $CancelButton
|
|
$form.Controls.Add($CancelButton)
|
|
|
|
$label = New-Object System.Windows.Forms.Label
|
|
$label.Location = New-Object System.Drawing.Point(10,20)
|
|
$label.Size = New-Object System.Drawing.Size(280,20)
|
|
$label.Text = "Arrêt de la VM $nom_machine ?"
|
|
$form.Controls.Add($label)
|
|
|
|
$form.Topmost = $True
|
|
|
|
$result = $form.ShowDialog()
|
|
## fin définition pop-up d'arrêt Machine ##
|
|
if ($result -eq [System.Windows.Forms.DialogResult]::OK)
|
|
{
|
|
Stop-VM -computername $syncHash.serveur_vm -name $nom_machine -Force
|
|
###WriteToLogFile1 "demande d'arrèts VM $nom_machine"
|
|
}
|
|
}else
|
|
{
|
|
[System.Windows.Forms.MessageBox]::Show('Aucune VM de sélectionné', 'Warning', 'ok', 'Warning')
|
|
###WriteToLogFile1 "Echec arrêt VM - Aucune VM séléctionnée"
|
|
}
|
|
})
|
|
|
|
|
|
################################################################################################################################################
|
|
################################################################################################################################################
|
|
######################################################### Renommer machine #####################################################################
|
|
################################################################################################################################################
|
|
################################################################################################################################################
|
|
$syncHash.BTN_rename_machine.add_click({
|
|
if ($global:syncHash.Datagrid_Connexion.SelectedIndex -ne "-1")
|
|
{
|
|
foreach ($selected_item in $global:syncHash.Datagrid_Connexion.SelectedItems)
|
|
{
|
|
$nom_machine = $selected_item.Serveur
|
|
}
|
|
## début définition pop-up de renommage Machine ##
|
|
Add-Type -AssemblyName System.Windows.Forms
|
|
Add-Type -AssemblyName System.Drawing
|
|
|
|
$form = New-Object System.Windows.Forms.Form
|
|
$form.Text = "Ajouter VM - Support"
|
|
$form.Size = New-Object System.Drawing.Size(300,200)
|
|
$form.StartPosition = "CenterScreen"
|
|
|
|
$OKButton = New-Object System.Windows.Forms.Button
|
|
$OKButton.Location = New-Object System.Drawing.Point(75,120)
|
|
$OKButton.Size = New-Object System.Drawing.Size(75,23)
|
|
$OKButton.Text = "OK"
|
|
$OKButton.DialogResult = [System.Windows.Forms.DialogResult]::OK
|
|
$form.AcceptButton = $OKButton
|
|
$form.Controls.Add($OKButton)
|
|
|
|
$CancelButton = New-Object System.Windows.Forms.Button
|
|
$CancelButton.Location = New-Object System.Drawing.Point(150,120)
|
|
$CancelButton.Size = New-Object System.Drawing.Size(75,23)
|
|
$CancelButton.Text = "Cancel"
|
|
$CancelButton.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
|
|
$form.CancelButton = $CancelButton
|
|
$form.Controls.Add($CancelButton)
|
|
|
|
$label = New-Object System.Windows.Forms.Label
|
|
$label.Location = New-Object System.Drawing.Point(10,20)
|
|
$label.Size = New-Object System.Drawing.Size(280,20)
|
|
$label.Text = "Saisir le nouveau nom de la VM:"
|
|
$form.Controls.Add($label)
|
|
|
|
$new_name_vm = New-Object System.Windows.Forms.TextBox
|
|
$new_name_vm.Location = New-Object System.Drawing.Point(10,40)
|
|
$new_name_vm.Size = New-Object System.Drawing.Size(260,20)
|
|
$form.Controls.Add($new_name_vm)
|
|
|
|
$form.Topmost = $True
|
|
|
|
$form.Add_Shown({$new_name_vm.Select()})
|
|
$result = $form.ShowDialog()
|
|
## fin définition pop-up de renommage Machine ##
|
|
if ($result -eq [System.Windows.Forms.DialogResult]::OK)
|
|
{
|
|
$NewNamevm = $new_name_vm.Text
|
|
Rename-VM -computername $syncHash.serveur_vm -name $nom_machine -NewName $NewNamevm
|
|
# Chargement du fichier XML
|
|
[xml] $MaJ_Liste_vm = (Get-Content -Path $syncHash.Liste_vm)
|
|
# Mise à jour des valeurs dans le liste_vm.xml
|
|
$VM_modifiee = $MaJ_Liste_vm.SelectNodes("//Serveur") | where {$PSItem.Nom -eq $nom_machine} #=> on se place sur le noeud du serveur renommé
|
|
$VM_modifiee.Nom = $NewNamevm
|
|
$VM_modifiee.Address = $NewNamevm
|
|
# Sauvegarde des modifications dans le fichier XML
|
|
$MaJ_Liste_vm.Save($syncHash.Liste_vm)
|
|
###WriteToLogFile1 "mise à jour de la liste des VM - modification $nom_machine => $NewNamevm"
|
|
}
|
|
}
|
|
else
|
|
{
|
|
[System.Windows.Forms.MessageBox]::Show('Aucune VM de sélectionné', 'Warning', 'ok', 'Warning')
|
|
###WriteToLogFile1 "Echec rennommage VM - Aucune VM sélectionnée"
|
|
}
|
|
})
|
|
|
|
################################################################################################################################################
|
|
################################################################################################################################################
|
|
######################################################### Supprimmer machine ###################################################################
|
|
################################################################################################################################################
|
|
################################################################################################################################################
|
|
$syncHash.BTN_Remove_machine.add_click({
|
|
if ($global:syncHash.Datagrid_Connexion.SelectedIndex -ne "-1")
|
|
{
|
|
foreach ($selected_item in $global:syncHash.Datagrid_Connexion.SelectedItems)
|
|
{
|
|
$nom_machine = $selected_item.Serveur
|
|
}
|
|
## début définition pop-up de suppression machine ##
|
|
Add-Type -AssemblyName System.Windows.Forms
|
|
Add-Type -AssemblyName System.Drawing
|
|
|
|
$form_Remove_machine = New-Object System.Windows.Forms.Form
|
|
$form_Remove_machine.Text = "Suprimmer VM - Support"
|
|
$form_Remove_machine.Size = New-Object System.Drawing.Size(280,130)
|
|
$form_Remove_machine.StartPosition = "CenterScreen"
|
|
|
|
$OKButton = New-Object System.Windows.Forms.Button
|
|
$OKButton.Location = New-Object System.Drawing.Point(55,55)
|
|
$OKButton.Size = New-Object System.Drawing.Size(75,23)
|
|
$OKButton.Text = "OK"
|
|
$OKButton.DialogResult = [System.Windows.Forms.DialogResult]::OK
|
|
$form_Remove_machine.AcceptButton = $OKButton
|
|
$form_Remove_machine.Controls.Add($OKButton)
|
|
|
|
$CancelButton = New-Object System.Windows.Forms.Button
|
|
$CancelButton.Location = New-Object System.Drawing.Point(140,55)
|
|
$CancelButton.Size = New-Object System.Drawing.Size(75,23)
|
|
$CancelButton.Text = "Cancel"
|
|
$CancelButton.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
|
|
$form_Remove_machine.CancelButton = $CancelButton
|
|
$form_Remove_machine.Controls.Add($CancelButton)
|
|
|
|
$label = New-Object System.Windows.Forms.Label
|
|
$label.Location = New-Object System.Drawing.Point(10,20)
|
|
$label.Size = New-Object System.Drawing.Size(280,20)
|
|
$label.Text = "Suppression VM: $nom_machine"
|
|
$form_Remove_machine.Controls.Add($label)
|
|
|
|
$form_Remove_machine.Topmost = $True
|
|
|
|
$result = $form_Remove_machine.ShowDialog()
|
|
## fin définition pop-up de suppression machine ##
|
|
if ($result -eq [System.Windows.Forms.DialogResult]::OK)
|
|
{
|
|
Remove-VM -computername $syncHash.serveur_vm -Name $nom_machine -Force
|
|
suppression_VM_dans_list
|
|
###WriteToLogFile1 "VM $nom_machine supprimée de la listevm.xml et de l'hyper-v"
|
|
}
|
|
}
|
|
else
|
|
{
|
|
[System.Windows.Forms.MessageBox]::Show('Aucune VM de sélectionné', 'Warning', 'ok', 'Warning')
|
|
###WriteToLogFile1 "Echec suppression VM - Aucune vm de sélectionnée"
|
|
}
|
|
})
|
|
|
|
|
|
################################################################################################################################################
|
|
################################################################################################################################################
|
|
######################################################## Redemarrage Service ###################################################################
|
|
################################################################################################################################################
|
|
################################################################################################################################################
|
|
$syncHash.BTN_Reboot_service.add_click({
|
|
if ($global:syncHash.Datagrid_Connexion.SelectedIndex -ne "-1")
|
|
{
|
|
foreach ($selected_item in $global:syncHash.Datagrid_Connexion.SelectedItems)
|
|
{
|
|
$nom_machine = $selected_item.Serveur
|
|
###WriteToLogFile1 "Demande redémarrage jetty sur le serveur : $nom_machine"
|
|
$OS_machine = $selected_item.OS
|
|
###WriteToLogFile1 "OS du serveur sélectionné: $OS_machine"
|
|
|
|
}
|
|
## début définition pop-up de suppression machine ##
|
|
Add-Type -AssemblyName System.Windows.Forms
|
|
Add-Type -AssemblyName System.Drawing
|
|
|
|
$form_Remove_machine = New-Object System.Windows.Forms.Form
|
|
$form_Remove_machine.Text = "reboot service vm - Support"
|
|
$form_Remove_machine.Size = New-Object System.Drawing.Size(370,140)
|
|
$form_Remove_machine.StartPosition = "CenterScreen"
|
|
|
|
$OKButton = New-Object System.Windows.Forms.Button
|
|
$OKButton.Location = New-Object System.Drawing.Point(105,70)
|
|
$OKButton.Size = New-Object System.Drawing.Size(75,23)
|
|
$OKButton.Text = "OK"
|
|
$OKButton.DialogResult = [System.Windows.Forms.DialogResult]::OK
|
|
$form_Remove_machine.AcceptButton = $OKButton
|
|
$form_Remove_machine.Controls.Add($OKButton)
|
|
|
|
$CancelButton = New-Object System.Windows.Forms.Button
|
|
$CancelButton.Location = New-Object System.Drawing.Point(190,70)
|
|
$CancelButton.Size = New-Object System.Drawing.Size(75,23)
|
|
$CancelButton.Text = "Cancel"
|
|
$CancelButton.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
|
|
$form_Remove_machine.CancelButton = $CancelButton
|
|
$form_Remove_machine.Controls.Add($CancelButton)
|
|
|
|
$label = New-Object System.Windows.Forms.Label
|
|
$label.Location = New-Object System.Drawing.Point(10,20)
|
|
$label.Size = New-Object System.Drawing.Size(360,20)
|
|
$label.Text = "Redémarrage service jetty (java) de la VM $nom_machine ?"
|
|
$form_Remove_machine.Controls.Add($label)
|
|
|
|
$form_Remove_machine.Topmost = $True
|
|
|
|
$result = $form_Remove_machine.ShowDialog()
|
|
## fin définition pop-up de suppression machine ##
|
|
if ($result -eq [System.Windows.Forms.DialogResult]::OK)
|
|
{
|
|
if ($OS_machine -like "Debian 12") {
|
|
redemarrage_jetty_debian
|
|
}elseif ($OS_machine -like "Windows Server 2022") {
|
|
redemarrage_jetty_windows
|
|
}elseif ($OS_machine -like "Oracle-linux 8.8") {
|
|
[System.Windows.Forms.MessageBox]::Show('Service Jetty pas installé sur la VM Sélectionnée', 'Warning', 'ok', 'Warning')
|
|
}
|
|
###WriteToLogFile1 "redémarrage Service Jetty demandée sur la VM $nom_machine"
|
|
}
|
|
}
|
|
else
|
|
{
|
|
[System.Windows.Forms.MessageBox]::Show('Aucune VM de sélectionné', 'Warning', 'ok', 'Warning')
|
|
###WriteToLogFile1 "Echec redémarrage Service Jetty - Acune VM sélectionnée"
|
|
}
|
|
})
|
|
|
|
|
|
################################################################################################################################################
|
|
################################################################################################################################################
|
|
################################################### Récupération liste Snapshot VM #############################################################
|
|
################################################################################################################################################
|
|
################################################################################################################################################
|
|
$syncHash.BTN_list_snap.add_click({
|
|
###WriteToLogFile1 "click BTN_list_snap ok"
|
|
$syncHash.Datagrid_Snapshot.Items.Clear() #=> vidange du datagrid avant chaque requète
|
|
$syncHash.Datagrid_Snapshot.Items.Refresh() #=> vidange du datagrid avant chaque requète
|
|
###WriteToLogFile1 "Vidange Datagrid_Snapshot ok"
|
|
if ($syncHash.Datagrid_Connexion.SelectedIndex -ne "-1")
|
|
{
|
|
###WriteToLogFile1 "Récupération liste Snapshot demandée"
|
|
refresh_liste_snapshot
|
|
}else
|
|
{
|
|
[System.Windows.Forms.MessageBox]::Show('Aucune VM de sélectionné', 'Warning', 'ok', 'Warning')
|
|
###WriteToLogFile1 "Echec relevé de snapshot - Aucune VM Sélectionnée"
|
|
}
|
|
})
|
|
|
|
|
|
################################################################################################################################################
|
|
################################################################################################################################################
|
|
########################################################### Faire Snapshot #####################################################################
|
|
################################################################################################################################################
|
|
################################################################################################################################################
|
|
$syncHash.BTN_faire_snap.add_click({
|
|
if ($global:syncHash.Datagrid_Connexion.SelectedItems -ne "-1")
|
|
{
|
|
$nom_machine = $global:syncHash.Datagrid_Connexion.SelectedItems.Serveur
|
|
###WriteToLogFile1 "serveur séléctionné : $nom_machine"
|
|
$list_snap = Get-VMSnapshot -ComputerName $syncHash.serveur_vm -VMName $nom_machine | Select-Object -Property CreationTime,Name,VMName
|
|
$nbr_snap = $list_snap.Count
|
|
###WriteToLogFile1 "$nbr_snap snap sur la vm $nom_machine"
|
|
if ($nbr_snap -lt 2 ) #=> check du nombre max de snapshots
|
|
{
|
|
foreach ($selected_item in $global:syncHash.Datagrid_Connexion.SelectedItems)
|
|
{
|
|
$nom_machine = $selected_item.Serveur
|
|
$nom_Snap = $snapshot.nom_snapshot
|
|
$VM_Snap = $snapshot.VM_snapshot
|
|
## début définition pop-up de création Snapshot ##
|
|
Add-Type -AssemblyName System.Windows.Forms
|
|
Add-Type -AssemblyName System.Drawing
|
|
|
|
$form_create_snap = New-Object System.Windows.Forms.Form
|
|
$form_create_snap.Text = "Création d'un Snapshot - Support"
|
|
$form_create_snap.Size = New-Object System.Drawing.Size(360,150)
|
|
$form_create_snap.StartPosition = "CenterScreen"
|
|
|
|
$OKButton = New-Object System.Windows.Forms.Button
|
|
$OKButton.Location = New-Object System.Drawing.Point(95,80)
|
|
$OKButton.Size = New-Object System.Drawing.Size(75,23)
|
|
$OKButton.Text = "OK"
|
|
$OKButton.DialogResult = [System.Windows.Forms.DialogResult]::OK
|
|
$form_create_snap.AcceptButton = $OKButton
|
|
$form_create_snap.Controls.Add($OKButton)
|
|
|
|
$CancelButton = New-Object System.Windows.Forms.Button
|
|
$CancelButton.Location = New-Object System.Drawing.Point(175,80)
|
|
$CancelButton.Size = New-Object System.Drawing.Size(75,23)
|
|
$CancelButton.Text = "Cancel"
|
|
$CancelButton.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
|
|
$form_create_snap.CancelButton = $CancelButton
|
|
$form_create_snap.Controls.Add($CancelButton)
|
|
|
|
$label = New-Object System.Windows.Forms.Label
|
|
$label.Location = New-Object System.Drawing.Point(5,20)
|
|
$label.Size = New-Object System.Drawing.Size(350,20)
|
|
$label.Text = "Nom du nouveau Snapshot pour la VM $nom_machine :"
|
|
$form_create_snap.Controls.Add($label)
|
|
|
|
$new_snap = New-Object System.Windows.Forms.TextBox
|
|
$new_snap.Location = New-Object System.Drawing.Point(10,50)
|
|
$new_snap.Size = New-Object System.Drawing.Size(320,20)
|
|
$form_create_snap.Controls.Add($new_snap)
|
|
|
|
$form_create_snap.Topmost = $True
|
|
$result = $form_create_snap.ShowDialog()
|
|
## fin définition pop-up de création Snapshot ##
|
|
if ($result -eq [System.Windows.Forms.DialogResult]::OK)
|
|
{
|
|
$newsnap = $new_snap.Text
|
|
###WriteToLogFile1 "demande de nouveau snap faite sur la vm $nom_machine : $newsnap"
|
|
Checkpoint-VM -computername $syncHash.serveur_vm -SnapshotName $newsnap -Name $nom_machine -Confirm:$false
|
|
refresh_liste_snapshot
|
|
}
|
|
}
|
|
}else {
|
|
[System.Windows.Forms.MessageBox]::Show('Ohh le petit gourmand!! Seulement 2 snaps autorisés! Supprime en un avant de faire un nouveau snapshot', 'Warning', 'ok', 'Warning')
|
|
###WriteToLogFile1 "Echec de réalisation de Snapshot sur la vm $nom_machine : trop de snapshot (2max) => $nbr_snap"
|
|
}
|
|
}else
|
|
{
|
|
[System.Windows.Forms.MessageBox]::Show('Aucun Snapshot de sélectionné!', 'Warning', 'ok', 'Warning')
|
|
###WriteToLogFile1 "Echec de réalisation de Snapshot - Aucune vm sélectionnée"
|
|
}
|
|
})
|
|
|
|
|
|
################################################################################################################################################
|
|
################################################################################################################################################
|
|
######################################################### Restaurer Snapshot ####################################################################
|
|
################################################################################################################################################
|
|
################################################################################################################################################
|
|
$syncHash.BTN_restore_snap.add_click({
|
|
if ($global:syncHash.Datagrid_Snapshot.SelectedItems -ne "-1")
|
|
{
|
|
foreach ($snapshot in $global:syncHash.Datagrid_Snapshot.SelectedItems)
|
|
{
|
|
$nom_Snap = $snapshot.nom_snapshot
|
|
$date_Snap = $snapshot.date_snapshot
|
|
$VM_Snap = $snapshot.VM_snapshot
|
|
## début définition pop-up de restauration Snapshot ##
|
|
Add-Type -AssemblyName System.Windows.Forms
|
|
Add-Type -AssemblyName System.Drawing
|
|
|
|
$form_restore_snap = New-Object System.Windows.Forms.Form
|
|
$form_restore_snap.Text = "Retourner à un Snapshot - Support"
|
|
$form_restore_snap.Size = New-Object System.Drawing.Size(400,150)
|
|
$form_restore_snap.StartPosition = "CenterScreen"
|
|
|
|
$OKButton = New-Object System.Windows.Forms.Button
|
|
$OKButton.Location = New-Object System.Drawing.Point(115,70)
|
|
$OKButton.Size = New-Object System.Drawing.Size(75,23)
|
|
$OKButton.Text = "OK"
|
|
$OKButton.DialogResult = [System.Windows.Forms.DialogResult]::OK
|
|
$form_restore_snap.AcceptButton = $OKButton
|
|
$form_restore_snap.Controls.Add($OKButton)
|
|
|
|
$CancelButton = New-Object System.Windows.Forms.Button
|
|
$CancelButton.Location = New-Object System.Drawing.Point(210,70)
|
|
$CancelButton.Size = New-Object System.Drawing.Size(75,23)
|
|
$CancelButton.Text = "Cancel"
|
|
$CancelButton.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
|
|
$form_restore_snap.CancelButton = $CancelButton
|
|
$form_restore_snap.Controls.Add($CancelButton)
|
|
|
|
$label1 = New-Object System.Windows.Forms.Label
|
|
$label1.Location = New-Object System.Drawing.Point(10,15)
|
|
$label1.Size = New-Object System.Drawing.Size(380,20)
|
|
$label1.Text = "Retour au Snapshot: $nom_Snap"
|
|
$form_restore_snap.Controls.Add($label1)
|
|
|
|
$label2 = New-Object System.Windows.Forms.Label
|
|
$label2.Location = New-Object System.Drawing.Point(10,40)
|
|
$label2.Size = New-Object System.Drawing.Size(380,20)
|
|
$label2.Text = "Réaliser le $date_Snap"
|
|
$form_restore_snap.Controls.Add($label2)
|
|
|
|
$form_restore_snap.Topmost = $True
|
|
$result = $form_restore_snap.ShowDialog()
|
|
## fin définition pop-up de restauration Snapshot ##
|
|
if ($result -eq [System.Windows.Forms.DialogResult]::OK)
|
|
{
|
|
###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
|
|
Stop-VM -computername $syncHash.serveur_vm -name $nom_machine -Force
|
|
# restauration du snapshot
|
|
Restore-VMSnapshot -computername $global:syncHash.serveur_vm -name $nom_Snap -VMName $VM_Snap -Confirm:$false
|
|
}
|
|
}
|
|
}else
|
|
{
|
|
[System.Windows.Forms.MessageBox]::Show('Aucun Snapshot de sélectionné!', 'Warning', 'ok', 'Warning')
|
|
###WriteToLogFile1 "Echec retour à un snapshot sur la vm $VM_Snap"
|
|
}
|
|
})
|
|
|
|
|
|
################################################################################################################################################
|
|
################################################################################################################################################
|
|
######################################################### Supprimer Snapshot ###################################################################
|
|
################################################################################################################################################
|
|
################################################################################################################################################
|
|
$syncHash.BTN_suppr_snap.add_click({
|
|
if ($global:syncHash.Datagrid_Snapshot.SelectedItems -ne "-1")
|
|
{
|
|
foreach ($snapshot in $global:syncHash.Datagrid_Snapshot.SelectedItems)
|
|
{
|
|
$nom_Snap = $snapshot.nom_snapshot
|
|
$date_Snap = $snapshot.date_snapshot
|
|
$VM_Snap = $snapshot.VM_snapshot
|
|
## début définition pop-up de suppression Snapshot ##
|
|
Add-Type -AssemblyName System.Windows.Forms
|
|
Add-Type -AssemblyName System.Drawing
|
|
|
|
$form_suppr_snap = New-Object System.Windows.Forms.Form
|
|
$form_suppr_snap.Text = "Suppression Snapshot - Support"
|
|
$form_suppr_snap.Size = New-Object System.Drawing.Size(400,150)
|
|
$form_suppr_snap.StartPosition = "CenterScreen"
|
|
|
|
$OKButton = New-Object System.Windows.Forms.Button
|
|
$OKButton.Location = New-Object System.Drawing.Point(115,70)
|
|
$OKButton.Size = New-Object System.Drawing.Size(75,23)
|
|
$OKButton.Text = "OK"
|
|
$OKButton.DialogResult = [System.Windows.Forms.DialogResult]::OK
|
|
$form_suppr_snap.AcceptButton = $OKButton
|
|
$form_suppr_snap.Controls.Add($OKButton)
|
|
|
|
$CancelButton = New-Object System.Windows.Forms.Button
|
|
$CancelButton.Location = New-Object System.Drawing.Point(210,70)
|
|
$CancelButton.Size = New-Object System.Drawing.Size(75,23)
|
|
$CancelButton.Text = "Cancel"
|
|
$CancelButton.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
|
|
$form_suppr_snap.CancelButton = $CancelButton
|
|
$form_suppr_snap.Controls.Add($CancelButton)
|
|
|
|
$label1 = New-Object System.Windows.Forms.Label
|
|
$label1.Location = New-Object System.Drawing.Point(10,15)
|
|
$label1.Size = New-Object System.Drawing.Size(380,20)
|
|
$label1.Text = "Suppression de Snapshot: $nom_Snap"
|
|
$form_suppr_snap.Controls.Add($label1)
|
|
|
|
$label2 = New-Object System.Windows.Forms.Label
|
|
$label2.Location = New-Object System.Drawing.Point(10,40)
|
|
$label2.Size = New-Object System.Drawing.Size(380,20)
|
|
$label2.Text = "Réaliser le $date_Snap"
|
|
$form_suppr_snap.Controls.Add($label2)
|
|
|
|
$form_suppr_snap.Topmost = $True
|
|
$result = $form_suppr_snap.ShowDialog()
|
|
## fin définition pop-up de suppression Snapshot ##
|
|
if ($result -eq [System.Windows.Forms.DialogResult]::OK)
|
|
{
|
|
###WriteToLogFile1 "demande de suppression du snapshot $nom_Snap sur la vm $VM_Snap"
|
|
Remove-VMSnapshot -computername $global:syncHash.serveur_vm -name $nom_Snap -VMName $VM_Snap
|
|
refresh_liste_snapshot
|
|
}
|
|
}
|
|
}else
|
|
{
|
|
[System.Windows.Forms.MessageBox]::Show('Aucun Snapshot de sélectionné!', 'Warning', 'ok', 'Warning')
|
|
###WriteToLogFile1 "Echec suppression snapshot sur la vm $VM_Snap - Aucun snapshot sélectionné"
|
|
}
|
|
})
|
|
|
|
|
|
################################################################################################################################################
|
|
################################################################################################################################################
|
|
######################################################### Renommer Snapshot ####################################################################
|
|
################################################################################################################################################
|
|
################################################################################################################################################
|
|
$syncHash.BTN_rename_snap.add_click({
|
|
if ($global:syncHash.Datagrid_Snapshot.SelectedItems -ne "-1")
|
|
{
|
|
foreach ($snapshot in $global:syncHash.Datagrid_Snapshot.SelectedItems)
|
|
{
|
|
$nom_Snap = $snapshot.nom_snapshot
|
|
$VM_Snap = $snapshot.VM_snapshot
|
|
## début définition pop-up de renommage Snapshot ##
|
|
Add-Type -AssemblyName System.Windows.Forms
|
|
Add-Type -AssemblyName System.Drawing
|
|
|
|
$form_rename_snap = New-Object System.Windows.Forms.Form
|
|
$form_rename_snap.Text = "Changement nom Snapshot"
|
|
$form_rename_snap.Size = New-Object System.Drawing.Size(300,150)
|
|
$form_rename_snap.StartPosition = "CenterScreen"
|
|
|
|
$OKButton = New-Object System.Windows.Forms.Button
|
|
$OKButton.Location = New-Object System.Drawing.Point(60,70)
|
|
$OKButton.Size = New-Object System.Drawing.Size(75,23)
|
|
$OKButton.Text = "OK"
|
|
$OKButton.DialogResult = [System.Windows.Forms.DialogResult]::OK
|
|
$form_rename_snap.AcceptButton = $OKButton
|
|
$form_rename_snap.Controls.Add($OKButton)
|
|
|
|
$CancelButton = New-Object System.Windows.Forms.Button
|
|
$CancelButton.Location = New-Object System.Drawing.Point(150,70)
|
|
$CancelButton.Size = New-Object System.Drawing.Size(75,23)
|
|
$CancelButton.Text = "Cancel"
|
|
$CancelButton.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
|
|
$form_rename_snap.CancelButton = $CancelButton
|
|
$form_rename_snap.Controls.Add($CancelButton)
|
|
|
|
$label = New-Object System.Windows.Forms.Label
|
|
$label.Location = New-Object System.Drawing.Point(10,20)
|
|
$label.Size = New-Object System.Drawing.Size(280,20)
|
|
$label.Text = "Saisir le nouveau nom du Snapshot:"
|
|
$form_rename_snap.Controls.Add($label)
|
|
|
|
$new_name_snap = New-Object System.Windows.Forms.TextBox
|
|
$new_name_snap.Location = New-Object System.Drawing.Point(10,40)
|
|
$new_name_snap.Size = New-Object System.Drawing.Size(260,20)
|
|
$form_rename_snap.Controls.Add($new_name_snap)
|
|
|
|
$form_rename_snap.Topmost = $True
|
|
|
|
$form_rename_snap.Add_Shown({$new_name_snap.Select()})
|
|
$result = $form_rename_snap.ShowDialog()
|
|
## fin définition pop-up de renommage Snapshot ##
|
|
|
|
if ($result -eq [System.Windows.Forms.DialogResult]::OK)
|
|
{
|
|
$NewNameSnap = $new_name_snap.Text
|
|
###WriteToLogFile1 " Demande de renommage de snapshot de la vm $VM_Snap. $nom_Snap => $NewNameSnap "
|
|
Rename-VMSnapshot -computername $global:syncHash.serveur_vm -name $nom_Snap -VMName $VM_Snap -NewName $NewNameSnap
|
|
refresh_liste_snapshot
|
|
}
|
|
}
|
|
}else
|
|
{
|
|
[System.Windows.Forms.MessageBox]::Show('Aucun Snapshot de sélectionné!', 'Warning', 'ok', 'Warning')
|
|
###WriteToLogFile1 "Echec renommage snapshot sur la vm $VM_Snap - Aucun snapshot sélectionné"
|
|
}
|
|
})
|
|
$syncHash.Window.ShowDialog() | Out-Null
|
|
|
|
})
|
|
try {
|
|
$psCmd.Runspace = $newRunspace
|
|
$psCmd.BeginInvoke() | Out-Null
|
|
}
|
|
catch {
|
|
$logpsCmd = "ligne 1282 - une exeption s'est produite $_.Exception.Message "
|
|
###WriteToLogFile0 $logpsCmd
|
|
}
|
|
|
|
#Read-Host -Prompt "Press Enter to exit"
|