728x90

https://moonth.tistory.com/397

 

Windows 10, 11 Sysprep 일반화 진입

Sysprep을 진행하는 감사모드로 진입하려면 아래 방법을 따라야 합니다. 윈도우를 설치하고 최초 부팅이 시작되면 첫번째 화면으로 국가를 선택하는 창이 나오는데 여기서 "Ctrl+Shift+F3"을 누릅니

moonth.tistory.com

지난번 일반화 진입하기에 이어 일반화 완료 하기입니다.

일반화를 완료하는 방법은 두가지가 있다 할 수 있겠습니다.

  • sysprep.exe UI로 일반화 하는 방법 : 프로그램과 드라이버를 추가하고 바탕화면 구성을 변경하거나 필요한 파일을 집어넣거나 하는 방법만 사용했다면 sysprep.exe UI가 실행된 상태에서 일반화 버튼을 눌러 일반화를 하면 됩니다.

  • 무인화 파일(unattend.xml) 파일을 이용하여 일반화 하는 방법 : 아래와 같은 cmd를 입력하여 무인화 파일을 일반화 시 등록할 수 있습니다. 이 무인화 파일에 들어간 여러 설정으로 사용자는 여러 설치 단계들을 미리 설정된 파일 정보로 건너뛸수 있습니다.
    예) c:\windows\System32\Sysprep\sysprep.exe /generalize /oobe /shutdown /unattend:C:\unattend.xml

프로그램을 설치하고 무인화 파일도 등록한다면 cmd를 이용한 방식을 따라야합니다. UI로는 무인화 파일을 등록할 수 없기 때문에 프로그램 추가/삭제, 드라이버 추가/삭제, 기타 파일 추가/삭제 등의 작업만 진행 할 수 있습니다.

이제부터 아래 설명할 내용들은 감사모드에서 적용할 수 있는 몇가지 예시 입니다. 무인화 설치에 관해서는 Windows AIK(Automated Installation Kit)의 내용을 살펴보아야합니다. AIK 툴을 설치하고 xml로 이루어진 무인화 파일을 제작해야합니다. 제작 예시는 별도로 다루겠습니다.

프로그램 삭제

아래 표에 작성한 명령어를 파워쉘에 입력하면 프로그램을 지웁니다. 필요하지 않는 프로그램만 메모장에 복사하여 "ps1" 확장자로 저장 후 한번에 실행할 수 있습니다. 

#AV1 Codec
Get-AppxPackage *AV1VideoExtension* | Remove-AppxPackage

#News app
Get-AppxPackage *BingNews* | Remove-AppxPackage

#Weather
Get-AppxPackage *BingWeather* | Remove-AppxPackage

#PowerShell
Get-AppxPackage *PowerShell* | Remove-AppxPackage

#WebP image support
Get-AppxPackage *WebpImageExtension* | Remove-AppxPackage

#HEIF image support
Get-AppxPackage *HEIFImageExtension* | Remove-AppxPackage

#Windows Terminal
Get-AppxPackage *WindowsTerminal* | Remove-AppxPackage

#Music app
Get-AppxPackage *ZuneMusic* | Remove-AppxPackage

#Movies and TV
Get-AppxPackage *ZuneVideo* | Remove-AppxPackage

#MS Office
Get-AppxPackage *MicrosoftOfficeHub* | Remove-AppxPackage

#People app
Get-AppxPackage *People* | Remove-AppxPackage

#Maps
Get-AppxPackage *WindowsMaps* | Remove-AppxPackage

#Help and tips
Get-AppxPackage *GetHelp* | Remove-AppxPackage

#Voice Recorder
Get-AppxPackage *WindowsSoundRecorder* | Remove-AppxPackage

#Notepad
Get-AppxPackage *WindowsNotepad* | Remove-AppxPackage

#MS Paint
Get-AppxPackage *Paint* | Remove-AppxPackage

#Sticky Notes
Get-AppxPackage *MicrosoftStickyNotes* | Remove-AppxPackage

#PowerAutomate
Get-AppxPackage *PowerAutomateDesktop* | Remove-AppxPackage

#Xbox and related apps
Get-AppxPackage *Xbox* | Remove-AppxPackage

#Feedback Hub
Get-AppxPackage *WindowsFeedbackHub* | Remove-AppxPackage

#Microsoft To-Do
Get-AppxPackage *Todos* | Remove-AppxPackage

#Calculator
Get-AppxPackage *WindowsCalculator* | Remove-AppxPackage

#Alarms and Clocks
Get-AppxPackage *WindowsAlarms* | Remove-AppxPackage

#Teams/Chat
Get-AppxPackage *Teams* | Remove-AppxPackage

#Microsoft Edge
Get-AppxPackage *MicrosoftEdge* | Remove-AppxPackage

