Skip to content

Instantly share code, notes, and snippets.

@Fred-Vatin
Created April 11, 2024 02:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fred-Vatin/43cf369674d480f9da9f145d74699dbb to your computer and use it in GitHub Desktop.
Save Fred-Vatin/43cf369674d480f9da9f145d74699dbb to your computer and use it in GitHub Desktop.
WinIsoInfo : get Windows Image info [french]
#requires -RunAsAdministrator
#region begin Usage
# Résumé
# ======
# Obtient des infos sur les ISO d'installation de Windows telles que leur version détaillée
# Syntaxe
# =======
# WinIsoInfo [-Path] <String[]>
# Exemples
# ========
# PS C:\> WinIsoInfo
# (la commande invoquée seule vous demandera le chemin vers l'ISO)
# ou bien passer le chemin directement en argument tel que:
# PS C:\> WinIsoInfo -Path "E:\Win 10\Installation\ISO\Windows 10 x64 fr.iso"
# Vous pouvez rediriger la sortie de la commande dans un fichier plutôt que dans la console telle que:
# PS C:\> WinIsoInfo -Path "E:\Win 10\Installation\ISO\Windows 10 x64 fr.iso" | Out-File c:\scripts\test.txt -width 255
# Dans ce cas l'argument [-Path] est requis.
#endregion Usage
$Path = $args[0]
function WinIsoInfo {
[cmdletbinding()]
Param([string]$Path)
Process {
#region begin Formatage du titre
$Space = 19
$TitleL1 = "INFORMATIONS DÉTAILLÉES SUR LE FICHIER ISO"
$TitleL2 = "D'INSTALLATION WINDOWS"
$TitleRef = " " * $Space + $TitleL1 + " " * $Space
$ExtraLine = $TitleRef.Length
$TitleDiff = $TitleRef.Length - $TitleL2.Length
$Title = $TitleRef + "`n" + " " * ($TitleDiff / 2) + $TitleL2 + " " * ($TitleDiff / 2)
$Title = "`n" + " " * $ExtraLine + "`n" + $Title + "`n" + " " * $ExtraLine
Write-Host -BackgroundColor DarkGreen -ForegroundColor Green $Title
#endregion
#region begin Traitement ISO parameter
# Si l'utisateur utilise la fonction sans préciser l'iso, alors lui demander d'entrer le chemin
if (!$Path) {
Write-Host -ForegroundColor Green "`n `n`tVeuillez entrer ci-dessous le chemin de l'ISO d'installation de Windows:"
$Path = Read-Host "`t`n`tTapez [ENTRÉE] pour valider"
# Tester la validité du chemin entrée (il doit exister et avoir l'extension ISO)
#cls
If (($Path -like '*.iso') -and (Test-Path -PathType Leaf -LiteralPath $Path)) {
Write-Host -ForegroundColor Green "`n `n`tFichier ISO à examiner :"
Write-Host -ForegroundColor Cyan "`n`t`"$Path`"`n"
}
else {
# s'il est invalide, arrêter le script
Write-Host -BackgroundColor Red -ForegroundColor Yellow "`n`tLe chemin entré est invalide :`t`t`t`t`t"
Write-Host -ForegroundColor Cyan "`n`t`"$Path`""
Write-Host -BackgroundColor Red -ForegroundColor Yellow "`n`tIl doit pointer vers un fichier ISO existant. `t`n`tVeuillez relancer le script manuellement.`t`t`n"
Break
}
}
# Si le chemin était passé en paramètre, tester la validité du chemin entrée (il doit exister et avoir l'extension ISO)
else {
#cls
If (($Path -like '*.iso') -and (Test-Path -PathType Leaf -LiteralPath $Path)) {
Write-Host -ForegroundColor Green "`n `n`tFichier ISO à examiner :"
Write-Host -ForegroundColor Cyan "`n`t`"$Path`"`n"
}
else {
# s'il est invalide, demander à l'utilisateur de l'entrer manuellement
Write-Host -BackgroundColor Red -ForegroundColor Yellow "`n`n`n`t`t`tLe chemin passé en paramètre de -iso est invalide :`t`t`t`t`t"
Write-Host -ForegroundColor Green "`n`tVeuillez entrer ci-dessous le chemin de l'ISO d'installation de Windows:"
$Path = Read-Host "`t`n`tTapez [ENTRÉE] pour valider"
# Tester la validité du chemin entrée (il doit exister et avoir l'extension ISO)
Clear-Host
If (($Path -like '*.iso') -and (Test-Path -PathType Leaf -LiteralPath $Path)) {
Write-Host -ForegroundColor Green "`n `n`tFichier ISO à examiner :"
Write-Host -ForegroundColor Cyan "`n`t`"$Path`"`n"
}
else {
# s'il est invalide, arrêter le script
Write-Host -BackgroundColor Red -ForegroundColor Yellow "`n`tLe chemin entré est invalide :`t`t`t`t`t"
Write-Host -ForegroundColor Cyan "`n`t`"$Path`""
Write-Host -BackgroundColor Red -ForegroundColor Yellow "`n`tIl doit pointer vers un fichier ISO existant. `t`n`tVeuillez relancer le script manuellement.`t`t`n"
Break
}
}
}
#endregion
#region begin Traitement de l'image ISO
# On monte l'image
Mount-DiskImage -ImagePath "$Path"
$ISOmount = Get-DiskImage $Path
# Si l'ISO ne peut être monté, fin du script
if ($ISOmount.Attached -ne "True") { throw "Impossible de monter le fichier ISO" }
# Récupérer la lettre du volume où l'image est montée
$ISOdriveLetter = (Get-Volume -DiskImage $ISOmount).DriveLetter
$wimPath = $ISOdriveLetter + ":"
# On en déduit le chemin complet vers l'image wim à traiter dont le traitement varie selon le type
Switch ($wimPath) {
{ (Test-Path "$wimPath\sources\install.wim") -or (Test-Path "$wimPath\sources\install.esd") } {
if (Test-Path "$wimPath\sources\install.wim") {
$wimPath = "$wimPath\sources\install.wim"
}
else { $wimPath = "$wimPath\sources\install.esd" }
Write-Host -ForegroundColor Green "`n`tImage détectée dans l'ISO :"
Write-Host -ForegroundColor Cyan "`n`t$wimPath"
Write-Host -ForegroundColor Green "`n `n`tContenu de l'ISO :"
$ImgInfo = DISM.exe /Get-WimInfo /WimFile:$wimPath
$ImgInfo # affichage des versions contenues dans l'image
# Pour chaque version trouvée dans l'image, afficher ses détails
Write-Host -ForegroundColor Green "`n `n`tDétails des installations possibles :"
$count = 0
Foreach ($item in $ImgInfo) {
# parcourt chaque ligne retournée par "DISM.exe /Get-ImageInfo /ImageFile:$wimPath"
if ($item.indexof("Index") -eq 0 ) {
# dès que le mot "Index" est trouvé en début de ligne…
$count ++ # on incrémente $count et on affiche les détails de chaque version de windows
DISM.exe /Get-WimInfo /WimFile:$wimPath /index:$count
Write-Host -ForegroundColor Green $("`n" + "=" * 80)
}
}
#Write-Host -ForegroundColor Green "`n`count : $Count"
break
}
{ (Test-Path "$wimPath\x86\sources\install.esd") -or (Test-Path "$wimPath\x86\sources\install.wim") } {
if (Test-Path "$wimPath\x86\sources\install.esd") {
$wimPath86 = "$wimPath\x86\sources\install.esd"
$wimPath64 = "$wimPath\x64\sources\install.esd"
}
else { $wimPath86 = "$wimPath\sources\install.wim"; $wimPath64 = "$wimPath\x64\sources\install.wim" }
Write-Host -ForegroundColor Magenta "`n`tCette installation contient les variantes x86 et x64`n`n"
Write-Host -ForegroundColor Green "`n`tImage X86 détectée dans l'ISO :"
Write-Host -ForegroundColor Cyan "`n`t$wimPath86"
Write-Host -ForegroundColor Green "`n `n`tContenu de l'ISO :"
$ImgInfo = DISM.exe /Get-WimInfo /WimFile:$wimPath86
$ImgInfo # affichage des versions contenues dans l'image
# Pour chaque version trouvée dans l'image, afficher ses détails
Write-Host -ForegroundColor Green "`n `n`tDétails des installations possibles :"
$count = 0
Foreach ($item in $ImgInfo) {
# parcourt chaque ligne retournée par "DISM.exe /Get-ImageInfo /ImageFile:$wimPath"
if ($item.indexof("Index") -eq 0 ) {
# dès que le mot "Index" est trouvé en début de ligne…
$count ++ # on incrémente $count et on affiche les détails de chaque version de windows
DISM.exe /Get-WimInfo /WimFile:$wimPath86 /index:$count
Write-Host -ForegroundColor Green $("`n" + "=" * 80)
}
}
Write-Host -ForegroundColor Green "`n`tImage X64 détectée dans l'ISO :"
Write-Host -ForegroundColor Cyan "`n`t$wimPath64"
Write-Host -ForegroundColor Green "`n `n`tContenu de l'ISO :"
$ImgInfo = DISM.exe /Get-WimInfo /WimFile:$wimPath64
$ImgInfo # affichage des versions contenues dans l'image
# Pour chaque version trouvée dans l'image, afficher ses détails
Write-Host -ForegroundColor Green "`n `n`tDétails des installations possibles :"
$count = 0
Foreach ($item in $ImgInfo) {
# parcourt chaque ligne retournée par "DISM.exe /Get-ImageInfo /ImageFile:$wimPath"
if ($item.indexof("Index") -eq 0 ) {
# dès que le mot "Index" est trouvé en début de ligne…
$count ++ # on incrémente $count et on affiche les détails de chaque version de windows
DISM.exe /Get-WimInfo /WimFile:$wimPath64 /index:$count
Write-Host -ForegroundColor Green $("`n" + "=" * 80)
}
}
break
}
default { Write-Host "Aucune image valide trouvée dans l'ISO" }
}
# On peut démonter l'image
Dismount-DiskImage -ImagePath "$Path"
# Message de fin de traitement
$EndMsg = "TRAITEMENT TERMINÉ"
$EndMsgDiff = $TitleRef.Length - $EndMsg.Length
$EndMsg = " " * ($EndMsgDiff / 2) + $EndMsg + " " * ($EndMsgDiff / 2)
$EndMsg = "`n" + " " * $ExtraLine + "`n" + $EndMsg + "`n" + " " * $ExtraLine
Write-Host -BackgroundColor DarkGreen -ForegroundColor Green $EndMsg
#endregion
}
} # End Function
WinIsoInfo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment