-
Notifications
You must be signed in to change notification settings - Fork 38
/
SysprepCSE.ps1
42 lines (36 loc) · 1.49 KB
/
SysprepCSE.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<#
.SYNOPSIS
Used as a custom script extension for running Sysprep.ext on Windows VM's in Azure
.DESCRIPTION
This Custom Script Extension is used to run Sysprep on a VM to prepare it for imaging.
/mode:vm is used to speed up first boot on VM's by skipping hardware detection.
Remove "/mode:vm" if the image will be deployed to different VM types then the source VM.
More info here: https://www.ciraltos.com/please-wait-for-the-windows-modules-installer/
.NOTES
## Script is offered as-is with no warranty, expressed or implied. ##
## Test it before you trust it! ##
Author : Travis Roberts, Ciraltos llc
Website : www.ciraltos.com
Version : 1.0.0.0 Initial Build 3/12/2022
.LINK
#>
#Script to run Sysprep on a VM
#Logging is handy when you need it!
if ((test-path c:\logfiles) -eq $false) {
new-item -ItemType Directory -path 'c:\' -name 'logfiles' | Out-Null
}
$logFile = "c:\logfiles\" + (get-date -format 'yyyyMMdd') + '_softwareinstall.log'
# Logging function
function Write-Log {
Param($message)
Write-Output "$(get-date -format 'yyyyMMdd HH:mm:ss') $message" | Out-File -Encoding utf8 $logFile -Append
}
#Run Sysprep
try{
write-output "Sysprep Starting"
Start-Process -filepath 'c:\Windows\system32\sysprep\sysprep.exe' -ErrorAction Stop -ArgumentList '/generalize', '/oobe', '/mode:vm', '/shutdown'
}
catch {
$ErrorMessage = $_.Exception.message
write-log "Error running Sysprep: $ErrorMessage"
}