cls $hote = (Get-VMHost).name new-item -path c:\ -name audit -itemtype directory -force $pathfile = "c:\audit\Audit de la virtualisation du serveur " + $hote + ".html" #$pathfilehtml = $chem.Path + "\desktop\" + $hote +".html" new-item -Path $pathfile -ItemType file -Force Add-Content -Path $pathfile -value "

Caractéristiques du l'infrastructure virtuelle

" # Analyse de l'hôte hyper-V Add-Content -Path $pathfile -value "

Description des caractéristiques du serveur $hote

" # Processeurs Add-Content -Path $pathfile -value "

Processeur(s) installé(s) sur le serveur :

" $hoteprocs = Get-WmiObject –class Win32_processor Add-Content -Path $pathfile -value '' Add-Content -Path $pathfile -value "" foreach ($hoteproc in $hoteprocs) { $cpu = $hoteproc.DeviceID $Nom = $hoteproc.Name $Description = $hoteproc.description $Cores = $hoteproc.NumberOfCores $logical = $hoteproc.NumberOfLogicalProcessors $Vitesse = $hoteproc.CurrentClockSpeed $l2 = $hoteproc.L2CacheSize $l3 = $hoteproc.L3CacheSize Add-Content -Path $pathfile -value "" } Add-Content -Path $pathfile -value "
CPU n°NomDescriptionCoresProcs logiquesVitesseL2L3
$cpu$Nom$Description$Cores$logical$Vitesse Mhz$l2 Mo$l3 Mo
" # Mémoire $Taille_RAM_MAX=[math]::Round([STRING]((Get-WmiObject -Class Win32_ComputerSystem ).TotalPhysicalMemory/1GB),2) $Taille_RAM_LIBRE=[math]::Round([String]((Get-WmiObject -Class Win32_OperatingSystem).FreePhysicalMemory/1MB) ,2) $Taille_RAM_UTILISE=[STRING]($Taille_RAM_MAX - $Taille_RAM_LIBRE) Add-Content -Path $pathfile -value "

Mémoire :

" Add-Content -Path $pathfile -value "Le serveur dispose de $Taille_RAM_MAX Gb de mémoire installée. Il en utilise actuellement $Taille_RAM_UTILISE Gb. Il lui en reste $Taille_RAM_LIBRE Gb de libre." # Configuration de la réplication Add-Content -Path $pathfile -value "

Réplication :

" $replica = Get-VMReplicationServer -ComputerName $hote $repli = $replica.RepEnabled if ($repli -like 'True') { $AuthType = $replica.AuthType $KerbAuthPort = $replica.KerbAuthPort $CertAuthPort = $replica.CertAuthPort $AllowAnyServer = $replica.AllowAnyServer Add-Content -Path $pathfile -value "Le serveur étant configuré pour la réplication, l'authentification est de type $AuthType. Le port $KerbAuthPort ainsi que le port $CertAuthPort sont utilisés pour la réplication.
" if ($AllowAnyServer -like 'True'){Add-Content -Path $pathfile -value "La réplication est activée vers n'importe quel serveur.
"} } else { Add-Content -Path $pathfile -value "Le serveur n'est pas configuré pour la réplication des machines virtuelles.
" } # disques durs Add-Content -Path $pathfile -value "

Disques durs physiques sur le serveur :

" $hotedds = Get-PhysicalDisk Add-Content -Path $pathfile -value '' Add-Content -Path $pathfile -value "" foreach ($hotedd in $hotedds) { $diskn = $hotedd.FriendlyName $etat = $hotedd.OperationalStatus $taille = [math]::Round($hotedd.Size/1GB,2) Add-Content -Path $pathfile -value "" } Add-Content -Path $pathfile -value "
Disque physiqueStatutCapacité
$diskn$etat$taille G
" Add-Content -Path $pathfile -value "

Partitions sur le serveur :

" $hotedds = Get-volume Add-Content -Path $pathfile -value '' Add-Content -Path $pathfile -value "" foreach ($hotedd in $hotedds) { $diskn = $hotedd.DriveLetter $tailledispo = [math]::Round($hotedd.SizeRemaining/1GB,2) $nom = $hotedd.FileSystemLabel $taille = [math]::Round($hotedd.Size/1GB,2) Add-Content -Path $pathfile -value "" } Add-Content -Path $pathfile -value "
LecteurNomCapacité totalEspace disponible
$diskn$nom$taille G$tailledispo G
" # Carte(s) réseau(x) Add-Content -Path $pathfile -value "

Carte(s) réseau(x) présente(s) sur le serveur :

" $hoteres = Get-NetAdapter Add-Content -Path $pathfile -value '' Add-Content -Path $pathfile -value "" foreach ($hotere in $hoteres) { $nom = $hotere.name $Description = $hotere.InterfaceDescription $Statut = $hotere.status $mac = $hotere.MacAddress $ipinter = $hotere.ifIndex $ip = Get-NetIPAddress -InterfaceIndex $ipinter -ErrorAction SilentlyContinue $vitesse = $hotere.LinkSpeed Add-Content -Path $pathfile -value "" } Add-Content -Path $pathfile -value "
NomDescriptionStatutMacIPVitesse
$nom$Description$Statut$mac$ip$vitesse
" $vmswitchs = Get-VMSwitch -ComputerName $hote | Select-Object * $VMs = Get-VM -ComputerName $hote | select-object * Add-Content -Path $pathfile -value "

