Skip to content

Commit

Permalink
Version 3.1.0 (2024-11-15)
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidGeeraerts committed Nov 15, 2024
1 parent d9d11bc commit b5128c0
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 81 deletions.
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
tools
cache

# Ignore files
# Ignore general files

*_dev.cmd
*.backup
*.old
*.old

# Ignore specific files
Notes_Windows_Appx_Package_CleanUp.txt
18 changes: 15 additions & 3 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,27 @@
[//]: # (#### Deprecated)

---
## Version 3.1.0 (2024-11-15)
#### Added
- sets the local user to first logged on user
- debug variable for log output
- console output for local user

#### Changed
- not KB list is now read from [file](config/Windows_Update_KB_List.txt)
- $CONFIG_SCHEMA_VERSION_MIN to 3.1.0
- - path to $APPX_LIST

## Version 3.0.2 (2024-11-14)
#### Fixed
- APPX Package removal
- path to $APPX_LIST

---


## Version 3.0.2 (2024-11-14)
#### Fixed
- APPX Package removal
- path to $APPX_LIST

## Version 3.0.1 (2024-11-14)
#### Fixed
- Ability to rerun APPX package removal
Expand Down
60 changes: 40 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,23 @@

### :page_with_curl: Description

Please refer to [Microsoft documentation on sysprep](https://learn.microsoft.com/en-us/windows-hardware/manufacture/desktop/sysprep--system-preparation--overview?view=windows-11).

Version 3 is a complete rewrite of the program.
It's now interactive, and you can choose what you want to do.
Automated processing of SysPrep.
It's now a menu driven interactive program, so you can choose what you want to do.
Automated processing of SysPrep for Windows 10 & 11; should work for Windows server that have only run basic Windows setup.
Log files will be stored where the program was executed from.


### :arrow_down: Download

Download the project as .zip file from [releases](https://github.com/DavidGeeraerts/module_system_SysPrep/releases/)
Download the project as .zip file from [releases](https://github.com/DavidGeeraerts/module_system_SysPrep/releases/latest)


## :white_check_mark: Process List

<img src="/images/Main_menu.png" alt="Main menu" title="module_system_sysprep main menu" width="500" height="500"/>

:one: Configure the local administrator

- This will enable and set a blank password for the local administrator account.
Expand All @@ -44,7 +48,7 @@ Download the project as .zip file from [releases](https://github.com/DavidGeerae

- Removes [APPX](https://learn.microsoft.com/en-us/powershell/module/appx/get-appxpackage?view=windowsserver2022-ps) packages that are known to break sysprep

- Add APPX packages to the list in this [file:](./config/APPX_List.txt)
- Add APPX packages to the list in this [file:](./config/APPX_List.txt) `APPX_List.txt`

- APPX packages can be added back after image depployment.

Expand All @@ -53,7 +57,7 @@ Download the project as .zip file from [releases](https://github.com/DavidGeerae

- Process windows updates via powershell [PSWindowsUpdate](https://www.powershellgallery.com/packages/PSWindowsUpdate) module

- Can exclude KB's in the [config file](./config/module_system_SysPrep.properties)
- Can exclude KB's in the [properties file](./config/module_system_SysPrep.properties)

:six: Disk Check, for dirty bit

Expand All @@ -69,6 +73,8 @@ Download the project as .zip file from [releases](https://github.com/DavidGeerae

- Checks to see if bitlocker is on for an encrypted system volume, and if so, it will unencrpyt to prepare for iamge capture.

- "If you run Sysprep on an NTFS file system partition that contains encrypted files or folders, the data in those folders becomes completely unreadable and unrecoverable."

- Uses [manange-bde](https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/manage-bde)


Expand All @@ -79,7 +85,17 @@ Download the project as .zip file from [releases](https://github.com/DavidGeerae

:zero: SysPrep

- Everything you need to know about [Sysprep](https://learn.microsoft.com/en-us/windows-hardware/manufacture/desktop/sysprep--system-preparation--overview?view=windows-11). A.k.a, read the documentation.
- Everything you need to know about [Sysprep](https://learn.microsoft.com/en-us/windows-hardware/manufacture/desktop/sysprep--system-preparation--overview?view=windows-11).

#### Sysprep process overview

When Sysprep runs, it goes through the following process:

1. Sysprep verification. Verifies that Sysprep can run. Only an administrator can run Sysprep. Only one instance of Sysprep can run at a time. Also, Sysprep must run on the version of Windows that you used to install Sysprep.
2. Logging initialization. Initializes logging. For more information, see Sysprep Log Files.
3. Parsing command-line arguments. Parses command-line arguments. If a user does not provide command-line arguments, a System Preparation Tool window appears and enables users to specify Sysprep actions.
4. Processing Sysprep actions. Processes Sysprep actions, calls appropriate .dll files and executable files, and adds actions to the log file.
5. Verifying Sysprep processing actions. Verifies that all .dll files have processed all their tasks, and then either shuts down or restarts the system.


### :green_book: Instructions
Expand All @@ -92,6 +108,17 @@ Each sysprep run on a computer will be saved to its own directory.
- Pass the config file name as a parameter if not using the default config.
- default `module_system_SysPrep.properties`

#### :incoming_envelope: Passing Config file as Paramter

- Open shell/terminal with administrative privilege
- cd /D to module directory where module_system_SysPrep.cmd
- Pass config file name if not the default `module_system_SysPrep.properties`
- Can have different properties files for different systems, then just pass the [custom] properties file as a parameter.

Example:

- `module_system_SysPrep.cmd` `Custom.properties`

Most basic would do the following:
- Configure the local administrator and log out current user, which should be the unattend.xml first logon user.
- Log in with local Administrator account --no password. This will be automatic.
Expand All @@ -100,27 +127,20 @@ Most basic would do the following:

#### :orange_book: Dependencies

- Must be run with local Administrator account -- which is why it gets activated.
- cmd
- Powershell


#### :incoming_envelope: Passing Config file as Paramter

- Open shell/terminal with administrative privilege
- cd /D to module directory where module_system_SysPrep.cmd
- Pass config file name if not the default `module_system_SysPrep.properties`
- Can have different properties files for different systems, then just pass the [custom] properties file as a parameter.


Example:

- `module_system_SysPrep.cmd` `Custom.config`
- You must run Windows Setup before you use Sysprep.
- You need a tool to capture an image of the installation, such as DISM - Deployment Image Servicing and Management Technical Reference for Windows or other disk-imaging software.
- [CloneZilla](https://clonezilla.org/) is recommended if not using DISM


##### :notebook: Notes (recent to old)

- Windows 8.1 and Windows Server 2012 or later, can sysprep up to 1001 times
- Sysprep cannot be run under the context of a System account. Running Sysprep under the context of System account by using Task Scheduler or PSExec, for example, is not supported.
- Remove APPX packages before deleting the local user used in unattend.xml
- Looks for APPX packages that are known to break SysPrep in Window 11
- Removes APPX packages that are known to break SysPrep in Window 10/11.
- [Microsoft has deprecated the GUI for SysPrep since Windows 8.1](https://docs.microsoft.com/en-us/windows-hardware/manufacture/desktop/sysprep--system-preparation--overview)
- SysPrep must be run with administrative privilege
- module_system_SysPrep logs will be saved here for archive:
Expand Down
24 changes: 0 additions & 24 deletions config/Windows_Appx_Package_CleanUp.txt

This file was deleted.

1 change: 1 addition & 0 deletions config/Windows_Update_KB_List.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
KB4481252
15 changes: 9 additions & 6 deletions config/module_system_SysPrep.properties
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ notes:
###############################################################################
# Schema version for the configuration file
###############################################################################
$CONFIG_SCHEMA_VERSION=3.0.0

$CONFIG_SCHEMA_VERSION=3.1.0
###############################################################################

---
Expand All @@ -35,6 +34,7 @@ $CONFIG_SCHEMA_VERSION=3.0.0

# Flushes the default user that is logged in
# default user from unattend file
# can leave blank as it will get picked up based on user logged in.
$LOCAL_USER=Scientific

# [DELETE] Scheduled Task keyword search
Expand All @@ -47,13 +47,13 @@ $KEYWORD_SCHEDULED_TASK=OneDrive

# [DELETE] Microsoft APPX Packages
# File that contains a list of APPX packages to delete using keywords
$KEYWORD_APPX_FILE=config\Microsoft_APPX_List.txt
$APPX_LIST=APPX_List.txt

# Windows Update via powershell, KB exclusion
# NotKBArticleID with space between KB's
# E.g. $NotKBArticleID=KB4481252 KB4481252
# NotKBArticleFile with space between KB's
# E.g. KB4481252 KB4481252
# KB4481252 = SilverLight
$NotKBArticleID=KB4481252
$NotKBArticleID=Windows_Update_KB_List.txt


# Use Unatand.xml for SysPrep
Expand Down Expand Up @@ -89,6 +89,9 @@ $TIMEOUT=5
# *******************
#############################################################################

# Turn on [1] or off [0]
$DEGUB=0

# Log Directory
$LD=logs

Expand Down
Binary file added images/Main_menu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
76 changes: 50 additions & 26 deletions module_system_SysPrep.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
@echo Off
SETLOCAL Enableextensions
SET $SCRIPT_NAME=module_system_SysPrep
SET $SCRIPT_VERSION=3.0.2
SET $SCRIPT_BUILD=20241114 1500
SET $SCRIPT_VERSION=3.1.0
SET $SCRIPT_BUILD=20241115 0830
Title %$SCRIPT_NAME% Version: %$SCRIPT_VERSION%
mode con:cols=70
mode con:lines=40
Expand All @@ -47,7 +47,7 @@ color 4E

:: Flushes the default user that is logged in
:: default user from unattend file
SET $LOCAL_USER=Scientific
SET $LOCAL_USER=

:: [DELETE] Scheduled Task keyword search
:: Keyword search is used to search for scheduled tasks that are created for users.
Expand All @@ -60,13 +60,13 @@ SET "$KEYWORD_SCHEDULED_TASK=OneDrive"
:: [DELETE] Microsoft APPX Packages
:: File that contains a list of APPX packages to delete using keywords
:: pathed to config
SET $APPX_LIST=%~dp0\config\APPX_List.txt
SET $APPX_List=APPX_List.txt

:: Windows Update via powershell, KB exclusion
:: NotKBArticleID with space between KB's
:: E.g. SET "$NotKBArticleID=KB4481252 KB4481252"
:: KB4481252 = SilverLight
SET "$NotKBArticleID=KB4481252"
:: Windows Update via powershell, KB exclusion
:: NotKBArticleFile with space between KB's
:: E.g. KB4481252 KB4481252
:: KB4481252 = SilverLight
SET $NotKBArticleID=Windows_Update_KB_List.txt

:: Use Unatand.xml for SysPrep
:: No [0] Yes [1]
Expand Down Expand Up @@ -97,12 +97,15 @@ SET $TIMEOUT=5
:: *******************
::###########################################################################::

:: Turn on [1] or off [0]
SET $DEGUB=0

:: Default properties file name
SET $CONFIG_FILE=module_system_SysPrep.properties

:: Minimum properties file schema version
:: DO NOT MODIFY
SET $CONFIG_SCHEMA_VERSION_MIN=3.0.0
SET $CONFIG_SCHEMA_VERSION_MIN=3.1.0

:: Log Directory
SET $LD=logs
Expand Down Expand Up @@ -244,11 +247,19 @@ REM FOR /F %%R IN ('ECHO %VARIABLE%') DO SET $VARIABLE=%%R
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

:: LOADING PROPERTIES
:: Debug
FOR /F "tokens=2 delims=^=" %%V IN ('FINDSTR /BC:"$DEGU" "%~dp0\config\%$CONFIG_FILE%"') DO SET "$DEGU=%%V"
echo $DEGU: %$DEGU%
:: APPX list file
FOR /F "tokens=2 delims=^=" %%V IN ('FINDSTR /BC:"$APPX_List" "%~dp0\config\%$CONFIG_FILE%"') DO SET "$APPX_List=%%V"
echo $APPX_List: %$APPX_List%
if exist "%~dp0\config\%$APPX_List%" set "$APPX_List=%~dp0\config\%$APPX_List%"
:: [DELETE] Scheduled Tasks
FOR /F "tokens=2 delims=^=" %%V IN ('FINDSTR /BC:"$KEYWORD_SCHEDULED_TASK" "%~dp0\config\%$CONFIG_FILE%"') DO SET "$KEYWORD_SCHEDULED_TASK=%%V"
echo $KEYWORD_SCHEDULED_TASK: %$KEYWORD_SCHEDULED_TASK%
:: Windows Update KB exclusion
FOR /F "tokens=2 delims=^=" %%V IN ('FINDSTR /BC:"$NotKBArticleID" "%~dp0\config\%$CONFIG_FILE%"') DO SET "$NotKBArticleID=%%V"
set /P $NotKBArticleID= < "%~dp0\config\%$NotKBArticleID%"
echo $NotKBArticleID: %$NotKBArticleID%
:: Timeout
FOR /F "tokens=2 delims=^=" %%V IN ('FINDSTR /BC:"$TIMEOUT" "%~dp0\config\%$CONFIG_FILE%"') DO SET "$TIMEOUT=%%V"
Expand Down Expand Up @@ -334,26 +345,38 @@ SET "$LD=%$WD%\%$LD%\%COMPUTERNAME%"
SET /P $OS_PRODUCT_KEY= < %$CD%\OS_PRODUCT_KEY.txt
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

:User
:: In case the current logged on user is different from $Local_User, this ensures the local account will still get disabled so local administrator auto logs in.
IF "%USERNAME%"=="Administrator" GoTo skipUser
echo %USERNAME%> "%$CD%\Username.txt"
IF NOT DEFINED $LOCAL_USER SET /P $LOCAL_USER= < "%$CD%\Username.txt"
IF NOT "%USERNAME%"=="$LOCAL_USER" SET $LOCAL_USER=%USERNAME%
:skipUser
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

:start
echo %TIME% [INFO] %DATE% Start... >> "%$LD%\%$MODULE_LOG%"
echo %TIME% [INFO] Script Name: %$SCRIPT_NAME% >> "%$LD%\%$MODULE_LOG%"
echo %TIME% [INFO] Script Version: %$SCRIPT_VERSION% >> "%$LD%\%$MODULE_LOG%"
echo %TIME% [DEBUG] Script Build: %$SCRIPT_BUILD% >> "%$LD%\%$MODULE_LOG%"
echo %TIME% [INFO] Computer: %COMPUTERNAME% >> "%$LD%\%$MODULE_LOG%"
echo %TIME% [DEBUG] Working directory [$WD]: %$WD% >> "%$LD%\%$MODULE_LOG%"
echo %TIME% [DEBUG] Log directory [$LD]: %$LD% >> "%$LD%\%$MODULE_LOG%"
echo %TIME% [DEBUG] Var directory [$VD]: %$CACHE% >> "%$LD%\%$MODULE_LOG%"
echo %TIME% [DEBUG] $LOCAL_USER: %$LOCAL_USER% >> "%$LD%\%$MODULE_LOG%"
echo %TIME% [DEBUG] $TIMEOUT: %$TIMEOUT% >> "%$LD%\%$MODULE_LOG%"
echo %TIME% [DEBUG] $UNATTEND_USE: %$UNATTEND_USE% >> "%$LD%\%$MODULE_LOG%"
echo %TIME% [DEBUG] $UNATTEND_CLEAN: %$UNATTEND_CLEAN% >> "%$LD%\%$MODULE_LOG%"
echo %TIME% [DEBUG] $UNATTEND_FILE: %$Unattend_FILE% >> "%$LD%\%$MODULE_LOG%"
echo %TIME% [DEBUG] $UNATTEND_DIR: %$UNATTEND_DIR% >> "%$LD%\%$MODULE_LOG%"
echo %TIME% [DEBUG] $IMAGE_USE: %$IMAGE_USE% >> "%$LD%\%$MODULE_LOG%"
if %$IMAGE_USE% EQU 1 echo %TIME% [DEBUG] $IMAGE_DIRECTORY: %$IMAGE_DIRECTORY% >> "%$LD%\%$MODULE_LOG%"
if %$IMAGE_USE% EQU 1 echo %TIME% [DEBUG] $IMAGE_FILE: %$IMAGE_FILE% >> "%$LD%\%$MODULE_LOG%"
if %$IMAGE_USE% EQU 1 echo %TIME% [DEBUG] $IMAGE_TYPE: %$IMAGE_TYPE% >> "%$LD%\%$MODULE_LOG%"
IF %$Debug% EQU 1 echo %TIME% [DEBUG] Script Build: %$SCRIPT_BUILD% >> "%$LD%\%$MODULE_LOG%"
echo %TIME% [INFO] Computer: %COMPUTERNAME% >> "%$LD%\%$MODULE_LOG%"
IF %$Debug% EQU 1 echo %TIME% [DEBUG] $Debug: %$Debug% >> "%$LD%\%$MODULE_LOG%"
IF %$Debug% EQU 1 echo %TIME% [DEBUG] Working directory [$WD]: %$WD% >> "%$LD%\%$MODULE_LOG%"
IF %$Debug% EQU 1 echo %TIME% [DEBUG] Log directory [$LD]: %$LD% >> "%$LD%\%$MODULE_LOG%"
IF %$Debug% EQU 1 echo %TIME% [DEBUG] cache directory [$CD]: %$CD% >> "%$LD%\%$MODULE_LOG%"
IF %$Debug% EQU 1 echo %TIME% [DEBUG] $LOCAL_USER: %$LOCAL_USER% >> "%$LD%\%$MODULE_LOG%"
IF %$Debug% EQU 1 echo %TIME% [DEBUG] APPX_FILE: %$APPX_FILE% >> "%$LD%\%$MODULE_LOG%"
IF %$Debug% EQU 1 echo %TIME% [DEBUG] $KEYWORD_SCHEDULED_TASK: %$KEYWORD_SCHEDULED_TASK% >> "%$LD%\%$MODULE_LOG%"
IF %$Debug% EQU 1 echo %TIME% [DEBUG] $NotKBArticleID: %$NotKBArticleID% >> "%$LD%\%$MODULE_LOG%"
IF %$Debug% EQU 1 echo %TIME% [DEBUG] $TIMEOUT: %$TIMEOUT% >> "%$LD%\%$MODULE_LOG%"
IF %$Debug% EQU 1 echo %TIME% [DEBUG] $UNATTEND_USE: %$UNATTEND_USE% >> "%$LD%\%$MODULE_LOG%"
IF %$Debug% EQU 1 echo %TIME% [DEBUG] $UNATTEND_CLEAN: %$UNATTEND_CLEAN% >> "%$LD%\%$MODULE_LOG%"
IF %$Debug% EQU 1 echo %TIME% [DEBUG] $UNATTEND_FILE: %$Unattend_FILE% >> "%$LD%\%$MODULE_LOG%"
IF %$Debug% EQU 1 echo %TIME% [DEBUG] $UNATTEND_DIR: %$UNATTEND_DIR% >> "%$LD%\%$MODULE_LOG%"
IF %$Debug% EQU 1 echo %TIME% [DEBUG] $IMAGE_USE: %$IMAGE_USE% >> "%$LD%\%$MODULE_LOG%"
IF %$Debug% EQU 1 if %$IMAGE_USE% EQU 1 echo %TIME% [DEBUG] $IMAGE_DIRECTORY: %$IMAGE_DIRECTORY% >> "%$LD%\%$MODULE_LOG%"
IF %$Debug% EQU 1 if %$IMAGE_USE% EQU 1 echo %TIME% [DEBUG] $IMAGE_FILE: %$IMAGE_FILE% >> "%$LD%\%$MODULE_LOG%"
IF %$Debug% EQU 1 if %$IMAGE_USE% EQU 1 echo %TIME% [DEBUG] $IMAGE_TYPE: %$IMAGE_TYPE% >> "%$LD%\%$MODULE_LOG%"
echo %TIME% [INFO] OS Name: %$OS_CAPTION% >> "%$LD%\%$MODULE_LOG%"
echo %TIME% [INFO] OS Display Version: %$OS_DISPLAY_VERSION% >> "%$LD%\%$MODULE_LOG%"
echo %TIME% [INFO] OS Build Number: %$OS_CurrentBuildNumber% >> "%$LD%\%$MODULE_LOG%"
Expand Down Expand Up @@ -477,6 +500,7 @@ GoTo Menu
CALL :banner
IF EXIST "%$CD%\%$PROCESS_2%" GoTo skipP2
Echo Processing %$STEP_DESCRIP% ...
echo Deleting the following user: %$LOCAL_USER%
echo %TIME% [INFO] Processing %$STEP_DESCRIP%... >> "%$LD%\%$MODULE_LOG%"
@powershell -command "(Get-WmiObject Win32_UserProfile | Select-Object LocalPath, SID | Out-String -Width 100)" > "%$CD%\User_Profiles.txt"
IF NOT DEFINED $LOCAL_USER GoTo skipP2
Expand Down Expand Up @@ -764,7 +788,7 @@ GoTo Menu
@sysprep /oobe /generalize /shutdown
)
FIND /I "Error" "%WINDIR%\System32\Sysprep\Panther\setuperr.log" 1> nul 2> nul && SET $SYSPREP_ERROR=1
echo %TIME% [DEBUG] $SYSPREP_ERROR: %$SYSPREP_ERROR% >> "%$LD%\%$MODULE_LOG%"
IF %$Debug% EQU 1 echo %TIME% [DEBUG] $SYSPREP_ERROR: %$SYSPREP_ERROR% >> "%$LD%\%$MODULE_LOG%"
echo %TIME% SysPrep error level: %$SYSPREP_ERROR% >> "%$CD%\%$PROCESS_0%"
echo %TIME% [INFO] %$STEP_DESCRIP% completed! >> "%$LD%\%$MODULE_LOG%"
echo %$STEP_DESCRIP% Done.
Expand Down

0 comments on commit b5128c0

Please sign in to comment.