<#PSScriptInfo .VERSION 26.10.29.1 .GUID 9670c013-d1b1-4f5d-9bd0-0fa185b9f203 .AUTHOR David Segura - Recast Software .COMPANYNAME osdcloud.com .COPYRIGHT (c) 2023 David Segura osdcloud.com. All rights reserved. .TAGS OSDeploy OSDCloud WinPE OOBE Windows AutoPilot .LICENSEURI .PROJECTURI https://github.com/OSDeploy/OSD .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS .EXTERNALSCRIPTDEPENDENCIES .RELEASENOTES Script should be executed in a Command Prompt using the following command powershell Invoke-Expression -Command (Invoke-RestMethod -Uri sandbox.osdcloud.com) This is abbreviated as powershell iex (irm sandbox.osdcloud.com) #> #Requires -RunAsAdministrator <# .SYNOPSIS PowerShell Script which supports the OSDCloud environment .DESCRIPTION PowerShell Script which supports the OSDCloud environment .NOTES Version 26.10.29.1 .LINK https://raw.githubusercontent.com/OSDeploy/OSD/master/cloud/sandbox.osdcloud.com.ps1 .EXAMPLE powershell iex (irm sandbox.osdcloud.com) #> [CmdletBinding()] param() $ScriptName = 'sandbox.osdcloud.com' $ScriptVersion = '26.10.29.1' #region Usage # Anonymous usage count: one event per run with a random id and no device or user data. $global:OSDCloudScriptEventSent = 'sandbox.osdcloud.com' & { try { [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12 $payload = @{ api_key = 'phc_2h7nQJCo41Hc5C64B2SkcEBZOvJ6mHr5xAHZyjPl3ZK' event = 'sandbox.osdcloud.com' properties = @{ distinct_id = [guid]::NewGuid().ToString() '$process_person_profile' = $false '$geoip_disable' = $true } timestamp = [datetime]::UtcNow.ToString('o') } Invoke-RestMethod -Method Post -Uri 'https://us.i.posthog.com/capture/' -Body ($payload | ConvertTo-Json -Compress) -ContentType 'application/json' -TimeoutSec 2 -ErrorAction Stop | Out-Null } catch { Write-Verbose "Usage event not sent: $($_.Exception.Message)" } } #endregion #region Initialize $Transcript = "$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-$ScriptName.log" $null = Start-Transcript -Path (Join-Path "$env:SystemRoot\Temp" $Transcript) -ErrorAction Ignore if ($env:SystemDrive -eq 'X:') { $WindowsPhase = 'WinPE' } else { $ImageState = (Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Setup\State' -ErrorAction Ignore).ImageState if ($env:UserName -eq 'defaultuser0') {$WindowsPhase = 'OOBE'} elseif ($ImageState -eq 'IMAGE_STATE_SPECIALIZE_RESEAL_TO_OOBE') {$WindowsPhase = 'Specialize'} elseif ($ImageState -eq 'IMAGE_STATE_SPECIALIZE_RESEAL_TO_AUDIT') {$WindowsPhase = 'AuditMode'} else {$WindowsPhase = 'Windows'} } Write-Host -ForegroundColor Green "[+] $ScriptName $ScriptVersion ($WindowsPhase Phase)" Invoke-Expression -Command (Invoke-RestMethod -Uri functions.osdcloud.com) #endregion #region Admin Elevation $whoiam = [system.security.principal.windowsidentity]::getcurrent().name $isElevated = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator") if ($isElevated) { Write-Host -ForegroundColor Green "[+] Running as $whoiam (Admin Elevated)" } else { Write-Host -ForegroundColor Red "[!] Running as $whoiam (NOT Admin Elevated)" Break } #endregion #region Transport Layer Security (TLS) 1.2 Write-Host -ForegroundColor Green "[+] Transport Layer Security (TLS) 1.2" [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12 #endregion #region WinPE if ($WindowsPhase -eq 'WinPE') { #Process OSDCloud startup and load Azure KeyVault dependencies osdcloud-StartWinPE -OSDCloud -KeyVault Write-Host -ForegroundColor Cyan "To start a new PowerShell session, type 'start powershell' and press enter" Write-Host -ForegroundColor Cyan "Start-OSDCloud, Start-OSDCloudGUI, or Start-OSDCloudAzure, can be run in the new PowerShell window" #Stop the startup Transcript. OSDCloud will create its own $null = Stop-Transcript -ErrorAction Ignore } #endregion #region Specialize if ($WindowsPhase -eq 'Specialize') { $null = Stop-Transcript -ErrorAction Ignore } #endregion #region AuditMode if ($WindowsPhase -eq 'AuditMode') { $null = Stop-Transcript -ErrorAction Ignore } #endregion #region OOBE if ($WindowsPhase -eq 'OOBE') { #Load everything needed to run AutoPilot and Azure KeyVault osdcloud-StartOOBE -Display -Language -DateTime -Autopilot -KeyVault -InstallWinGet -WinGetUpgrade -WinGetPwsh $null = Stop-Transcript -ErrorAction Ignore } #endregion #region Windows if ($WindowsPhase -eq 'Windows') { #Load OSD and Azure stuff $null = Stop-Transcript -ErrorAction Ignore } #endregion