Machines virtuelles présentes sur le serveur :

" Add-Content -Path $pathfile -value "Voici les différentes machines virtuelles présentes sur le serveur :" Add-Content -Path $pathfile -value '' Add-Content -Path $pathfile -value "" foreach ($vm in $vms) { $nomvm = $vm.name.ToUpper() $nbrproc = $vm.ProcessorCount $etat = $vm.State $composint = $vm.IntegrationServicesState $Generation = $vm.Generation #$vmcluster = $vm.IsClustered if ($vm.IsClustered -like 'True') {$vmcluster = "Oui" } else {$vmcluster = "Non"} Add-Content -Path $pathfile -value "" } Add-Content -Path $pathfile -value "
Machine virtuelleEn clusterGenerationEtatService d'intégration
$nomvm$vmcluster$Generation$etat$composint
" Add-Content -Path $pathfile -value "

Détails des machines virtuelles

" foreach ($vm in $vms) { $nomvm = $vm.name Add-Content -Path $pathfile -value "

Machine virtuelle $nomvm

" # processeur $proc = Get-VMProcessor $nomvm -ComputerName $hote $memoire = Get-VMMemory $nomvm -ComputerName $hote $coeurs = $proc.count $memmin = ($memoire.Minimum)/1gb $memdem = ($memoire.Startup)/1gb $memmax = ($memoire.Maximum)/1gb $memconf = $memoire.DynamicMemoryEnabled $Generation = $vm.Generation Add-Content -Path $pathfile -value "La machine virtuelle $nomvm possède un processeur $coeurs coeur(s), avec au démarrage $memdem Go.
" if ($memconf -like 'True') {Add-Content -Path $pathfile -value "L'allocation mémoire dynamique étant activée, la mémoire minimal est de $memmin Go et la quantité maximum est de $memmax Go."} else {Add-Content -Path $pathfile -value "L'allocation mémoire dynamique est désactivée.
"} if ($Generation -eq 1) { $dem = (Get-VMBios -VMName $nomvm).StartupOrder Add-Content -Path $pathfile -value "L'ordre de démarrage configuré dans le bios est le suivant : $dem.
" } else { $dems = (Get-VMFirmware -VMName $nomvm -ComputerName $hote).BootOrder Add-Content -Path $pathfile -value "L'ordre de démarrage configuré dans le firmware est le suivant : " Foreach ($dem in $dems) { $boottype = $dem.Boottype Add-Content -Path $pathfile -value "$boottype, " } Add-Content -Path $pathfile -value "
" } # Réplication $repl = Get-VMReplication -VMName $nomvm -ComputerName $hote -ErrorAction SilentlyContinue $State = $repl.State $Health = $repl.Health $Mode = $repl.Mode $FrequencySec = $repl.FrequencySec $PrimaryServer = $repl.PrimaryServer $ReplicaServer = $repl.ReplicaServer $ReplicaPort = $repl.ReplicaPort $AuthType = $repl.AuthType $Relationship = $repl.Relationship if($state -notlike "") { Add-Content -Path $pathfile -value "La machine virtuelle $nomvm est répliquée toutes les $FrequencySec secondes du serveur $PrimaryServer vers le serveur $ReplicaServer. L'état de la réplication est actuellement sur $Health." Add-Content -Path $pathfile -value "La réplication se fait sur le port $ReplicaPort via l'authentification $AuthType.
" } else { Add-Content -Path $pathfile -value "La machine virtuelle $nomvm n'est pas répliquée sur un autre serveur.
" } # Ports COM $com = Get-VMComPort -VMName $nomvm -ComputerName $hote $com = $com.name if ($com -notlike "") {Add-Content -Path $pathfile -value "La machine virtuelle $nomvm possède le(s) port(s) de communication suivant(s) : $com"} # Lecteur de disquette if ($Generation -eq 1) { $disqs = Get-VMFloppyDiskDrive -VMName $nomvm -ComputerName $hote if ($disqs -notlike "") { Add-Content -Path $pathfile -value "
La machine virtuelle $nomvm possède au moins un lecteur de disquette." } } # Disque dur Add-Content -Path $pathfile -value "
Disques durs virtuels
" Add-Content -Path $pathfile -value '' Add-Content -Path $pathfile -value "" $dds = Get-VMHardDiskDrive -VMName $nomvm -ComputerName $hote foreach ($dd in $dds) { $pathdd = $dd.Path $testdd = get-item $pathdd $nomdd = $testdd.name $taillevhd = [math]::Round($testdd.length/1GB,2) $stockagevhd = (Get-Item -Path $pathdd).DirectoryName $connecte = $dd.name $typevhd = (get-vhd -path $pathdd).vhdtype $sizevhd = [math]::Round((get-vhd -path $pathdd).size/1GB,2) Add-Content -Path $pathfile -value "" } Add-Content -Path $pathfile -value "
Nom du FichierTaille du DDEmplacementConnectéTypeTaille
$nomdd$taillevhd$stockagevhd$connecte$typevhd$sizevhd G
" # Lecteur dvd $dvds = Get-VMDvdDrive -VMName $nomvm -ComputerName $hote if ($dvds -notlike "") { Add-Content -Path $pathfile -value "
Lecteur(s) DVD
" Add-Content -Path $pathfile -value '' Add-Content -Path $pathfile -value "" foreach ($dvd in $dvds) { $ControllerType = $dvd.ControllerType $ControllerNumber = $dvd.ControllerNumber $ControllerLocation = $dvd.ControllerLocation $DvdMediaType = $dvd.DvdMediaType $path = $dvd.path Add-Content -Path $pathfile -value "" } Add-Content -Path $pathfile -value "
Controller TypeController n°Location n°Type de DVDChemin d'accès
$ControllerType$ControllerNumber$ControllerLocation$DvdMediaType$path
" } # Carte(s) réseau(x) Add-Content -Path $pathfile -value "
Carte(s) réseau(x) virtuelle(s)
" Add-Content -Path $pathfile -value '' Add-Content -Path $pathfile -value "" $res = Get-VMNetworkAdapter -VMName $nomvm -ComputerName $hote foreach ($re in $res) { $nom = $re.name $Commutateur = $re.SwitchName $Mac = $re.MacAddress $Statut = $re.Status $IP = $re.IPAddresses $id = $re.Id Add-Content -Path $pathfile -value "" } Add-Content -Path $pathfile -value "
NomCommutateurMacStatutIP
$nom$Commutateur$Mac$Statut$IP
" # Services d'intégration Add-Content -Path $pathfile -value "
Services d'intégration
" Add-Content -Path $pathfile -value '' Add-Content -Path $pathfile -value "" $res = Get-VMNetworkAdapter -VMName $nomvm $services = Get-VMIntegrationService -VMName $nomvm -ComputerName $hote foreach ($service in $services) { $nom = $service.name $active = $service.Enabled $primaire = $service.PrimaryStatusDescription $secondaire = $service.SecondaryStatusDescription Add-Content -Path $pathfile -value "" } Add-Content -Path $pathfile -value "
NomActivéPrimaireSecondaire
$nom$active$primaire$secondaire
" # Point de contrôle $Conts = Get-VMSnapshot -VMName $nomvm -ComputerName $hote if ($conts -notlike "") { Add-Content -Path $pathfile -value "
Point(s) de contrôle
" Add-Content -Path $pathfile -value '' Add-Content -Path $pathfile -value "" foreach ($cont in $Conts) { $nom = $cont.name $SnapshotType = $cont.SnapshotType $CreationTime = $cont.CreationTime $ParentSnapshotName = $cont.ParentSnapshotName Add-Content -Path $pathfile -value "" } } else { Add-Content -Path $pathfile -value "La machine virtuelle $nomvm ne possède pas de point de contrôle." } Add-Content -Path $pathfile -value "
NomType de point de contrôleDate de créationPoint de contrôle parent
$nom$SnapshotType$CreationTime$ParentSnapshotName
" } Get-VMNetworkAdapterVlan -VMName $nomvm -ComputerName $hote Get-VMNetworkAdapterAcl -VMName $nomvm -ComputerName $hote Get-VMNetworkAdapterExtendedAcl -VMName $nomvm -ComputerName $hote Get-VMNetworkAdapterFailoverConfiguration -VMName $nomvm -ComputerName $hote Get-VmNetworkAdapterIsolation -VMName $nomvm -ComputerName $hote Get-VMNetworkAdapterRoutingDomainMapping -VMName $nomvm -ComputerName $hote Get-VMRemoteFx3dVideoAdapter -VMName $nomvm -ComputerName $hote Get-VMRemoteFXPhysicalVideoAdapter -Name $nomvm -ComputerName $hote Get-VMReplicationAuthorizationEntry -ComputerName $hote Get-VMResourcePool -ComputerName $hote Get-VMSan -ComputerName $hote Get-VMScsiController -VMName $nomvm -ComputerName $hote Get-VMSnapshot -VMName $nomvm #Get-VMStoragePath -VMName $vm <# #switch foreach ($vmswitch in $vmswitchs){ $vmswitch = $vmswitch.SwitchName Get-VMSwitch -name $vmswitch Get-VMSwitchExtension -VMSwitchName $vmswitch Get-VMSwitchExtensionPortData -Vmname $vm Get-VMSwitchExtensionPortFeature -Vmname $nomvm Get-VMSwitchExtensionSwitchData -SwitchName $vmswitch Get-VMSwitchExtensionSwitchFeature -SwitchName $vmswitch Get-VMSystemSwitchExtension -name $vm Get-VMSystemSwitchExtensionPortFeature Get-VMSystemSwitchExtensionSwitchFeature #> $fin = "

Rapport édité le " + (Get-Date) + "." Add-Content -Path $pathfile -value $fin &"C:\Program Files\Internet Explorer\iexplore.exe" "$pathfile"