Files
Supervision_Hyper-V/test-2-module_hyper-V-boucles_runspaces.ps1
2023-11-22 14:48:52 +01:00

1046 lines
65 KiB
PowerShell

################################################################################################################################################
################################################################################################################################################
################################################# Assembly nécessaire pour la fenêtre graphique ################################################
################################################################################################################################################
################################################################################################################################################
Add-Type -AssemblyName PresentationFramework
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName PresentationCore
Add-Type -AssemblyName WindowsBase
# .Net methods for hiding/showing the console in the background
Add-Type -Name Window -Namespace Console -MemberDefinition '
[DllImport("Kernel32.dll")]
public static extern IntPtr GetConsoleWindow();
[DllImport("user32.dll")]
public static extern bool ShowWindow(IntPtr hWnd, Int32 nCmdShow);
'
################################################################################################################################################
################################################################################################################################################
############################################################### 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
################################################################################################################################################
################################################################################################################################################
############################## Déclaration de la Hash table qui sera synchronisée entre les différents runspaces ###############################
################################################################################################################################################
################################################################################################################################################
$syncHash = [hashtable]::Synchronized(@{})
################################################################################################################################################
################################################################################################################################################
############################################ Déclaration du premier runspace pour l'interface graphique ########################################
################################################################################################################################################
################################################################################################################################################
$newRunspace =[runspacefactory]::CreateRunspace()
$newRunspace.ApartmentState = "STA" ## Le STA est là pour l'interface en WP
$newRunspace.ThreadOptions = "ReuseThread"
$newRunspace.Open()
$newRunspace.SessionStateProxy.SetVariable("syncHash",$syncHash)
$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 Test" HorizontalAlignment="Center" Margin="10,0,0,0" VerticalAlignment="Top" Width="100" Height="25" />
</StackPanel>
<GroupBox Header="Qui que c'est qu'est réveillé?" 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="100" Margin="0,20,20,0" RenderTransformOrigin="0.49,2.067">
<StackPanel x:Name="SP_Buttons3" Orientation="Vertical" Width="100" 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="Reboot_machine" Content="Reboot 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="100" 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="ajout_machine" Content="Ajouter 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="100" 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="list_snap" Content="Lister Snapshot" HorizontalAlignment="Left" Margin="0,40,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="100" 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="suppr_snap" Content="Effacer 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="100" 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 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 = 'C:\Users\maxime.tertrais\Desktop\Supervision_powershell_VM\interface_(ping_et_reboot-shutdown)\Liste_VM.xml'
$global:syncHash.BTN_Start.IsEnabled =$true
$global:syncHash.BTN_Stop.IsEnabled = $false
$global:syncHash.tests_en_cours = $false
$global:syncHash.logfilepath = "C:\Users\maxime.tertrais\Desktop\Supervision_powershell_VM\interface_(ping_et_reboot-shutdown)\Logs_supervision _vm_support.log"
$global:syncHash.todaysdate = Get-Date -Format "MM-dd-yyyy-hh-mm-ss"
#Déclaration de fonctions
function WriteToLogFile ($message)
{
(Get-Date).ToString() +" - "+ $message >> $syncHash.logfilepath
}
if(Test-Path $syncHash.logfilepath)
{
Remove-Item $syncHash.logfilepath
}
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
WriteToLogFile $nom_machine
$list_snap = Get-VMSnapshot -ComputerName $global:syncHash.serveur_vm -VMName $nom_machine | Select-Object -Property CreationTime,Name,VMName
WriteToLogFile $list_snap
ForEach ($Snap in $list_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
WriteToLogFile "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 Hide-Console
{
$consolePtr = [Console.Window]::GetConsoleWindow()
#0 hide
[Console.Window]::ShowWindow($consolePtr, 0)
}
Hide-Console
################################################################################################################################################
################################################################################################################################################
######################################################### Fermeture de la fenètre ##############################################################
################################################################################################################################################
################################################################################################################################################
$syncHash.Window.Add_Closing({
$_.Cancel = $true
$Resultat = [System.Windows.Forms.MessageBox]::Show('Voulez-vous fermer lapplication ?', 'Warning', 'YesNo', 'Warning')
If ($Resultat -eq 'Yes')
{
$_.Cancel = $false
$syncHash.Window.Close()
}
})
################################################################################################################################################
################################################################################################################################################
############################################## Ajout du second runspace au bouton Start ########################################################
################################################################################################################################################
################################################################################################################################################
$syncHash.BTN_Start.add_click({
#WriteToLogFile "clik start fait"
$syncHash.BTN_Start.IsEnabled=$false
$syncHash.BTN_Stop.IsEnabled=$true
#WriteToLogFile "switch bouton start/stop ok"
$global:syncHash.tests_en_cours = $true
#WriteToLogFile "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)
#WriteToLogFile "ouverture runspace enfant ok"
$psScript = [PowerShell]::Create().AddScript({
## Corps du runspace
$MachinesXML = [xml](get-content $syncHash.Liste_vm )
$Liste_Machines = $MachinesXML.Machine.Serveur
while ($syncHash.tests_en_cours -like $true) {
$syncHash.Datagrid_Connexion.Items.Clear()
$syncHash.Datagrid_Connexion.Items.Refresh()
#$log_raz_datagrid = "RAZ Datagrid_Connexion ok"
#$log_raz_datagrid |Add-Content -Path "C:\Users\maxime.tertrais\Desktop\Supervision_powershell_VM\interface_(ping_et_reboot-shutdown)\Logs_supervision _vm_support.log"
#$log_lancement_boucle = "lancement boucle de test"
#$log_lancement_boucle |Add-Content -Path "C:\Users\maxime.tertrais\Desktop\Supervision_powershell_VM\interface_(ping_et_reboot-shutdown)\Logs_supervision _vm_support.log"
ForEach ($Machine in $Liste_Machines)
{
$Test = Get-VM -ComputerName $syncHash.serveur_vm -Name $Machine.Address
#$log_test_fait = "test fait"
#$log_test_fait |Add-Content -Path "C:\Users\maxime.tertrais\Desktop\Supervision_powershell_VM\interface_(ping_et_reboot-shutdown)\Logs_supervision _vm_support.log"
#$serveurvm |Add-Content -Path "C:\Users\maxime.tertrais\Desktop\Supervision_powershell_VM\interface_(ping_et_reboot-shutdown)\Logs_supervision _vm_support.log"
#$Machine.Address |Add-Content -Path "C:\Users\maxime.tertrais\Desktop\Supervision_powershell_VM\interface_(ping_et_reboot-shutdown)\Logs_supervision _vm_support.log"
$Test |Add-Content -Path "C:\Users\maxime.tertrais\Desktop\Supervision_powershell_VM\interface_(ping_et_reboot-shutdown)\Logs_supervision _vm_support.log"
$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
#$Machine_Valeur |Add-Content -Path "C:\Users\maxime.tertrais\Desktop\Supervision_powershell_VM\interface_(ping_et_reboot-shutdown)\Logs_supervision _vm_support.log"
$global:syncHash.Window.Dispatcher.invoke([action]{
$syncHash.Datagrid_Connexion.Items.Add($Machine_Valeur) > $null
})
#$Machine_Valeur |Add-Content -Path "C:\Users\maxime.tertrais\Desktop\Supervision_powershell_VM\interface_(ping_et_reboot-shutdown)\Logs_supervision _vm_support.log"
}
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()
})
################################################################################################################################################
################################################################################################################################################
######################################################### 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
}
}else
{
[System.Windows.Forms.MessageBox]::Show('Aucune VM de sélectionné', 'Warning', 'ok', 'Warning')
}
})
################################################################################################################################################
################################################################################################################################################
########################################################## 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(40,10)
$label.Size = New-Object System.Drawing.Size(110,20)
$label.Text = "Merci de préciser les points suivants :"
$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(142,23)
$label_BDD_vm.Text = "Type de BDD de la VM : "
$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")
$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(142,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(142,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(142,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(142,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
}
else
{
[System.Windows.Forms.MessageBox]::Show('Ajout nouvelle VM annulé', 'Warning', 'ok', 'Warning')
}
})
################################################################################################################################################
################################################################################################################################################
######################################################## 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
}
}else
{
[System.Windows.Forms.MessageBox]::Show('Aucune VM de sélectionné', 'Warning', 'ok', 'Warning')
}
})
################################################################################################################################################
################################################################################################################################################
########################################################## 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êts 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
}
}else
{
[System.Windows.Forms.MessageBox]::Show('Aucune VM de sélectionné', 'Warning', 'ok', 'Warning')
}
})
################################################################################################################################################
################################################################################################################################################
######################################################### 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
$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)
}
}
else
{
[System.Windows.Forms.MessageBox]::Show('Aucune VM de sélectionné', 'Warning', 'ok', 'Warning')
}
})
################################################################################################################################################
################################################################################################################################################
######################################################### 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(300,200)
$form_Remove_machine.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_Remove_machine.AcceptButton = $OKButton
$form_Remove_machine.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_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
}
}
else
{
[System.Windows.Forms.MessageBox]::Show('Aucune VM de sélectionné', 'Warning', 'ok', 'Warning')
}
})
################################################################################################################################################
################################################################################################################################################
################################################### Récupération liste Snapshot VM #############################################################
################################################################################################################################################
################################################################################################################################################
$syncHash.BTN_list_snap.add_click({
WriteToLogFile "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
WriteToLogFile "Vidange Datagrid_Snapshot ok"
if ($syncHash.Datagrid_Connexion.SelectedIndex -ne "-1")
{
WriteToLogFile "selection Datagrid_Snapshot ok"
refresh_liste_snapshot
}else
{
[System.Windows.Forms.MessageBox]::Show('Aucune VM de sélectionné', 'Warning', 'ok', 'Warning')
}
})
################################################################################################################################################
################################################################################################################################################
########################################################### Faire Snapshot #####################################################################
################################################################################################################################################
################################################################################################################################################
$syncHash.BTN_faire_snap.add_click({
if ($global:syncHash.Datagrid_Connexion.SelectedItems -ne "-1")
{
foreach ($selected_item in $global:syncHash.Datagrid_Connexion.SelectedItems)
{
$nom_machine = $selected_item.Serveur
## 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
Checkpoint-VM -computername $syncHash.serveur_vm -SnapshotName $newsnap -Name $nom_machine -Confirm:$false
refresh_liste_snapshot
}
}
}else
{
[System.Windows.Forms.MessageBox]::Show('Aucun Snapshot de sélectionné!', 'Warning', 'ok', 'Warning')
}
})
################################################################################################################################################
################################################################################################################################################
######################################################### Restorer 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(75,60)
$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(150,60)
$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)
$label = New-Object System.Windows.Forms.Label
$label.Location = New-Object System.Drawing.Point(10,20)
$label.Size = New-Object System.Drawing.Size(380,20)
$label.Text = "Retour au Snapshot $nom_Snap réaliser le $date_Snap ?"
$form_restore_snap.Controls.Add($label)
$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)
{
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')
}
})
################################################################################################################################################
################################################################################################################################################
######################################################### Suprimmer 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(75,60)
$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(150,60)
$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)
$label = New-Object System.Windows.Forms.Label
$label.Location = New-Object System.Drawing.Point(10,20)
$label.Size = New-Object System.Drawing.Size(380,20)
$label.Text = "Supprimmer le Snapshot $nom_Snap réaliser le $date_Snap ?"
$form_suppr_snap.Controls.Add($label)
$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)
{
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')
}
})
################################################################################################################################################
################################################################################################################################################
######################################################### 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 = "Suppression Snapshot - Support"
$form_rename_snap.Size = New-Object System.Drawing.Size(300,200)
$form_rename_snap.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_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,120)
$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
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')
}
})
$syncHash.Window.ShowDialog() | Out-Null
})
$psCmd.Runspace = $newRunspace
$psCmd.BeginInvoke() | Out-Null