#Requires -RunAsAdministrator <# .SYNOPSIS Test-CloudScriptConnection is a function that tests the connection to CloudScript. .DESCRIPTION Test-CloudScriptConnection is a function that tests the connection to CloudScript. .NOTES Script is intended to be hosted as 'text/plain' and invoked via Invoke-Expression (iex). .EXAMPLE The 'Invoke-RestMethod' cmdlet is used to download the script. The 'Invoke-Expression' cmdlet is used to execute the script. Use the 'pipe' operator: PS C:\> Invoke-RestMethod -Uri | Invoke-Expression Use the 'Invoke-RestMethod' with parameters as the 'Invoke-Expression' argument: PS C:\> Invoke-Expression (Invoke-RestMethod -Uri ) Use the cmdlet alias 'iex' and 'irm' to condense the command: PS C:\> iex (irm ) #> $ScriptName = 'Test-CloudScriptConnection' $ScriptVersion = '1.0.0' #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)" #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') { $env:CLOUD_SCRIPT_CONNECTED = $true Write-Host -ForegroundColor 'Green' '[+] WinPE - CloudScript Connected' } #endregion #region AuditMode elseif ($WindowsPhase -eq 'AuditMode') { $env:CLOUD_SCRIPT_CONNECTED = $true Write-Host -ForegroundColor 'Green' '[+] AuditMode - CloudScript Connected' } #endregion #region OOBE elseif ($WindowsPhase -eq 'OOBE') { $env:CLOUD_SCRIPT_CONNECTED = $true Write-Host -ForegroundColor 'Green' '[+] OOBE - CloudScript Connected' } #endregion #region Windows elseif ($WindowsPhase -eq 'Windows') { $env:CLOUD_SCRIPT_CONNECTED = $true Write-Host -ForegroundColor 'Green' '[+] Windows - CloudScript Connected' } #endregion #region Other else { $env:CLOUD_SCRIPT_CONNECTED = $false Write-Host -ForegroundColor 'Red' "[!] $WindowsPhase - CloudScript NOT Connected" } #endregion $null = Stop-Transcript -ErrorAction Ignore