-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathARC-OnboardingScript.ps1
More file actions
68 lines (56 loc) · 3.09 KB
/
Copy pathARC-OnboardingScript.ps1
File metadata and controls
68 lines (56 loc) · 3.09 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
$global:scriptPath = $myinvocation.mycommand.definition
function Restart-AsAdmin {
$pwshCommand = "powershell"
if ($PSVersionTable.PSVersion.Major -ge 6) {
$pwshCommand = "pwsh"
}
try {
Write-Host "This script requires administrator permissions to install the Azure Connected Machine Agent. Attempting to restart script with elevated permissions..."
$arguments = "-NoExit -Command `"& '$scriptPath'`""
Start-Process $pwshCommand -Verb runAs -ArgumentList $arguments
exit 0
} catch {
throw "Failed to elevate permissions. Please run this script as Administrator."
}
}
try {
if (-not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
if ([System.Environment]::UserInteractive) {
Restart-AsAdmin
} else {
throw "This script requires administrator permissions to install the Azure Connected Machine Agent. Please run this script as Administrator."
}
}
$env:SUBSCRIPTION_ID = "d9ba3041-b3b8-44e1-b381-0fe49ab5876d";
$env:RESOURCE_GROUP = "PRD-GWC-AVS-ARC-RG-01";
$env:TENANT_ID = "e8c64f0c-dfd3-414a-8c04-7d70ac6492be";
$env:LOCATION = "germanywestcentral";
$env:AUTH_TYPE = "token";
$env:CORRELATION_ID = "1c2180e4-9ef4-4bc7-988a-cacc2856c4b3";
$env:CLOUD = "AzureCloud";
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor 3072;
$azcmagentPath = Join-Path $env:SystemRoot "AzureConnectedMachineAgent"
if (-Not (Test-Path -Path $azcmagentPath)) {
New-Item -Path $azcmagentPath -ItemType Directory
Write-Output "Directory '$azcmagentPath' created"
}
$tempPath = Join-Path $azcmagentPath "temp"
if (-Not (Test-Path -Path $tempPath)) {
New-Item -Path $tempPath -ItemType Directory
Write-Output "Directory '$tempPath' created"
}
$installScriptPath = Join-Path $tempPath "install_windows_azcmagent.ps1"
# Download the installation package
Invoke-WebRequest -UseBasicParsing -Uri "https://gbl.his.arc.azure.com/azcmagent-windows" -TimeoutSec 30 -OutFile "$installScriptPath";
# Install the hybrid agent
& "$installScriptPath";
if ($LASTEXITCODE -ne 0) { exit 1; }
Start-Sleep -Seconds 5;
# Run connect command
& "$env:ProgramW6432\AzureConnectedMachineAgent\azcmagent.exe" connect --resource-group "$env:RESOURCE_GROUP" --tenant-id "$env:TENANT_ID" --location "$env:LOCATION" --subscription-id "$env:SUBSCRIPTION_ID" --cloud "$env:CLOUD" --correlation-id "$env:CORRELATION_ID";
}
catch {
$logBody = @{subscriptionId="$env:SUBSCRIPTION_ID";resourceGroup="$env:RESOURCE_GROUP";tenantId="$env:TENANT_ID";location="$env:LOCATION";correlationId="$env:CORRELATION_ID";authType="$env:AUTH_TYPE";operation="onboarding";messageType=$_.FullyQualifiedErrorId;message="$_";};
Invoke-WebRequest -UseBasicParsing -Uri "https://gbl.his.arc.azure.com/log" -Method "PUT" -Body ($logBody | ConvertTo-Json) | out-null;
Write-Host -ForegroundColor red $_.Exception;
}