VMWare Horizon Mirage | Extraction des données - CVD's
Vérification de la version de PowerShell
- https://docs.microsoft.com/fr-fr/skypeforbusiness/set-up-your-computer-for-windows-powershell/download-and-install-windows-powershell-3-0
Dans la console PowerShell, tapez la commande suivante et appuyez sur ENTRÉE pour vérifier sa version :
Get-Host | Select-Object Version
Des informations similaires à celles-présentées ci-dessous doivent s'afficher dans la fenêtre de console :
Version
-------
3.0 Si le numéro de version renvoyé est 3.0, c'est que vous utilisez Windows PowerShell 3.0
Pour installer Windows Management Framework 3.0, procédez comme suit :
Double-cliquez sur le fichier d’installation .MSU ( Windows6.1-KB2506143-x64.msu ou Windows6.1-KB2506143-x86).
Dans l'assistant Télécharger et installer des mises à jour, sur la page Lire les termes du contrat de licence (1 sur 1), cliquez sur J'accepte.
Une fois le processus d'installation terminé, cliquez sur Redémarrer maintenant pour redémarrer votre ordinateur.
Les sources pour vous amuser avec l'extraction PS2EXE-GUI.zip
Conversion d'un *.ps1 en *.exe
il faudra renommer le fichier MirageExtractorV1.txt en ps1 ,
Et la commande pour convertir un powershell, ps1 to exe :
D:\Profile\erholo\Downloads\PS2EXE-GUI\ps2exe.ps1 D:\Profile\erholo\Desktop\MirageExtractorV1.ps1 D:\Profile\erholo\Desktop\MirageExtractorV1.exe -title 'Mirage Extractor' -description 'Mirage Extractor' -company 'SPIE ICS' -product 'Mirage Extractor' -copyright '<copyright SPIE ICS>' -version 1.0.0.0 -iconFile "C:\Windows\Installer\{B3008896-955E-4CF8-BEDA-B3B10525519C}\wanova.ico"
Contenu du fichier MirageExtractorV1.ps1
####################
# Mirage Extractor #
# version 1 #
# 12/12/2018 #
# Eric Holo #
# CRIDF #
####################
# Chargement des Windows Form
#region
[void][System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[void][System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
#endregion
###########
#fonction cvdcollectioncollect
###########
function AddData
{
param($cvdcollection, $list)
$list.BeginUpdate()
$list.items.Clear()
foreach ($cvd in $cvdcollection)
{
$item = New-Object System.Windows.Forms.ListViewItem($cvd.ID)
[Void]$item.SubItems.Add($cvd.Name)
#[Void]$item.SubItems.Add($button_export)
[Void] $list.Items.Add($item)
#############################
#############################
}
$list.EndUpdate()
}
#################################################
# CONFIGURATION DE LA WINDOWS FORM
#################################################
# Creation de la form principale
$form = New-Object Windows.Forms.Form
# Pour bloquer le resize du form et supprimer les icones Minimize and Maximize
$form.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::FixedDialog
$form.MaximizeBox = $False
$form.MinimizeBox = $False
# Choix du titre
$form.Text = "Mirage Extractor"
# Choix de la taille
$form.Size = New-Object System.Drawing.Size(400,250)
#################################################
$form2 = New-Object Windows.Forms.Form
# Pour bloquer le resize du form et supprimer les icones Minimize and Maximize
$form2.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::FixedDialog
$form2.MaximizeBox = $False
$form2.MinimizeBox = $False
# Choix du titre
$form2.Text = "Mirage Collections"
# Choix de la taille
$form2.Size = New-Object System.Drawing.Size(620,475)
##############################################
# Creation de la form principale
$form3 = New-Object Windows.Forms.Form
# Pour bloquer le resize du form et supprimer les icones Minimize and Maximize
$form3.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::FixedDialog
$form3.MaximizeBox = $False
$form3.MinimizeBox = $False
# Choix du titre
$form3.Text = "Mirage Extractor"
# Choix de la taille
$form3.Size = New-Object System.Drawing.Size(400,250)
#################################################
# AJOUT DES COMPOSANTS
#################################################
# Bouton Quitter
$button_quit = New-Object System.Windows.Forms.Button
$button_quit.Text = "Fermer"
$button_quit.Size = New-Object System.Drawing.Size(355,40)
$button_quit.Location = New-Object System.Drawing.Size(20,150)
# Label 1
$label_prez = New-Object System.Windows.Forms.Label
$label_prez.AutoSize = $true
$label_prez.Location = New-Object System.Drawing.Point(20,20)
$label_prez.Size = New-Object System.Drawing.Size(100,20)
$label_prez.Text = "Entrez les credentials afin de vous authentifier sur mirage "
# Label 3
$label_connector = New-Object System.Windows.Forms.Label
$label_connector.AutoSize = $true
$label_connector.Location = New-Object System.Drawing.Point(20,100)
$label_connector.Size = New-Object System.Drawing.Size(100,20)
$label_connector.Text = "Etat de connection "
# Bouton Starter
$button_starter = New-Object System.Windows.Forms.Button
$button_starter.Text = "Extract"
$button_starter.Size = New-Object System.Drawing.Size(355,40)
$button_starter.Location = New-Object System.Drawing.Size(20,40)
# Bouton export
$button_export = New-Object System.Windows.Forms.Button
$button_export.Size = New-Object System.Drawing.Size(10,10)
#################################################
# GESTION DES EVENEMENTS
#################################################
# Gestion event quand on clique sur le bouton Fermer
$button_quit.Add_Click(
{
$form.Close();
})
$button_starter.Add_Click(
{
cd 'C:\Program Files (x86)\VMware\Infrastructure\VMware PowerCLI for Mirage\Modules'
Import-Module .\VMware.Mirage.Cmds
$Usermirage = Get-Credential -Credential CRIDF\mirage.adm
$BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($Usermirage.Password)
$PlainPassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)
$connector=Connect-MirageServer -Server infra-p-mir1 -Username $Usermirage.UserName -Password $Plainpassword
$cvdcollection=Get-MirageCvdCollection | select Id,Name
if ($connector.IsConnected -eq "True")
{
$label_connector.Text = 'Vous êtes connecté.'
$list = New-Object System.Windows.Forms.ListView
$list.Location = New-Object System.Drawing.Point(3,30)
$list.Size = New-Object System.Drawing.Size(605, 382)
$list.View = "Details"
$list.GridLines = $true
$list.FullRowSelect = $true
$list.AllowColumnReorder = $true
$list.Scrollable = $true
$list.Sorting ='None'
$col = $list.Columns.Add("ID", 100)
$tag = New-Object -TypeName PSCustomObject -Property @{
sortOrder = [System.Windows.Forms.SortOrder]::Ascending
}
$col.Tag = $tag
$col = $list.Columns.Add("Name", 310)
# $col = $list.Columns.Add("Export",50)
AddData $cvdcollection $list
$OnResize =
{
$size = New-Object System.Drawing.Size
$size.Width = $form.Width - 15
$size.Height = $form.Height - 93
$list.Size = $size
}
$form2.add_Resize($OnResize)
$form2.Controls.add($list)
$ListView_MouseClick =
{
# On right mouse click show the dialog form
# If the dialog result is OK change the subitem text
# The MouseClick event returns the clicked coordinates (X, Y)
# and ListViewHitTestInfo is used to get the right-clicked subitem
# $Inp.Text contains the text the user entered
if($_.Button -eq [Windows.Forms.MouseButtons]::Right)
{
$value1 = $NULL
$value2 = $NULL
$value3 = $NULL
$value4 = $NULL
$value5 = $NULL
$value6 = $NULL
$export4
$export3=$NULL
$export2=$NULL
$export1=$List.HitTest($_.X, $_.Y).Item
foreach ($ligne in $export1){ $export2 = $export2 + $ligne -split "ListViewItem: {"}
foreach ($ligne in $export2){ $export3 = $export3 + $ligne -split "}"}
$ID=$export3[1]
$value1=Get-MirageCvd -Archived 0 | Select Id
foreach ($line in $value1) { $value2 = $value2 + $line -split "\s+"}
foreach ($line in $value2) { $value3 = $value3 + $line -split "}"}
foreach ($line in $value3) { $value4 = $value4 + $line -split "@{Id="}
foreach ($ligne in $value4){if ($ligne.contains("cvd-")){$value5=$value5+$ligne+" "}}
$value6=$value5.split(" ")
$count=$value6.count -1
$value7 = [System.Collections.generic.List[System.Object]]$value6
$value7.removeat($count)
for($i=0;$i -lt $value7.count; $i++)
{
Get-MirageCvdCollection -ID $ID| Get-MirageCvd -Id $value7[$i] | ft | out-file -append \\landesk-p-app2\Inventaires\ExportMirage\monextract.csv
}
}
}
$list.Add_MouseClick($ListView_MouseClick)
$form2.ShowDialog()
}
else{
$label_connector.Text = "Identifiant invalide, veuillez relancer l'initialisation."
}
})
#################################################
# INSERTION DES COMPOSANTS
#################################################
# Ajout des composants a la Form
$form.Controls.Add($label_prez)
$form.Controls.Add($label_connector)
$form.Controls.Add($button_quit)
$form.Controls.Add($button_starter)
# Affichage de la Windows
$form.ShowDialog()
#################################################
# END OF PROGRAM
#################################################