#Your Phone
Get-AppxPackage *YourPhone* | Remove-AppxPackage

#Spotify
Get-AppxPackage *SpotifyAB.SpotifyMusic* | Remove-AppxPackage

#Screen & Sketch/Snipping tool
Get-AppxPackage *ScreenSketch* | Remove-AppxPackage

#Solitaire Collection
Get-AppxPackage *MicrosoftSolitaireCollection* | Remove-AppxPackage

#Photos
Get-AppxPackage *Windows.Photos* | Remove-AppxPackage

#OneDrive
Get-AppxPackage *OneDriveSync* | Remove-AppxPackage

#Skype
Get-AppxPackage *SkypeApp* | Remove-AppxPackage

#Xbox Console Companion
Get-AppxPackage *GamingApp* | Remove-AppxPackage

프로그램 추가

MS 오피스나 한글, 어도비 프리미어 및 포토샵등의 프로그램들은 별다른 제한없이 설치 가능하나 그 갯수가 많아지면 시스템 변경점이 발생되어 일반화가 실패할 가능성이 있습니다. appx 등의 확장자를 가진 MS app 을 설치한다면 명령어를 이용하고 설치하되 모든 유저에게 적용되도록 설치합니다. 아래의 명령 예시를 참고 하세요

Add-AppxPackage -Path "C:\path\to\appxfile.appx" -AllUsers

MS 앱에 경우 현재 사용중인 사용자에게만 권한을 적용하기 때문에 Allusers 옵션을 넣어서 설치하지 않는다면 일반화 이후 새로 생성되는 계정이 일반화 단계에서 미리 설치한 MS apps를 권한 문제로 실행하지 못하는 문제가 발생될 수 있습니다. 또한 MS apps 의 오프라인 설치 파일의 경우 라이선스 xml 파일도 있어야 합니다. (이는 폐쇠적인 기업환경에 필요할 수 있습니다.) 폐쇠적인 기업환경이 아니라면(MS store가 차단되어있지 않다면) 이러한 프로그램 추가 문제를 깊이 신경쓰지 않아도 됩니다.

드라이버 추가

모아둔 시스템 드라이버가 있다면 아래 명령어로 현재 윈도우에 추가가 가능합니다. 단 드라이버는 실행파일이나 압축 형식으로 되어있으면 안됩니다. 아래 명령어를 보시면 .inf 파일을 검색하여 등록하는 것입니다. easy 드라이버팩이나 nvidia driver 실행파일의 경우 등록이 되지 않습니다.

Get-ChildItem "D:\Drivers\" -Recurse -Filter "*.inf" | ForEach-Object {PNPUtil.exe /add-driver $_.FullName /install}

드라이버 등록 후 용량이 과도하게 늘어날 수 있다는걸 기업하십시오. 예를 들어 800Mb짜리 Nvidia 드라이버를 위 명령어로 시스템에 추가한다면 4~5Gb 정도의 용량을 차지하게 될 것입니다. 이는 "inf" 파일이 가리키는 모든 드라이버를 시스템에 가지고 오기 때문입니다. nvidia 는 드라이버 제작시 여러개의 inf 파일을 만들었고 파일을 중복으로 가져가게 설계 해두었습니다. 지금 확인을 해보았는데 약 60개의 inf 파일이 검색 되었고 이중에 그래픽을 담당하는 inf 파일은 하나지만 위 명령어를 사용하면 60여개를 모두 가져와 불필요한 용량을 늘리게 되는 것입니다. 이에 주의 하시길 바랍니다. 인텔 내장 그래픽 드라이버도 마찬가지 입니다.

불필요 드라이버 정리

드라이버 정리를 하기 전에 현재 드라이버 상태를 백업합니다. 현재 컴퓨터의 상태를 포함하여 드라이버를 제거하기 전에 체크포인트를 생성하는 PowerShell 명령을 사용할 것입니다.

Checkpoint-Computer -Description “CheckpointDeleteDrivers”

드라이버에 문제가 발생하여 복구 해야 한다면 아래 명령을 사용합니다.

Restore-Computer -CheckpointName “CheckpointDeleteDrivers”

드라이버 백업 후 드라이버 정리를 수행합니다. 감사모드 상태에서는 드라이버 정리를 편하게 UI로 실행 할 수 있습니다. "디스크 정리" 앱을 사용합니다. 감사모드 상태에서만 등장하는 "장치 드라이버 패키지" 정리 기능을 사용하여 중복된 드라이버를 제거하고 최신 드라이버만 유지합니다.

장치 드라이버를 정리하면서 임시파일, 휴지통 등 불필요한 파일을 모두 선택하여 지워주면 용량 확보에 추가적인 도움이 됩니다.

