-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathOSConfig.ps1
110 lines (109 loc) · 6.25 KB
/
OSConfig.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#======================================================================================
# Author: David Segura
# Version: 18.9.4
# https://www.osdeploy.com/
#======================================================================================
# Requirements
#======================================================================================
$ErrorActionPreference = 'SilentlyContinue'
#$VerbosePreference = 'Continue'
#======================================================================================
# Set OSDeploy
#======================================================================================
$OSDeploy = "$env:ProgramData\OSDeploy"
$OSConfig = "$env:ProgramData\OSConfig"
$OSConfigLogs = "$OSDeploy\Logs\OSConfig"
$ScriptName = $MyInvocation.MyCommand.Name
$ScriptDirectory = Split-Path $MyInvocation.MyCommand.Path -Parent
$Host.UI.RawUI.WindowTitle = "$ScriptDirectory\$ScriptName"
#======================================================================================
# Create the Log Directory
#======================================================================================
if (!(Test-Path $OSConfigLogs)) {New-Item -ItemType Directory -Path $OSConfigLogs}
#======================================================================================
# Start the Transcript
#======================================================================================
$LogName = "$ScriptName-$((Get-Date).ToString('yyyy-MM-dd-HHmmss')).log"
Start-Transcript -Path (Join-Path $OSConfigLogs $LogName)
Write-Host ""
Write-Host "Starting $ScriptName from $ScriptDirectory" -ForegroundColor Yellow
#======================================================================================
# Remove Existing OSConfig
#======================================================================================
if ($ScriptDirectory -ne $OSConfig) {
if (Test-Path $OSConfig) {
Write-Host "Removing existing $OSConfig..." -ForegroundColor Yellow
Remove-Item -Path $OSConfig -Recurse -Force
}
}
#======================================================================================
# Check for Provisioning Package
#======================================================================================
if ($ScriptDirectory -like "*ProvisioningPkgTmp*") {
Write-Host "OSConfig is running from a Provisioning Package ..." -ForegroundColor Yellow
#======================================================================================
# Expand Provisioning Package
#======================================================================================
if (Test-Path "$ScriptDirectory\OSConfig.cab") {
if (!(Test-Path $OSConfig)) {New-Item -ItemType Directory -Path $OSConfig}
Write-Host "Expanding '$ScriptDirectory\OSConfig.cab' to '$OSConfig'..." -ForegroundColor Yellow
expand "$ScriptDirectory\OSConfig.cab" $OSConfig -F:*
}
} else {
#======================================================================================
# Copy Files
#======================================================================================
if ($ScriptDirectory -ne $OSConfig) {
Write-Host "Copying '$ScriptDirectory' to '$OSConfig'..." -ForegroundColor Yellow
Copy-Item -Path $ScriptDirectory -Destination $OSConfig -Recurse
}
}
#======================================================================================
# Capture the Environment Variables in the Log
#======================================================================================
Get-Childitem -Path Env:* | Sort-Object Name | Format-Table
#======================================================================================
# Increase the Screen Buffer size
#======================================================================================
# This entry allows increased scrolling of the console windows
if (!(Test-Path "HKCU:\Console")) {
New-Item -Path "HKCU:\Console" -Force | Out-Null
New-ItemProperty -Path HKCU:\Console ScreenBufferSize -Value 589889656 -PropertyType DWORD -Force | Out-Null
}
#======================================================================================
# Execute PowerShell files in OSConfig
#======================================================================================
Write-Host ""
$OSConfigChild = Get-ChildItem $OSConfig -Directory
foreach ($item in $OSConfigChild) {
Write-Host "$($item.FullName)" -ForegroundColor Green
$OSConfigScripts = Get-ChildItem $item.FullName -Filter *.ps1 -File
foreach ($script in $OSConfigScripts) {
Write-Host "Executing $($script.FullName)"
#======================================================================================
# Execute Provisioning Package Minimized
# Change WindowStyle to Hidden when testing is complete
#======================================================================================
if (Test-Path "$ScriptDirectory\OSConfig.cab") {
Start-Process PowerShell.exe -ArgumentList "-file `"$($script.FullName)`"" -Wait -WindowStyle Minimized
#======================================================================================
# Execute Standard PowerShell Script
# Choose proper WindowStyle
#======================================================================================
} else {
#Start-Process PowerShell.exe -ArgumentList "-file `"$($script.FullName)`"" -Wait
#Start-Process PowerShell.exe -ArgumentList "-file `"$($script.FullName)`"" -Wait -NoNewWindow
Start-Process PowerShell.exe -ArgumentList "-file `"$($script.FullName)`"" -Wait -WindowStyle Minimized
#Start-Process PowerShell.exe -ArgumentList "-file `"$($script.FullName)`"" -Wait -WindowStyle Maximized
#Start-Process PowerShell.exe -ArgumentList "-file `"$($script.FullName)`"" -Wait -WindowStyle Hidden
}
}
Write-Host ""
}
#======================================================================================
# Enable the following lines for testing as needed
# Start-Process PowerShell_ISE.exe -Wait
# Read-Host -Prompt "Press Enter to Continue"
#======================================================================================
Stop-Transcript
#======================================================================================