/
Install-PSD.ps1
183 lines (153 loc) · 7.95 KB
/
Install-PSD.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#
# Install.ps1
# version 1.0
#Requires -RunAsAdministrator
Param(
$psDeploymentFolder = "NA",
$psDeploymentShare = "NA",
[Switch]$Upgrade
)
if($psDeploymentFolder -eq 'NA'){
Write-Error "You have not specified the -psDeploymentfolder"
Write-Error "Run the installer script again and specify -psDeploymentFolder and -psDeploymentShare"
Break
}
if($psDeploymentShare -eq 'NA'){
Write-Error "You have not specified the -psDeploymentfolder"
Write-Error "Run the installer script again and specify -psDeploymentFolder and -psDeploymentShare"
Break
}
# Set vars
$install = Split-Path -Path "$PSScriptRoot"
$verbosePreference = "Continue"
if($Upgrade)
{
Write-Verbose "Installer running in upgrade mode"
}
# Utility function to copy folders (using XCOPY)
function Copy-PSDFolder
{
param (
[Parameter(Mandatory=$True,Position=1)]
[string] $source,
[Parameter(Mandatory=$True,Position=2)]
[string] $destination
)
$s = $source.TrimEnd("\")
$d = $destination.TrimEnd("\")
Write-Verbose "Copying folder $source to $destination using XCopy"
& xcopy $s $d /s /e /v /d /y /i | Out-Null
}
#TODO - Check for ADK installed and version
$mdtADK = (Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Where-Object {$_.DisplayName -like "Windows Assessment and Deployment Kit*"}).DisplayVersion
Write-Verbose "ADK installed version== $mdtADK"
$mdtADKPE = (Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Where-Object {$_.DisplayName -like "Windows Assessment and Deployment Kit Windows*"}).DisplayVersion
Write-Verbose "WinPE Addon for ADK(only for ADK1809 or above)== $mdtADKPE"
#TODO - Check for MDT installed and version
$mdtVer = ((Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Where-Object {$_.DisplayName -like "Microsoft Deployment Toolkit*"}).Displayname)
Write-Verbose "MDT installed version== $mdtVer"
# Create the folder and share
if (Test-Path -path $psDeploymentFolder)
{
if(!($Upgrade))
{
Write-Warning "PSD Folder already exist, will break"
BREAK
}
}
else
{
New-Item -Path $psDeploymentFolder -ItemType Directory
New-SmbShare -Name $psDeploymentShare -Path $psDeploymentFolder -FullAccess Administrators
}
# Load the MDT PowerShell provider
$mdtDir = $(Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Deployment 4' -Name Install_Dir).Install_Dir
Write-Verbose "MDT installation directory: $mdtDir"
Import-Module "$($mdtDir)Bin\MicrosoftDeploymentToolkit.psd1"
# Create the deployment share at the specified path
#TODO - check for existig PSDdrive if a re-run
if(!($Upgrade))
{
New-PSDrive -Name "PSD" -PSProvider "MDTProvider" -Root $psDeploymentFolder -Description "PSD Deployment Share" -NetworkPath "\\$env:COMPUTERNAME\$psDeploymentShare" | add-MDTPersistentDrive
}
# Copy the scripts
Copy-PSDFolder "$install\Scripts\*.ps1" "$psDeploymentFolder\Scripts"
Dir "$psDeploymentFolder\Scripts\*.ps1" | Unblock-File
Copy-PSDFolder "$install\Scripts\*.xaml" "$psDeploymentFolder\Scripts"
Dir "$psDeploymentFolder\Scripts\*.xaml" | Unblock-File
# Copy the templates
Copy-PSDFolder "$install\Templates" "$psDeploymentFolder\Templates"
Dir "$psDeploymentFolder\Templates\*" | Unblock-File
# Copy the script modules to the right places
write-verbose "Copying PSD Modules to $psdeploymentfolder......."
"PSDGather", "PSDDeploymentShare", "PSDUtility", "PSDWizard" | % {
if ((Test-Path "$psDeploymentFolder\Tools\Modules\$_") -eq $false)
{
$null = New-Item "$psDeploymentFolder\Tools\Modules\$_" -ItemType directory
}
Write-Verbose "Copying module $_ to $psDeploymentFolder\Tools\Modules"
Copy-Item "$install\Scripts\$_.psm1" "$psDeploymentFolder\Tools\Modules\$_"
Dir "$psDeploymentFolder\Tools\Modules\$_\*" | Unblock-File
}
# Copy the provider module files
Write-Verbose "Copying MDT provider files to $psDeploymentFolder\Tools\Modules"
if ((Test-Path "$psDeploymentFolder\Tools\Modules\Microsoft.BDD.PSSnapIn") -eq $false)
{
$null = New-Item "$psDeploymentFolder\Tools\Modules\Microsoft.BDD.PSSnapIn" -ItemType directory
}
Copy-Item "$($mdtDir)Bin\Microsoft.BDD.PSSnapIn.dll" "$psDeploymentFolder\Tools\Modules\Microsoft.BDD.PSSnapIn"
Copy-Item "$($mdtDir)Bin\Microsoft.BDD.PSSnapIn.dll.config" "$psDeploymentFolder\Tools\Modules\Microsoft.BDD.PSSnapIn"
Copy-Item "$($mdtDir)Bin\Microsoft.BDD.PSSnapIn.dll-help.xml" "$psDeploymentFolder\Tools\Modules\Microsoft.BDD.PSSnapIn"
Copy-Item "$($mdtDir)Bin\Microsoft.BDD.PSSnapIn.Format.ps1xml" "$psDeploymentFolder\Tools\Modules\Microsoft.BDD.PSSnapIn"
Copy-Item "$($mdtDir)Bin\Microsoft.BDD.PSSnapIn.Types.ps1xml" "$psDeploymentFolder\Tools\Modules\Microsoft.BDD.PSSnapIn"
Copy-Item "$($mdtDir)Bin\Microsoft.BDD.Core.dll" "$psDeploymentFolder\Tools\Modules\Microsoft.BDD.PSSnapIn"
Copy-Item "$($mdtDir)Bin\Microsoft.BDD.Core.dll.config" "$psDeploymentFolder\Tools\Modules\Microsoft.BDD.PSSnapIn"
Copy-Item "$($mdtDir)Bin\Microsoft.BDD.ConfigManager.dll" "$psDeploymentFolder\Tools\Modules\Microsoft.BDD.PSSnapIn"
# Copy the provider template files
Write-Verbose "Copying PSD templates to $psDeploymentFolder\Templates"
if ((Test-Path "$psDeploymentFolder\Templates") -eq $false)
{
$null = New-Item "$psDeploymentFolder\Templates"
}
Copy-Item "$($mdtDir)Templates\Groups.xsd" "$psDeploymentFolder\Templates"
Copy-Item "$($mdtDir)Templates\Medias.xsd" "$psDeploymentFolder\Templates"
Copy-Item "$($mdtDir)Templates\OperatingSystems.xsd" "$psDeploymentFolder\Templates"
Copy-Item "$($mdtDir)Templates\Packages.xsd" "$psDeploymentFolder\Templates"
Copy-Item "$($mdtDir)Templates\SelectionProfiles.xsd" "$psDeploymentFolder\Templates"
Copy-Item "$($mdtDir)Templates\TaskSequences.xsd" "$psDeploymentFolder\Templates"
Copy-Item "$($mdtDir)Templates\Applications.xsd" "$psDeploymentFolder\Templates"
Copy-Item "$($mdtDir)Templates\Drivers.xsd" "$psDeploymentFolder\Templates"
Copy-Item "$($mdtDir)Templates\Groups.xsd" "$psDeploymentFolder\Templates"
Copy-Item "$($mdtDir)Templates\LinkedDeploymentShares.xsd" "$psDeploymentFolder\Templates"
# Update the ISO properties
if(!($Upgrade))
{
Write-Verbose "Updating PSD ISO properties"
Set-ItemProperty PSD: -Name "Boot.x86.LiteTouchISOName" -Value "PSDLiteTouch_x86.iso"
Set-ItemProperty PSD: -Name "Boot.x86.LiteTouchWIMDescription" -Value "PowerShell Deployment Boot Image (x86)"
Set-ItemProperty PSD: -Name "Boot.x64.LiteTouchISOName" -Value "PSDLiteTouch_x64.iso"
Set-ItemProperty PSD: -Name "Boot.x64.LiteTouchWIMDescription" -Value "PowerShell Deployment Boot Image (x64)"
}
#Add ZTIGather.XML to correct folder (The file is missing after install) (added by admminy)
Write-verbose "Adding ZTIGather.XML to correct folder"
Copy-Item "$($mdtDir)Templates\Distribution\Scripts\ZTIGather.xml" "$psDeploymentFolder\Tools\Modules\PSDGather"
#Add UNC Path to DeploymentShare (TBA)
#Create folders
Write-verbose "Creating Logs folder in $psdeploymentshare"
$null = New-Item -ItemType directory -Path $psDeploymentFolder\Logs -Force
Write-verbose "Creating Dynamics Logs sub-folder in $psdeploymentshare"
$null = New-Item -ItemType directory -Path $psDeploymentFolder\Logs\Dyn -Force
Write-verbose "Creating DriverSources folder in $psdeploymentshare"
$null = New-Item -ItemType directory -Path $psDeploymentFolder\DriverSources -Force
Write-verbose "Creating DriverPackages folder in $psdeploymentshare"
$null = New-Item -ItemType directory -Path $psDeploymentFolder\DriverPackages -Force
#Relax Permissions on DeploymentShare (added admminy)
if(!($Upgrade))
{
Write-verbose "Relaxing permissons on $psDeploymentShare"
$null = icacls $psDeploymentFolder /grant '"Users":(OI)(CI)(RX)'
$null = icacls $psDeploymentFolder /grant '"Administrators":(OI)(CI)(F)'
$null = icacls $psDeploymentFolder /grant '"SYSTEM":(OI)(CI)(F)'
Grant-SmbShareAccess -Name $psDeploymentShare -AccountName "EVERYONE" -AccessRight Change -Force
Revoke-SmbShareAccess -Name $psDeploymentShare -AccountName "CREATOR OWNER" -Force
}