Skip to content

Instantly share code, notes, and snippets.

@sundmoon
Last active March 27, 2017 22:26
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 sundmoon/48556af0556d96bbddb06ee2f91864eb to your computer and use it in GitHub Desktop.
Save sundmoon/48556af0556d96bbddb06ee2f91864eb to your computer and use it in GitHub Desktop.
Get-ISOInfo
```powershell
# Source path for Windows ISO files
$ISOPath = 'F:\__WINDISTR'
$MountFolder = 'F:\Mount'
if (!(Test-Path -Path $ISOPath))
{
Write-Warning -Message "Could not find ISO store at $ISOPath. Aborting..."
Break
}
if (!(Test-Path -Path $MountFolder))
{
New-Item $MountFolder -ItemType Directory
}
else
{
if ((Get-ChildItem $MountFolder).count -ne 0)
{
Write-Warning -Message "Mount folder $MountFolder should be empty. Aborting..."
Break
}
}
$ISO = Get-ChildItem $ISOPath -Recurse -Filter *.iso
#best effort to parse conventional iso names for meaningful tokens, may not match all possible iso names
function Get-ISOTokens {
param (
[string]$FullName
)
#you may add your languages here or amend the logic to encompass more complex variants
$Language = switch -regex ($FullName) {
'\\en_windows_|_English_' {'English'}
'\\ru_windows_|_Russian_' {'Russian'}
default {'Unknown/Custom'}
}
#extracting 5 or more sequential digits
[regex]$rx='\d{5,}'
$Build = $rx.Match($FullName).value
#mining for Arch
$x64 = $FullName -match 'x64' -or $FullName -match '64BIT'
$x32 = $FullName -match 'x32' -or $FullName -match 'x86' -or $FullName -match '32BIT'
If ($x64 -and $x32) {
$Arch = 'x32_x64'
} elseif ($x64) {
$Arch = 'x64'
} elseif ($x32) {
$Arch = 'x32'
}
@{
Language = $Language
Arch = $Arch
Build = $Build
}
}
function Get-ISOInfo
{
[cmdletbinding()]
param (
[Parameter(Mandatory = $true,
ValueFromPipeline = $true)]
[System.IO.FileInfo[]]$ISO
)
process {
Mount-DiskImage -ImagePath $PSItem.FullName
$ISOImage = Get-DiskImage -ImagePath $PSItem.fullname | Get-Volume
$ISODrive = [string]$ISOImage.DriveLetter+':'
$InstallImage = "$ISODrive\sources\install.wim"
if (!(Test-Path -Path $InstallImage ))
{
Write-Warning -Message "Could not find install.wim in $PSItem.FullName"
}
else
{
Write-Verbose -Message "Processing $PSItem"
#assuming wim image format, don't mess with esd, swm etc. for now
$images = Get-WindowsImage -ImagePath $ISODrive\sources\install.wim
Write-Verbose -Message "Images count: $($images.count)"
$tokens = Get-ISOTokens $PSItem.FullName
foreach ($image in $images)
{
[PSCustomObject]@{
'FullName' = $PSItem.FullName
#'ISOLanguage' = (Get-ISOLanguage $PSItem.FullName)
'ISOLanguage' = $tokens['Language']
'ISOArch' = $tokens['Arch']
'ISOBuild' = $tokens['Build']
'ImageIndex' = $image.ImageIndex
'ImageName' = $image.ImageName
'ImageDescription' = $image.ImageDescription
'ImageSize' = $image.ImageSize
}
}
}
Dismount-DiskImage -ImagePath $PSItem.fullname
}
}
$ISO | Get-ISOInfo -Verbose | fl *
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment