private/Software/Assert-OSDeployAdministrator.ps1
|
<#
.SYNOPSIS Throws a terminating error when the current session is not elevated. .DESCRIPTION Checks whether the current Windows session is running with Administrator privileges using WindowsPrincipal and the Administrator built-in role. Throws a terminating error if the check fails. Called internally by Install-OSDeploySoftware before performing any installation that requires Administrator rights (ADK, MDT). .NOTES Author: David Segura Company: Recast Software Windows-only. Not exported from the module. Change Summary: #> function Assert-OSDeployAdministrator { $currentIdentity = [System.Security.Principal.WindowsIdentity]::GetCurrent() $principal = [System.Security.Principal.WindowsPrincipal]::new($currentIdentity) if (-not $principal.IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator)) { throw 'Install-OSDeploySoftware must be run from an elevated PowerShell session.' } } |