Advertisement
Wasif_Hasan_

WIMInfoInstall.ps1

Aug 13th, 2020
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # WIMInfoInstall.ps1
  2. # This will install a context menu named "WIM Information" on .wim files
  3. # Clicking it will show a GUI grid view with a lot of information on it
  4.  
  5. $currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
  6. if( -not ($currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)))
  7. {
  8.     Write-Host "Running Admin Shell, Please wait....."
  9.     Start-Sleep -Seconds 1
  10.     Start-Process powershell.exe -ArgumentList "-ExecutionPolicy Bypass -File `"$($MyInvocation.MyCommand.Path)`"" -Verb RunAs
  11.     Exit
  12. }
  13.  
  14. function Install {
  15. If(-not (Test-Path C:\bin)){New-Item C:\bin -Type Directory}
  16. @'
  17. Param([string]$WimFile)
  18. $currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
  19. if( -not ($currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)))
  20. {
  21.    Write-Host "Running Admin Shell, Please wait....."
  22.    Start-Sleep -Seconds 1
  23.    Start-Process powershell.exe -ArgumentList "-WindowStyle Hidden -ExecutionPolicy Bypass -File `"$($MyInvocation.MyCommand.Path)`" `"$($WimFile)`"" -Verb RunAs
  24.    Exit 0
  25. }
  26. New-Item C:\bin.csv -Type File | Out-Null
  27. $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]
  28. 0..($TIndex) | Foreach {
  29.  $kv = dism /get-wiminfo /wimfile:"$WimFile" /index:$_ | Select-String -Pattern '(.*)\s:\s(.*)'
  30.  $rep = $kv -replace '^(.*)\s+:\s+(.*)','"$1"="$2"'
  31.  $rep = $rep -join ";"
  32.  $kep = Invoke-Expression "[pscustomobject][ordered]@{$($rep)}"
  33.  $kep | ConvertTo-Csv -NoTypeInformation | Add-Content C:\bin.csv
  34. }
  35. 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)"
  36. Remove-Item C:\bin.csv
  37. Read-Host
  38. '@ | Set-Content C:\bin\wiminf.ps1
  39. @'
  40. Windows Registry Editor Version 5.00
  41.  
  42. [HKEY_CLASSES_ROOT\.wim\shell\WIMInfo]
  43. "MUIVerb"="WIM Information"
  44. "Icon"="C:\\Windows\\HelpPane.exe"
  45.  
  46. [HKEY_CLASSES_ROOT\.wim\shell\WIMInfo\command]
  47. @="powershell -file C:\\bin\\wiminf.ps1 \"%1\""
  48. '@ | Set-Content C:\bin\wimsav.reg
  49. regedit /s C:\bin\wimsav.reg
  50. }
  51.  
  52. function Uninstall {
  53. Remove-Item "REGISTRY::HKEY_CLASSES_ROOT\.wim\shell\WIMInfo" -Recurse
  54. Remove-Item C:\bin\wiminf.ps1
  55. Remove-Item C:\bin\wimsav.reg
  56. }
  57.  
  58. [Console]::WindowWidth = 192
  59. [Console]::Title = "WIMInfo Installer"
  60. @'
  61. ################################################################################################################################################################
  62.                                                                  WIMInfo Installer
  63.                       This Powershell script will install a context menu on .wim files
  64.                       When you right-click it you will get a button named "WIM Information"
  65.                       That will show information for the WIM Files
  66. ################################################################################################################################################################
  67. '@
  68. $msg = @'
  69.  
  70. [1] Install
  71. [2] Repair
  72. [3] Uninstall
  73.  
  74. '@
  75. choice /c 123 /n /m $msg
  76. switch ($LastExitCode) {
  77. 1 {Install}
  78. 2 {Install}
  79. 3 {Uninstall}
  80. }
  81.  
  82. Write-Host "`nDone!"
  83. Read-Host
  84.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement