-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSCCM-PS-Extension.ps1
executable file
·520 lines (421 loc) · 20.8 KB
/
SCCM-PS-Extension.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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
#
# SCCM_PS_Extension.ps1
#
# Actions:
# - Install WDS (2. Install WDS Role.ps1)
# - Install SCCM Pre-req (4. Install SCCM prerequisites.ps1)
# - Install WSUS (5. InstallWSUS-ReportViewer2008.ps1)
# Setting variables
$FQDN = $args[0]
$NetBiosDomainName = $args[1]
$SecurePassword = ConvertTo-SecureString -String $args[2] -AsPlainText -Force
$SCCMServer = $args[3]
$ADDSServer = $args[4]
$adminPassword = ConvertTo-SecureString -String $args[5] -AsPlainText -Force
$AdminUser = $args[6]
$sqlHostName = $Args[7]
#Construct variables
$adHostName = get-content env:computername
#Capture Script Location (because Extension versions may vary)
$CurrentScriptLocation = (Get-Location).path
#Configure logging
function log
{
param([string]$message)
"`n`n$(get-date -f o) $message"
}
#Disable Defender RealTime Scanning
Set-MpPreference -DisableRealtimeMonitoring $true
#GetSCCMISO
$ProgressPreference = 'SilentlyContinue'
Invoke-WebRequest -Uri "https://pmmazurelabfiles.blob.core.windows.net/pmmaurelabfilescontainer/mu_system_center_configuration_manager_current_branch_version_1802_x86_x64_dvd_12064903.iso" -OutFile "C:\Packages\Plugins\Microsoft.Compute.CustomScriptExtension\1.9.5\Downloads\0\mu_system_center_configuration_manager_current_branch_version_1802_x86_x64_dvd_12064903.iso"
#Enable CredSSP to allow Multiple HOP Remote PowerShell
log "Configuring WSMAN"
Enable-WSManCredSSP -Role Server -Force
Enable-WSManCredSSP -Role Client -DelegateComputer ("*."+$FQDN) -Force
Enable-PSRemoting -force
Set-Item WSMan:\localhost\Client\TrustedHosts * -Force
#Set policy "Allow delegating fresh credentials with NTLM-only server authentication"
log "Configuring CREDSSP"
$allowed = @('WSMAN/*.'+ $FQDN)
$key = 'hklm:\SOFTWARE\Policies\Microsoft\Windows\CredentialsDelegation'
if (!(Test-Path $key)) {
md $key
}
New-ItemProperty -Path $key -Name AllowFreshCredentialsWhenNTLMOnly -Value 1 -PropertyType Dword -Force
$key = Join-Path $key 'AllowFreshCredentialsWhenNTLMOnly'
if (!(Test-Path $key)) {
md $key
}
$i = 1
$allowed |% {
# Script does not take into account existing entries in this key
New-ItemProperty -Path $key -Name $i -Value $_ -PropertyType String -Force
$i++
}
#Create Credentials
$mycreds = New-Object System.Management.Automation.PSCredential ($AdminUser, $adminPassword)
#Impersonate User
log "Impersonate user '$AdminUser'"
.\New-ImpersonateUser.ps1 -Credential $mycreds
# This configures DHCP according to pages 31 through 45
$ScriptBlockDHCP= {
param ($NetBiosDomainName, $adIpAddress, $FQDN)
function log
{
param([string]$message)
"`n`n$(get-date -f o) $message"
}
#Construct variables
$DHCPScopeFriendlyName = "SCCM LAN"
$DHCPScopeStartIP = "10.0.66.51"
$DHCPScopeEndIP = "10.0.66.99"
$adHostName = get-content env:computername
#Install the DHCP Feature including the Management Tools
log "Install the DHCP Feature including the Management Tools"
Install-WindowsFeature -Name DHCP -IncludeManagementTools
#Restart the DHCO Service
net stop DHCPServer | net start DHCPServer
#Notify Server Manager that Authorization is complete
log "Notify Server Manager that Authorization is complete"
Set-ItemProperty -Path registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\ServerManager\Roles\12 -Name ConfigurationState -Value 2
#Get Current DHCP Bindings
log "Get Current DHCP Bindings"
Get-DhcpServerv4Binding
#Set the Binding state
log "Set the Binding state"
Set-DhcpServerv4Binding -BindingState $true -InterfaceAlias "Ethernet"
#Configure the AD Domain the in DHCP Scope
log "Configure the AD Domain the in DHCP Scope"
Add-DhcpServerInDC -DnsName $NetBiosDomainName -IPAddress ((Get-NetIPAddress -AddressFamily IPv4 -PrefixOrigin manual).IPAddress)
#Add DHCP Scope
log "Add DHCP Scope"
Add-DhcpServerv4Scope -Name $DHCPScopeFriendlyName -StartRange $DHCPScopeStartIP -EndRange $DHCPScopeEndIP -SubnetMask 255.255.255.0
$ScopeID = Get-DhcpServerv4Scope -ComputerName $adHostName | select Scopeid
#Set Lease Duration to 7 days
log "Set Lease Duration to 7 days"
Set-DhcpServerv4Scope -ComputerName $adHostName -ScopeId $ScopeID[0].ScopeId.IPAddressToString -LeaseDuration 7.00:00:00
#Configure Dynamic IP Address Assignment type to Both
log "Configure Dynamic IP Address Assignment type to Both"
Set-DhcpServerv4Scope -ComputerName $adHostName -ScopeId $ScopeID[0].ScopeId.IPAddressToString -Type both
#Enable Dynamic DNS Update, and also for client who do not request (older clients)
log "Enable Dynamic DNS Update, and also for client who do not request (older clients)"
Set-DhcpServerv4DnsSetting -ComputerName $adHostName -DynamicUpdates Always -UpdateDnsRRForOlderClients $true
}
$session = New-PSSession -cn ($ADDSServer+"."+$FQDN) -Credential $mycreds -Authentication Credssp
Invoke-Command -Session $session -ScriptBlock $ScriptBlockDHCP -ArgumentList $NetBiosDomainName,$adIpAddress,$FQDN
Remove-PSSession -VMName ($ADDSServer+"."+$FQDN)
# This creates AD Extension for SCCM pages 107 through 108
$ScriptBlockADExtension= {
function log
{
param([string]$message)
"`n`n$(get-date -f o) $message"
}
$ImageISOName = "mu_system_center_configuration_manager_current_branch_version_1802_x86_x64_dvd_12064903.iso"
#Mount disk image SCCM ISO and get the driveletter
log "Mount disk image SCCM ISO and get the driveletter"
$InstallPath = "C:\Packages\Plugins\Microsoft.Compute.CustomScriptExtension\1.9.5\Downloads\0"
$mountResult = Mount-DiskImage -ImagePath ($InstallPath+'\'+$ImageISOName) -PassThru
$ISODriveLetter = ($mountResult | Get-Volume).DriveLetter
#Run the extension
log "Run the AD extension EXTADSCH.exe"
$ExtensionExe = $ISODriveLetter+":\SMSSETUP\BIN\X64\extadsch.exe"
& $ExtensionExe
#Log the results from the schema extension
log "Log the results from the schema extension"
get-content "C:\ExtADSch.log"
}
$session = New-PSSession -cn ($ADDSServer+"."+$FQDN) -Credential $mycreds -Authentication Credssp
Invoke-Command -Session $session -ScriptBlock $ScriptBlockADExtension
Remove-PSSession -VMName ($ADDSServer+"."+$FQDN)
# This creates System Management Contains and sets the necesary permissions and membership pages 108 hrough 117
$ScriptBlockSCCMContainer= {
param ($SCCMServer)
function log
{
param([string]$message)
"`n`n$(get-date -f o) $message"
}
#Import AD Module
log "Import AD Module"
Import-Module ActiveDirectory
#Get Root Domain CN
$root = (Get-ADRootDSE).defaultNamingContext
# Create the System Management container
log "Create the System Management container"
$ou = New-ADObject -Type Container -name "System Management" -Path "CN=System,$root" -Passthru
# Get the current ACL for the OU
$acl = get-acl "ad:CN=System Management,CN=System,$root"
# Create a new access control entry to allow access to the OU
log "Create a new access control entry to allow access to the OU"
$identity = [System.Security.Principal.IdentityReference] [System.Security.Principal.SecurityIdentifier] (get-adcomputer $env:ComputerName).SID
$adRights = [System.DirectoryServices.ActiveDirectoryRights] "GenericAll"
$type = [System.Security.AccessControl.AccessControlType] "Allow"
$inheritanceType = [System.DirectoryServices.ActiveDirectorySecurityInheritance] "All"
$ace = New-Object System.DirectoryServices.ActiveDirectoryAccessRule $identity,$adRights,$type,$inheritanceType
# Add the ACE to the ACL, then set the ACL to save the changes
log "Add the ACE to the ACL, then set the ACL to save the changes"
$acl.AddAccessRule($ace)
Set-acl -aclobject $acl "ad:CN=System Management,CN=System,$root"
#Add SCCM Server to Administrators group
log "Add SCCM Server to Administrators group"
Add-ADGroupMember -Identity "Administrators" -Members ($SCCMServer+"$")
}
$session = New-PSSession -cn ($ADDSServer+"."+$FQDN) -Credential $mycreds -Authentication Credssp
Invoke-Command -Session $session -ScriptBlock $ScriptBlockSCCMContainer -ArgumentList $SCCMServer
Remove-PSSession -VMName ($ADDSServer+"."+$FQDN)
# This Installs and WSUS and ReportViewer 2008 - from PMM-HowtoInstallSCCM2012-051118-1513-16.pdf - pages 92-106
# Variables
$WSUSContentPath = "C:\WSUS"
$TestWSUSContentPath = Test-Path $WSUSContentPath
$WSUSToolsPath = "C:\Program Files\Update Services\Tools\"
$WSUSBPAReport = "WSUS-BPA-Report.txt"
# Log start of WSUS install
log "Begin WSUS install."
# Make WSUS Directory for storing Content
If($TestWSUSContentPath -eq $true) {
log "WSUS content path already exists, moving forward"
}
Else {
log "Creating WSUS content directory..."
New-Item -Path "C:\" -Name WSUS -ItemType Directory
}
# Install WSUS with Management Tools
log "Install WSUS with Management Tools"
Start-Sleep -s 30
Install-WindowsFeature -Name UpdateServices -IncludeManagementTools
# Define WSUS content directory
Start-Sleep -s 30
cd $WSUSToolsPath
log "Setting WSUS content path to C:\WSUS."
.\wsusutil.exe postinstall CONTENT_DIR=C:\WSUS\Content
# This Installs and configures WDS according to pages 45 through 59
#Install the WDS Feature including the Management Tools
log "Install WVD"
Install-WindowsFeature wds-deployment -includemanagementtools
#Configure to WDS Service to delay start
log "Configure to WDS Service to delay start"
sc.exe config WDSServer start= delayed-auto
#Wait for the WDS initialization to complete
Start-Sleep -s 90
#Start the WDS Service
log "Start the WDS Service"
net stop WDSServer
net start WDSServer
#Set the Remote Installation Path to C:\RemoteInstall
log "Set the Remote Installation Path to C:\RemoteInstall"
wdsutil /initialize-server /remInst:"C:\RemoteInstall"
#Configure WDS to respond to all Client Computers
log "Configure WDS to respond to all Client Computers"
wdsutil /set-server /AnswerClients:All
#Configure Respone Delay to 1 second
log "Configure Respone Delay to 1 second"
wdsutil /set-server /Responsedelay:1
# This creates the IIS Roles, Features, configurations incl BITS pages 65 through 81
#Install the IIS role including management tools
log "Install the IIS role including management tools"
Install-WindowsFeature -name Web-Server -IncludeManagementTools
log "Enable various IIS Features..."
#Enable Web Server Features
Log "Installing IIS-HttpRedirect"
Enable-WindowsOptionalFeature -Online -FeatureName IIS-HttpRedirect
Log "Installing IIS-WebDav"
Enable-WindowsOptionalFeature -Online -FeatureName IIS-WebDav
#Enable application development Features
Log "Installing IIS-ApplicationDevelopment"
Enable-WindowsOptionalFeature -Online -FeatureName IIS-ApplicationDevelopment
Log "Installing IIS-ASPNET"
Enable-WindowsOptionalFeature -Online -FeatureName IIS-ASPNET -All
Log "Installing IIS-ASP"
Enable-WindowsOptionalFeature -Online -FeatureName IIS-ASP -All
Log "Installing Web-Asp-Net45"
Add-WindowsFeature Web-Asp-Net45
Log "Installing Web-Net-Ext45"
Add-WindowsFeature Web-Net-Ext45
Log "Installing IIS-ISAPIExtensions"
Enable-WindowsOptionalFeature -Online -FeatureName IIS-ISAPIExtensions
Log "Installing IIS-ISAPIFILTER"
Enable-WindowsOptionalFeature -Online -FeatureName IIS-ISAPIFILTER
#Enable Haalth and Diagnostics Features
Log "Installing IIS-HTTPlogging"
Enable-WindowsOptionalFeature -Online -FeatureName IIS-HTTPlogging
Log "Installing IIS-LoggingLibraries"
Enable-WindowsOptionalFeature -Online -FeatureName IIS-LoggingLibraries
Log "Installing IIS-RequestMonitor"
Enable-WindowsOptionalFeature -Online -FeatureName IIS-RequestMonitor
Log "Installing IIS-HttpTracing"
Enable-WindowsOptionalFeature -Online -FeatureName IIS-HttpTracing
#Enable Security Features
Log "Installing IIS-BasicAuthentication"
Enable-WindowsOptionalFeature -Online -FeatureName IIS-BasicAuthentication
Log "Installing IIS-WindowsAuthentication"
Enable-WindowsOptionalFeature -Online -FeatureName IIS-WindowsAuthentication
Log "Installing IIS-URLAuthorization"
Enable-WindowsOptionalFeature -Online -FeatureName IIS-URLAuthorization
Log "Installing IIS-RequestFiltering"
Enable-WindowsOptionalFeature -Online -FeatureName IIS-RequestFiltering
Log "Installing IIS-IPSecurity"
Enable-WindowsOptionalFeature -Online -FeatureName IIS-IPSecurity
#Enable Managent tools Features
Log "Installing IIS-IIS6ManagementCompatibility"
Enable-WindowsOptionalFeature -Online -FeatureName IIS-IIS6ManagementCompatibility
Log "Installing IIS-LegacyScripts"
Enable-WindowsOptionalFeature -Online -FeatureName IIS-LegacyScripts -all
Log "Installing IIS-WMICompatibility"
Enable-WindowsOptionalFeature -Online -FeatureName IIS-WMICompatibility -all
Log "Installing IIS-ManagementService"
Enable-WindowsOptionalFeature -Online -FeatureName IIS-ManagementService
Log "Installing IIS-ManagementScriptingTools"
Enable-WindowsOptionalFeature -Online -FeatureName IIS-ManagementScriptingTools
Log "Installing Web-Lgcy-Mgmt-Console"
Add-WindowsFeature Web-Lgcy-Mgmt-Console
#Enable WebDav Authoring
log "Enable WebDav Authoring"
Set-WebConfigurationProperty -Filter system.webServer/webdav/authoring -PSPath "MACHINE/WEBROOT/APPHOST" -Location "Default Web Site" -Name Enabled -Value True
#Add new WebDav Authoring rule
log "Add new WebDav Authoring rule"
$newRule = @{
users="*"
path="*"
access="Read"
}
Add-WebConfiguration -Filter system.webServer/webdav/authoringRules -PSPath "MACHINE/WEBROOT/APPHOST" -Location "Default Web Site" -Value $newRule
#Set Allow Anonymous Property Queries to true
log "Set Allow Anonymous Property Queries to true"
C:\Windows\System32\InetSrv\AppCmd set config "Default Web Site/" /section:system.webServer/webdav/authoring /properties.allowAnonymousPropfind:true /commit:apphost
#Set Allow Custom Propertiess to false
log "Set Allow Custom Propertiess to false"
C:\Windows\System32\InetSrv\AppCmd set config "Default Web Site/" /section:system.webServer/webdav/authoring /properties.allowCustomProperties:false /commit:apphost
#Set Allow Property Queries with Infinite Depth to true
log "Set Allow Property Queries with Infinite Depth to true"
C:\Windows\System32\InetSrv\AppCmd set config "Default Web Site/" /section:system.webServer/webdav/authoring /properties.allowInfinitePropfindDepth:true /commit:apphost
#Enable Windows Authentication on Default Web Site
log "Enable Windows Authentication on Default Web Site"
Set-WebConfigurationProperty -filter "/system.webServer/security/authentication/windowsAuthentication" -name enabled -value true -PSPath "IIS:\" -location "Default Web Site"
#Install Remote Differential Compression feature including management tools
log "Install Remote Differential Compression feature including management tools"
Install-WindowsFeature -name RDC -IncludeManagementTools
#Install BITS feature including management tools
log "Install BITS feature including management tools"
Install-WindowsFeature -name BITS -IncludeManagementTools
#Allow all fileExtensions to be used
log "Allow all fileExtensions to be used"
Start-Sleep -s 60
((Get-Content -path C:\Windows\System32\inetsrv\config\applicationHost.config -Raw) -replace ' allowed="false" />',' allowed="true" />') | Set-Content -Path C:\Windows\System32\inetsrv\config\applicationHost.config
# Invoke Best Practices Analyzer
log "Invoke Best Practices Analyzer"
Invoke-BpaModel -ModelId Microsoft/Windows/UpdateServices
# Get BPA Report and save to log
log "Get BPA Report and save to log"
Get-BpaResult -ModelId Microsoft/Windows/UpdateServices | Select Title,Severity,Compliance | Format-List | Out-file -FilePath $Store$WSUSBPAReport
log "WSUS is installed."
# Intall ReportViewer 2008 silently
log "Downloading ReportViewer 2008"
Invoke-WebRequest -Uri "https://download.microsoft.com/download/2/d/8/2d889b35-c4db-49c6-ae19-e5a0c7c2b24d/ReportViewer.exe" -OutFile "C:\Packages\Plugins\ReportViewer.exe"
sleep -Seconds 3
log "Installing ReportViewer 2008"
Start-Process -file msiexec -arg "/i C:\packages\plugins\ReportViewer.exe /q" | Wait-process
#Install ADK
log "Downloading ADK"
Invoke-WebRequest -Uri "http://download.microsoft.com/download/B/E/6/BE63E3A5-5D1C-43E7-9875-DFA2B301EC70/adk/adksetup.exe" -OutFile "C:\Packages\Plugins\adksetup.exe"
sleep -Seconds 3
log "Installing ADK"
$SetupSwitches = "/Features OptionId.DeploymentTools OptionId.ImagingAndConfigurationDesigner OptionId.ICDConfigurationDesigner OptionId.UserStateMigrationTool /norestart /quiet /ceip off"
Start-Process -FilePath C:\Packages\Plugins\adksetup.exe -ArgumentList $SetupSwitches -NoNewWindow -Wait
#Install WINPE
log "Downloading WINPE"
Invoke-WebRequest -Uri "http://download.microsoft.com/download/D/7/E/D7E22261-D0B3-4ED6-8151-5E002C7F823D/adkwinpeaddons/adkwinpesetup.exe" -OutFile "C:\Packages\Plugins\adkwinpesetup.exe"
sleep -Seconds 3
log "Installing WINPE"
$SetupSwitches = "/Features OptionId.WindowsPreinstallationEnvironment /norestart /quiet /ceip off"
Start-Process -FilePath C:\Packages\Plugins\adkwinpesetup.exe -ArgumentList $SetupSwitches -NoNewWindow -Wait
#Install SCCM
Start-Sleep -s 300
$SCCMSetupScript = "ConfigMgrSetup.ini"
$InstallPath = "C:\Packages\Plugins\Microsoft.Compute.CustomScriptExtension\1.9.5\Downloads\0"
$ImageISOName = "mu_system_center_configuration_manager_current_branch_version_1802_x86_x64_dvd_12064903.iso"
#Create the necesary SCCM Downloads folder
New-Item -Path C:\Downloads -ItemType Directory
#Mount disk image SCCM ISO and get the driveletter
$mountResult = Mount-DiskImage -ImagePath ($InstallPath+"\"+$ImageISOName) -PassThru
log $mountResult
$ISODriveLetter = ($mountResult | Get-Volume).DriveLetter
log "ISODriveLetter:'$ISODriveLetter'"
#Wait for the mount to complete
log "wait 30 sec to allow ISO mount to complete"
Start-Sleep -s 30
#Update the values inside the .ini file
if ($sqlHostName -ne "sql-01")
{
$filePath = $CurrentScriptLocation+'\'+'ConfigMgrSetup.ini'
$tempFilePath = "$env:TEMP\$($filePath | Split-Path -Leaf)"
$find = 'sql-01'
$replace = $sqlHostName
(Get-Content -Path $filePath) -replace $find, $replace | Add-Content -Path $tempFilePath
Remove-Item -Path $filePath
Move-Item -Path $tempFilePath -Destination $filePath
}
if ($SCCMServer -ne "sccm-01")
{
$filePath = $CurrentScriptLocation+'\'+'ConfigMgrSetup.ini'
$tempFilePath = "$env:TEMP\$($filePath | Split-Path -Leaf)"
$find = 'sccm-01'
$replace = $SCCMServer
(Get-Content -Path $filePath) -replace $find, $replace | Add-Content -Path $tempFilePath
Remove-Item -Path $filePath
Move-Item -Path $tempFilePath -Destination $filePath
}
if ($FQDN -ne "contoso.com")
{
$filePath = $CurrentScriptLocation+'\'+'ConfigMgrSetup.ini'
$tempFilePath = "$env:TEMP\$($filePath | Split-Path -Leaf)"
$find = 'contoso.com'
$replace = $FQDN
(Get-Content -Path $filePath) -replace $find, $replace | Add-Content -Path $tempFilePath
Remove-Item -Path $filePath
Move-Item -Path $tempFilePath -Destination $filePath
}
$SCCMSetupScriptFullPath = $InstallPath + "\" + $SCCMSetupScript
$SCCMInstall = $ISODriveLetter+":\SMSSETUP\BIN\X64\setup.exe"
#Start-Process cmd.exe -ArgumentList "/C $SCCMInstall /script c:\RDSG\SCCMSetupScript.ini"
log "SCCM Install:'$SCCMInstall'"
log "SCCM Scriptpath: '$SCCMSetupScriptFullPath'"
& $SCCMInstall /script $SCCMSetupScriptFullPath
#Wait 1 minute to make sure SCCM Setup created a logfile
Start-Sleep -s 60
$LogFileToCheck = "C:\ConfigMgrSetup.log"
$StringToCheck = "Exiting ConfigMgr Setup Bootstrapper"
$NumberOfLinesToCheck = 5
$Sleeptime = 30
$CheckCount = 0
$Match = 0
log "SCCM-PS-Extension COMPLETED, please wait for SCCM Install to complete ~30 min..."
Do
{
$Selection = Get-Content -Path $LogFileToCheck | Select-Object -Last $NumberOfLinesToCheck
If($Find = select-string -pattern $StringToCheck -InputObject $Selection)
{
$Match = 1
log "String '$StringToCheck' was found in $LogFileToCheck, exiting..."
}
else
{
$CheckCount++
log "Now checked $CheckCount times."
log "String '$StringToCheck' is still not found, seeping for $Sleeptime seconds and then rechecking."
Start-Sleep -s $Sleeptime # this is where powershell waits for however long we want and then rechecks
}
} While ($Match -ne 1)
#Set Domain Admins and Admin user to role Full Administrators
Remove-ImpersonateUser
$AdminUserUPN = $NetBiosDomainName+"\"+$AdminUser
$DomainAdminsUPN = $NetBiosDomainName+"\domain admins"
$SCCMServerUPN = $SCCMServer+"."+$FQDN
set-location "C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin"
Import-Module .\ConfigurationManager.psd1
New-PSDrive -Name "TST" -PSProvider "AdminUI.PS.Provider\CMSite" -Root $SCCMServerUPN -Description "SCCM TST Site"
CD TST:
New-CMAdministrativeUser -Name $AdminUserUPN -RoleName "Full Administrator"
New-CMAdministrativeUser -Name $DomainAdminsUPN -RoleName "Full Administrator"
Get-CMAdministrativeUser