좀더 어려운 방법이 있습니다. 파워쉘 명령어를 사용하지만 감사모드가 아닌 상태에서도 이용할 수 있습니다. 아래 코드를 메모장에 복사하여 파워쉘 스크립트 (ps1) 로 저장후 실행합니다.

$dismOut = dism /online /get-drivers
$Lines = $dismOut | select -Skip 10
$Operation = "theName"
$Drivers = @()
foreach ( $Line in $Lines ) {
    $tmp = $Line
    $txt = $($tmp.Split( ':' ))[1]
    switch ($Operation) {
        'theName' { $Name = $txt
                     $Operation = 'theFileName'
                     break
                   }
        'theFileName' { $FileName = $txt.Trim()
                         $Operation = 'theEntr'
                         break
                       }
        'theEntr' { $Entr = $txt.Trim()
                     $Operation = 'theClassName'
                     break
                   }
        'theClassName' { $ClassName = $txt.Trim()
                          $Operation = 'theVendor'
                          break
                        }
        'theVendor' { $Vendor = $txt.Trim()
                       $Operation = 'theDate'
                       break
                     }
        'theDate' { # change the date format for easy sorting
                     $tmp = $txt.split( '.' )
                     $txt = "$($tmp[2]).$($tmp[1]).$($tmp[0].Trim())"
                     $Date = $txt
                     $Operation = 'theVersion'
                     break
                   }
        'theVersion' { $Version = $txt.Trim()
                        $Operation = 'theNull'
                        $params = [ordered]@{ 'FileName' = $FileName
                                              'Vendor' = $Vendor
                                              'Date' = $Date
                                              'Name' = $Name
                                              'ClassName' = $ClassName
                                              'Version' = $Version
                                              'Entr' = $Entr
                                            }
                        $obj = New-Object -TypeName PSObject -Property $params
                        $Drivers += $obj
                        break
                      }
         'theNull' { $Operation = 'theName'
                      break
                     }
    }
}
Write-Host "All installed third-party  drivers"
$Drivers | sort Filename | ft
Write-Host "Different versions"
$last = ''
$NotUnique = @()
foreach ( $Dr in $($Drivers | sort Filename) ) {   
    if ($Dr.FileName -eq $last  ) {  $NotUnique += $Dr  }
    $last = $Dr.FileName
}
$NotUnique | sort FileName | ft
Write-Host "Outdated drivers"
$list = $NotUnique | select -ExpandProperty FileName -Unique
$ToDel = @()
foreach ( $Dr in $list ) {
    Write-Host "duplicate found" -ForegroundColor Yellow
    $sel = $Drivers | where { $_.FileName -eq $Dr } | sort date -Descending | select -Skip 1
    $sel | ft
    $ToDel += $sel
}
Write-Host "Drivers to remove" -ForegroundColor Red
$ToDel | ft
# removing old drivers
foreach ( $item in $ToDel ) {
    $Name = $($item.Name).Trim()
    Write-Host "deleting $Name" -ForegroundColor Yellow
    Write-Host "pnputil.exe -d $Name" -ForegroundColor Yellow
    Invoke-Expression -Command "pnputil.exe -d $Name"
}

이 PowerShell 스크립트는 현재 설치된 서드파티 드라이버를 가져와서, 중복 및 오래된 드라이버를 찾고 삭제하는 기능을 수행합니다.

스크립트에서는 dism 명령어를 사용하여 현재 설치된 드라이버 목록을 가져오고, 이를 select 명령어를 사용하여 필요한 부분만 추출합니다. 그리고 foreach 루프를 사용하여 드라이버 목록을 처리하며, 각 드라이버의 파일명, 버전, 업체명, 설치 날짜 등의 정보를 추출합니다.

그 다음 중복된 드라이버를 찾고 삭제하기 위해, foreach 루프와 where 조건절을 사용하여 중복된 드라이버를 필터링하고, pnputil.exe를 사용하여 드라이버를 삭제합니다.

무인화 파일 없이 진행할 수 있는 프로그램 설치/제거, 드라이버 설치/제거 등을 알아보았습니다. 파일 복사를 하고싶으면 그냥 두고싶은데 두면 되며 사용자 바탕화면에 두고 싶다면 "C:\Users\Default\desktop" 경로를 사용해야합니다. 새로 생성한 계정은 디폴트 값을 복사하여 계정을 생성하기 때문입니다. 

마무리 되었으면 제일 위에서 설명한 방법으로 일반화를 끝내면 되겠습니다. 일반화를 끝내면 이것을 이미지화 시켜 윈도우 인스톨러로 활용하거나 ghost, winclon, aomei 등등 백업/복구 프로그램으로 백업하여 유지보수 용으로도 활용할 수 있습니다.

728x90

+ Recent posts