Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # WIMInfoInstall.ps1
- # This will install a context menu named "WIM Information" on .wim files
- # Clicking it will show a GUI grid view with a lot of information on it
- $currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
- if( -not ($currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)))
- {
- Write-Host "Running Admin Shell, Please wait....."
- Start-Sleep -Seconds 1
- Start-Process powershell.exe -ArgumentList "-ExecutionPolicy Bypass -File `"$($MyInvocation.MyCommand.Path)`"" -Verb RunAs
- Exit
- }
- function Install {
- If(-not (Test-Path C:\bin)){New-Item C:\bin -Type Directory}
- @'
- Param([string]$WimFile)
- $currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
- if( -not ($currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)))
- {
- Write-Host "Running Admin Shell, Please wait....."
- Start-Sleep -Seconds 1
- Start-Process powershell.exe -ArgumentList "-WindowStyle Hidden -ExecutionPolicy Bypass -File `"$($MyInvocation.MyCommand.Path)`" `"$($WimFile)`"" -Verb RunAs
- Exit 0
- }
- New-Item C:\bin.csv -Type File | Out-Null
- $TIndex = ((dism /get-wiminfo /wimfile:"$WimFile" | Select-String "Index : (.*)").Matches.Groups.Value)[((dism /get-wiminfo /wimfile:"$WimFile" | Select-String "Index : (.*)").Matches.Groups.Value).Length-1]
- 0..($TIndex) | Foreach {
- $kv = dism /get-wiminfo /wimfile:"$WimFile" /index:$_ | Select-String -Pattern '(.*)\s:\s(.*)'
- $rep = $kv -replace '^(.*)\s+:\s+(.*)','"$1"="$2"'
- $rep = $rep -join ";"
- $kep = Invoke-Expression "[pscustomobject][ordered]@{$($rep)}"
- $kep | ConvertTo-Csv -NoTypeInformation | Add-Content C:\bin.csv
- }
- Import-Csv C:\bin.csv | Where-Object {$_.Index -in 0..$($TIndex)} | Select-Object Index,Name,Description,Edition,Architecture,@{n='Bootable';e={$_.'WIM Bootable'}},@{n='Size';e={[string]([math]::Round((($_.Size.ToString().Split(" ")[0].split(",") -join "")/1024/1024/1024),2)) + " GB"}},@{n='HAL';e={$_.HAL}},Version,@{n='Major';e={$_.Version.Split(".")[0]}},@{n='Minor';e={$_.Version.Split(".")[1]}},@{n='Build';e={$_.Version.Split(".")[2]}},@{n='Service Pack Build';e={$_.'ServicePack Build'}},@{n='Service Pack Level';e={$_.'ServicePack Level'}},@{n='Installation Type';e={$_.Installation}},@{n='Product Type';e={$_.ProductType}},@{n='Product Suite';e={$_.ProductSuite}},@{n='Installation Directory';e={$_.'System Root'}},Directories,Files,@{n='Date Created';e={$_.Created}},@{n='Last Modified';e={$_.Modified}} | Out-GridView -Title "WIM Information for $($WimFile)"
- Remove-Item C:\bin.csv
- Read-Host
- '@ | Set-Content C:\bin\wiminf.ps1
- @'
- Windows Registry Editor Version 5.00
- [HKEY_CLASSES_ROOT\.wim\shell\WIMInfo]
- "MUIVerb"="WIM Information"
- "Icon"="C:\\Windows\\HelpPane.exe"
- [HKEY_CLASSES_ROOT\.wim\shell\WIMInfo\command]
- @="powershell -file C:\\bin\\wiminf.ps1 \"%1\""
- '@ | Set-Content C:\bin\wimsav.reg
- regedit /s C:\bin\wimsav.reg
- }
- function Uninstall {
- Remove-Item "REGISTRY::HKEY_CLASSES_ROOT\.wim\shell\WIMInfo" -Recurse
- Remove-Item C:\bin\wiminf.ps1
- Remove-Item C:\bin\wimsav.reg
- }
- [Console]::WindowWidth = 192
- [Console]::Title = "WIMInfo Installer"
- @'
- ################################################################################################################################################################
- WIMInfo Installer
- This Powershell script will install a context menu on .wim files
- When you right-click it you will get a button named "WIM Information"
- That will show information for the WIM Files
- ################################################################################################################################################################
- '@
- $msg = @'
- [1] Install
- [2] Repair
- [3] Uninstall
- '@
- choice /c 123 /n /m $msg
- switch ($LastExitCode) {
- 1 {Install}
- 2 {Install}
- 3 {Uninstall}
- }
- Write-Host "`nDone!"
- Read-Host
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement