⬆️ ⬇️

Script for obtaining information from a Windows image

I have a series of articles on the topic of servicing Windows images by the DISM system teams. In my articles, examples of scripts in the command interpreter language cmd.exe were given . As a result of the work, the original Windows image (live system or stand-alone * .wim file) was changed - updates were integrated into it, system components were disabled, universal applications were removed. But how to see the changes in the image? In this article, I present a script that, using DISM commands, extracts various information from a Windows image and displays it to the user on the screen, or exports it to a file.



This script will be useful for system administrators who create their own “builds” or test others. Sometimes it may be necessary to look at some information about the installed OS - in this case this script is also useful. All DISM commands for obtaining information from a Windows image are implemented in this script. Information from the image that can be obtained using this script:





An aspect of information is indicated in brackets. If a certain type of objects can be added or removed from the image, then the information will show the presence of objects of this type in the image. If some property of the operating system can be switched in the image (for example, enabled / disabled), then the information will display the status of this property. The last two items in the list are available only on OS starting with Windows 8. I called this script GetWimInfo.cmd , here it is:



Script



@echo off title Getting information from Windows image set _file=install.wim set _img=Online set _mnt=mount set _tool=7 set _word=Wim ver | find "6.1" > nul || set _tool=8 if %_tool% GTR 7 set _word=Image :pre_menu cls if not exist %_file% goto :adv_menu dism /English /LogLevel:1 /Get-%_word%Info /%_word%File:%_file% echo ------------------------------------------------------------------------------- if %ERRORLEVEL% NEQ 0 pause & exit set /p _ind=Input index or press [Enter] for quit: || exit if %_ind% EQU 0 goto :adv_menu if %_ind% GTR 0 if %_ind% LEQ 24 goto :ind_menu goto :pre_menu :ind_menu cls dism /English /LogLevel:1 /Get-%_word%Info /%_word%File:%_file% /Index:%_ind% echo ------------------------------------------------------------------------------- if %ERRORLEVEL% NEQ 0 pause & goto :pre_menu choice /c abcdefghijklmnopqrstuvwxyz /n /m "Mount selected image? [m] " if %ERRORLEVEL% EQU 13 goto :mount goto :pre_menu :adv_menu cls if %_img%==Online (echo DISM: Online Servicing)^ else (dism /English /LogLevel:1 /Get-Mounted%_word%Info) echo ------------------------------------------------------------------------------- echo ~~~~Menu~~~~ echo [d] drivers ([D] - export) echo [p] packages ([P] - export) echo [f] features ([F] - export) echo [l] languages echo [e] editions echo [a] app if %_tool% GTR 7 echo [x] appx ([X] - export) if %_tool% GTR 7 echo [s] assoc ([S] - export) echo [q] quit (unmount) echo ------------------------------------------------------------------------------- choice /c dDpPfFleaxXsSq /n /cs /m "Your choice: " if %ERRORLEVEL% EQU 1 goto :drivers if %ERRORLEVEL% EQU 2 goto :drivers-export if %ERRORLEVEL% EQU 3 goto :packages if %ERRORLEVEL% EQU 4 goto :packages-export if %ERRORLEVEL% EQU 5 goto :features if %ERRORLEVEL% EQU 6 goto :features-export if %ERRORLEVEL% EQU 7 goto :languages if %ERRORLEVEL% EQU 8 goto :editions if %ERRORLEVEL% EQU 9 goto :app if %ERRORLEVEL% EQU 10 if %_tool% GTR 7 (goto :appx) else (goto :adv_menu) if %ERRORLEVEL% EQU 11 if %_tool% GTR 7 (goto :appx-export) else (goto :adv_menu) if %ERRORLEVEL% EQU 12 if %_tool% GTR 7 (goto :assoc) else (goto :adv_menu) if %ERRORLEVEL% EQU 13 if %_tool% GTR 7 (goto :assoc-export) else (goto :adv_menu) goto :unmount :drivers cls dism /%_img% /English /LogLevel:1 /Get-Drivers /All | more echo ------------------------------------------------------------------------------- choice /cb /n /m "Back [b] " goto :adv_menu :drivers-export cls if exist drivers%_numd%.txt set /a _numd+=1 & goto :drivers-export echo Getting list of drivers. Please wait... dism /%_img% /English /LogLevel:1 /Get-Drivers /All /Format:Table > drivers%_numd%.txt goto :adv_menu :packages cls dism /%_img% /English /LogLevel:1 /Get-Packages | more echo ------------------------------------------------------------------------------- choice /cb /n /m "Back [b] " goto :adv_menu :packages-export cls if exist packages%_nump%.txt set /a _nump+=1 & goto :packages-export echo Getting list of packages. Please wait... dism /%_img% /English /LogLevel:1 /Get-Packages /Format:Table > packages%_nump%.txt goto :adv_menu :features cls dism /%_img% /English /LogLevel:1 /Get-Features | more echo ------------------------------------------------------------------------------- choice /cb /n /m "Back [b] " goto :adv_menu :features-export cls if exist features%_numf%.txt set /a _numf+=1 & goto :features-export echo Getting list of features. Please wait... dism /%_img% /English /LogLevel:1 /Get-Features /Format:Table > features%_numf%.txt goto :adv_menu :languages cls dism /%_img% /English /LogLevel:1 /Get-Intl echo ------------------------------------------------------------------------------- choice /cb /n /m "Back [b] " goto :adv_menu :editions cls dism /%_img% /English /LogLevel:1 /Get-CurrentEdition echo ------------------------------------------------------------------------------- dism /%_img% /English /LogLevel:1 /Get-TargetEditions echo ------------------------------------------------------------------------------- choice /cb /n /m "Back [b] " goto :adv_menu :app cls if %_img%==Online goto :adv_menu dism /%_img% /English /LogLevel:1 /Get-Apps echo ------------------------------------------------------------------------------- dism /%_img% /English /LogLevel:1 /Get-AppPatches echo ------------------------------------------------------------------------------- choice /cb /n /m "Back [b] " goto :adv_menu :appx cls dism /%_img% /English /LogLevel:1 /Get-ProvisionedAppxPackages | more echo ------------------------------------------------------------------------------- choice /cb /n /m "Back [b] " goto :adv_menu :appx-export cls if exist appxes%_numx%.txt set /a _numx+=1 & goto :appx-export echo Getting list of appx. Please wait... dism /%_img% /English /LogLevel:1 /Get-ProvisionedAppxPackages > appxes%_numx%.txt goto :adv_menu :assoc cls dism /%_img% /English /LogLevel:1 /Get-DefaultAppAssociations | more echo ------------------------------------------------------------------------------- choice /cb /n /m "Back [b] " goto :adv_menu :assoc-export cls if exist associat%_nums%.txt set /a _nums+=1 & goto :assoc-export echo Getting list of assoc. Please wait... dism /%_img% /English /LogLevel:1 /Get-DefaultAppAssociations > associat%_nums%.txt goto :adv_menu :mount cls md %_mnt% dism /English /LogLevel:1 /Mount-%_word% /%_word%File:%_file% /Index:%_ind% /MountDir:%_mnt% /ReadOnly if %ERRORLEVEL% NEQ 0 rd %_mnt% & pause & exit set _img=Image:%_mnt% goto :adv_menu :unmount cls if not exist %_file% exit if not %_img%==Online ( dism /English /LogLevel:1 /Unmount-%_word% /MountDir:%_mnt% /Discard rd %_mnt% ) set _img=Online goto :pre_menu 


Using



If the startup folder of the script contains an autonomous Windows operating system image - install.wim , then information about the available indexes is requested from it and the user is prompted to enter the number with which the work will be performed. In the next submenu of the selected index, the extended information is displayed and the user is prompted to mount this image to continue. After the image is mounted, the main script menu is displayed on the screen. If there is no install.wim file in the script launch folder, then immediately go to the main menu, and information requests will be sent to the current OS. Working with the main menu is very simple - just press the corresponding key to display information on the screen. For some items, the amount of data may be large, so items have been added for exporting information to the created text file in the script launch folder. Export to file is an uppercase letter.

')

Parsing code



At first, the set command sets the variables. You can change the estimated name of the install.wim image file (for example, to install.esd). You can change the name of the mount folder (by default, mount) or set the path if the mount folder should be outside of the launch folder.
Also, at first, the OS version on which the script is launched is determined, by logic - if not Windows 7, then something newer. Based on this, it is concluded which version of the DISM system will accept script commands, which affects the accessibility of the last two menu items.



: pre_menu



Preliminary menu. Getting basic information about wim file with error checking. If there is no image file, then run in online mode.


: ind_menu



Index menu. Obtaining extended information about the selected "index" in a wim file with error control. Offer to mount the "index".


: adv_menu



The main (extended) menu script. After pressing the key corresponding to the selected item, a transition takes place to the corresponding label in the script body, then following the required commands and returning to this menu. All items display information on the screen of the same type and include some command DISM. No need to disassemble them. Than the display of information on the screen of greater interest is the export to a text file. Information is recorded in tabular form, which is convenient for perception and comparison. For each type of information - a text file with a specific name. Repeated export on some item does not replace the file, but creates a new one, adding a numeric index to the name. This is useful when collecting information from several different image indices, for example.



: mount



Mounting image Pre-created mount folder. Error control. The variable defining the specification of the image changes, now points to the path to the autonomous image.
I also note that the mount is performed in the / ReadOnly mode, which means that it is not possible to make any changes to the image, including the dates and attributes of the image file.



: unmount



Unmounting an image. If online maintenance was performed (/ Online), then it is not necessary to unmount it. Return of variables to initial values.


Unmount with the / Discard key, since the mount was read-only. Missing key is unacceptable.



Conclusion



This script is a logical addition to the collection of scripts presented by me in previous articles. Although, in truth, all this was written more than three months ago, and this script was my first. Just gradually open the cards. Of course, many system administrators have long written such solutions for themselves and each has its own. Other people's work seemed uncomfortable, in some cases cumbersome. Someone tried to implement all the capabilities of the DISM system in one “mega” script, I decided to make several scripts, each for a specific task. Probably not very good that some code is repeated, because when implementing some ideas and / or correcting errors, I had to edit all the files at once. Advertisers PowerShell pass by. I wrote this script for myself and decided to share it with you the way it is. I hope it will be useful to many - both for work and as an example in study.

Source: https://habr.com/ru/post/349894/



All Articles