aboutsummaryrefslogtreecommitdiff
path: root/scripts/azure-pipelines/windows/drop-to-admin-user-prefix.ps1
blob: b4592eabd4eee44b0b36dc7969b93ad451dcdd6f (plain)
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
param(
  [string]$AdminUserPassword = $null
)

$ErrorActionPreference = 'Stop'
$ProgressPreference = 'SilentlyContinue'
if (-Not [string]::IsNullOrEmpty($AdminUserPassword)) {
  $PsExecPath = 'C:\PsExec64.exe'
  $PsExecArgs = @(
    '-u',
    'AdminUser',
    '-p',
    $AdminUserPassword,
    '-accepteula',
    '-i',
    '-h',
    'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe',
    '-ExecutionPolicy',
    'Unrestricted',
    '-File',
    $PSCommandPath
  )

  Write-Host "Executing: $PsExecPath $PsExecArgs"
  $proc = Start-Process -FilePath $PsExecPath -ArgumentList $PsExecArgs -Wait -PassThru
  exit $proc.ExitCode
}