#DIGIT-BS OSDCloud Logic gist function OSDCloudLogic { param ( [Parameter(ParameterSetName = 'School', Mandatory = $true)] [string]$School ) #================================================ # [PreOS] Update Module #================================================ if ((Get-MyComputerModel) -match 'Virtual') { Write-Host -ForegroundColor Green "Setting Display Resolution to 1600x" Set-DisRes 1600 } Write-Host -ForegroundColor Green "Updating OSD PowerShell Module" Install-Module OSD -Force Write-Host -ForegroundColor Green "Importing OSD PowerShell Module" Import-Module OSD -Force #======================================================================= # [OS] Params and Start-OSDCloud #======================================================================= Write-Host -ForegroundColor Green "Set the Global Variables for a Driver Pack name --> none" $Global:MyOSDCloud = @{ DriverPackName = 'none' #ApplyManufacturerDrivers = $false #ApplyCatalogDrivers = $false #ApplyCatalogFirmware = $false } $Params = @{ OSVersion = "Windows 10" OSBuild = "22H2" OSEdition = "Pro" OSLanguage = "de-de" ZTI = $true Firmware = $true } Start-OSDCloud @Params #================================================ # [PostOS] OOBEDeploy Configuration #================================================ Write-Host -ForegroundColor Green "Create C:\ProgramData\OSDeploy\OSDeploy.OOBEDeploy.json" $OOBEDeployJson = @' { "Autopilot": { "IsPresent": false }, "RemoveAppx": [ "Microsoft.549981C3F5F10", "Microsoft.BingWeather", "Microsoft.GetHelp", "Microsoft.Getstarted", "Microsoft.Microsoft3DViewer", "Microsoft.MicrosoftOfficeHub", "Microsoft.MicrosoftSolitaireCollection", "Microsoft.MixedReality.Portal", "Microsoft.Office.OneNote", "Microsoft.People", "Microsoft.SkypeApp", "Microsoft.Wallet", "Microsoft.WindowsCamera", "microsoft.windowscommunicationsapps", "Microsoft.WindowsFeedbackHub", "Microsoft.WindowsMaps", "Microsoft.Xbox.TCUI", "Microsoft.XboxApp", "Microsoft.XboxGameOverlay", "Microsoft.XboxGameCallableUI", "Microsoft.XboxGamingOverlay", "Microsoft.XboxIdentityProvider", "Microsoft.XboxSpeechToTextOverlay", "Microsoft.YourPhone", "Microsoft.ZuneMusic", "Microsoft.ZuneVideo" ], "UpdateDrivers": { "IsPresent": true }, "UpdateWindows": { "IsPresent": true } } '@ If (!(Test-Path "C:\ProgramData\OSDeploy")) { New-Item "C:\ProgramData\OSDeploy" -ItemType Directory -Force | Out-Null } $OOBEDeployJson | Out-File -FilePath "C:\ProgramData\OSDeploy\OSDeploy.OOBEDeploy.json" -Encoding ascii -Force #================================================ # [PostOS] AutopilotOOBE Configuration Staging #================================================ Write-Host -ForegroundColor Green "Create C:\ProgramData\OSDeploy\OSDeploy.AutopilotOOBE.json" $AutopilotOOBEJson = @" { "Assign": { "IsPresent": true }, "GroupTag": "$School", "AddToGroup": "CGRP-MDM-$School", "Hidden": [ "AssignedComputerName", "AssignedUser", "PostAction", "Assign" ], "PostAction": "Quit", "Run": "NetworkingWireless", "Docs": "https://google.com/", "Title": "DIG-IT | Produktive Umgebung | Autopilot Register" } "@ If (!(Test-Path "C:\ProgramData\OSDeploy")) { New-Item "C:\ProgramData\OSDeploy" -ItemType Directory -Force | Out-Null } $AutopilotOOBEJson | Out-File -FilePath "C:\ProgramData\OSDeploy\OSDeploy.AutopilotOOBE.json" -Encoding ascii -Force #================================================ # [PostOS] AutopilotOOBE CMD Command Line #================================================ Write-Host -ForegroundColor Green "Create C:\Windows\System32\Autopilot.cmd" $AutopilotCMD = @' PowerShell -NoL -Com Set-ExecutionPolicy RemoteSigned -Force Set Path = %PATH%;C:\Program Files\WindowsPowerShell\Scripts Start /Wait PowerShell -NoL -C Install-Module OSD -Force Start /Wait PowerShell -NoL -C Install-Module AutopilotOOBE -Force Start /Wait PowerShell -NoL -C Invoke-WebPSScript https://setkeyboard.digit-bs.osdcloud.ch Start /Wait PowerShell -NoL -C Invoke-WebPSScript https://productkey.digit-bs.osdcloud.ch Start /Wait PowerShell -NoL -C Invoke-WebPSScript https://check-autopilotprereq.osdcloud.ch REM Start /Wait PowerShell -NoL -C Invoke-WebPSScript https://intuneaadcleanup.osdcloud.ch Start /Wait PowerShell -NoL -C Invoke-WebPSScript https://start-autopilotoobe.osdcloud.ch REM Start /Wait PowerShell -NoL -C Invoke-WebPSScript https://workaround-autopilotoobe.osdcloud.ch Start /Wait PowerShell -NoL -C Start-OOBEDeploy Start /Wait PowerShell -NoL -C Invoke-WebPSScript https://cleanup.osdcloud.ch Start /Wait PowerShell -NoL -C Restart-Computer -Force '@ $AutopilotCMD | Out-File -FilePath 'C:\Windows\System32\Autopilot.cmd' -Encoding ascii -Force #================================================ # [PostOS] SetupComplete CMD Command Line #================================================ Write-Host -ForegroundColor Green "Create C:\Windows\Setup\Scripts\SetupComplete.cmd" $SetupCompleteCMD = @' '@ $SetupCompleteCMD | Out-File -FilePath 'C:\Windows\Setup\Scripts\SetupComplete.cmd' -Encoding ascii -Width 2000 -Force #======================================================================= # [PostOS] Driver Management for Microsoft Surface devices #======================================================================= $Get_Manufacturer_Info = (Get-WmiObject Win32_ComputerSystem).Manufacturer If($Get_Manufacturer_Info -like "*Microsoft*") { Write-Host -ForegroundColor Cyan "Device manufacturer is Microsoft Corporation --> need to download some drivers" $Get_Product_Info = (Get-MyComputerProduct) Write-Host -ForegroundColor Gray "Getting OSDCloudDriverPackage for this $Get_Product_Info" $DriverPack = Get-OSDCloudDriverPacks | Where-Object {($_.Product -contains $Get_Product_Info) -and ($_.OS -match $Params.OSVersion)} if ($DriverPack) { [System.String]$DownloadPath = 'C:\Drivers' if (-NOT (Test-Path "$DownloadPath")) { New-Item $DownloadPath -ItemType Directory -Force -ErrorAction Stop | Out-Null } $OutFile = Join-Path $DownloadPath $DriverPack.FileName Write-Host -ForegroundColor Cyan "ReleaseDate: $($DriverPack.ReleaseDate)" Write-Host -ForegroundColor Cyan "Name: $($DriverPack.Name)" Write-Host -ForegroundColor Cyan "Product: $($DriverPack.Product)" Write-Host -ForegroundColor Cyan "Url: $($DriverPack.Url)" if ($DriverPack.HashMD5) { Write-Host -ForegroundColor Cyan "HashMD5: $($DriverPack.HashMD5)" } Write-Host -ForegroundColor Cyan "OutFile: $OutFile" Save-WebFile -SourceUrl $DriverPack.Url -DestinationDirectory $DownloadPath -DestinationName $DriverPack.FileName if (! (Test-Path $OutFile)) { Write-Warning "$((Get-Date).ToString('yyyy-MM-dd-HHmmss')) Driver Pack failed to download" } $DriverPack | ConvertTo-Json | Out-File "$OutFile.json" -Encoding ascii -Width 2000 -Force } } #======================================================================= # Dump some variables #======================================================================= $Global:OSDCloud | Out-File C:\OSDCloud\Logs\OSDCloud_Variables.log -Force $Global:OSDCloud.DriverPack | Out-File C:\OSDCloud\Logs\OSDCloud_DriverPack_Variables.log -Force #======================================================================= # Restart-Computer #======================================================================= Write-Host -ForegroundColor Green "Restarting in 20 seconds!" Start-Sleep -Seconds 20 wpeutil reboot }