-
Notifications
You must be signed in to change notification settings - Fork 3
/
custom_data.ps1
64 lines (50 loc) · 2.78 KB
/
custom_data.ps1
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
# New-Item -Path "C:\Azure" -ItemType "directory" -Force
Set-Location -Path "C:\Azure"
Start-Transcript -Path "C:\Azure\CustomData.log"
Write-Host "=========================================================="
Write-Host "Installing Azure CLI at $(Get-Date -UFormat '%H:%M:%S')"
$ProgressPreference = 'SilentlyContinue'
Invoke-WebRequest -Uri https://aka.ms/installazurecliwindows -OutFile .\AzureCLI.msi
Start-Process msiexec.exe -Wait -ArgumentList '/I AzureCLI.msi /quiet'
Write-Host "Install complete at $(Get-Date -UFormat '%H:%M:%S')"
Write-Host "=========================================================="
Write-Host "Extending path at $(Get-Date -UFormat '%H:%M:%S')"
$AzureCliPath = 'C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\wbin'
if (Test-Path -Path $AzureCliPath) {
$Paths = $env:PATH -split ';'
if ($Paths.Contains($AzureCliPath)) {
Write-Host ("Path {0} is already in the PATH environment variable." -f $AzureCliPath)
} else {
$RegistryKey = 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment'
$Path = (Get-ItemProperty -Path $RegistryKey -Name PATH).path
Set-ItemProperty -Path $RegistryKey -Name PATH -Value "$Path;$AzureCliPath"
Write-Host ("Added path {0} to the PATH environment variable." -f $AzureCliPath)
}
}
else {
Write-Host ("ERROR: Path {0} not found." -f $AzureCliPath)
Exit 1
}
Write-Host "Path section completed at $(Get-Date -UFormat '%H:%M:%S')"
Write-Host "=========================================================="
Write-Host "Installing PowerShell 7.2.1 at $(Get-Date -UFormat '%H:%M:%S')"
$PowerShellMsiUri = 'https://github.com/PowerShell/PowerShell/releases/download/v7.2.1/PowerShell-7.2.1-win-x64.msi'
Invoke-WebRequest -Uri $PowerShellMsiUri -OutFile .\PowerShell-7.2.1-win-x64.msi
Start-Process msiexec.exe -Wait -ArgumentList '/package PowerShell-7.2.1-win-x64.msi /quiet ADD_EXPLORER_CONTEXT_MENU_OPENPOWERSHELL=1 ENABLE_PSREMOTING=1 REGISTER_MANIFEST=1 USE_MU=1 ENABLE_MU=1'
Write-Host "PowerShell 7.2.1 install complete at $(Get-Date -UFormat '%H:%M:%S')"
Write-Host "=========================================================="
Write-Host "Installing Azure Az PowerShell Module at $(Get-Date -UFormat '%H:%M:%S')"
C:\Program` Files\PowerShell\7\pwsh.exe -Command {
$PSVersionTable.PSVersion
}
C:\Program` Files\PowerShell\7\pwsh.exe -Command {
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Localmachine
Install-Module -Name Az -Scope AllUsers -Repository PSGallery -Force -Verbose
}
C:\Program` Files\PowerShell\7\pwsh.exe -Command {
Import-Module Az -Verbose
Get-Module PackageManagement,PowerShellGet,Az
}
Write-Host "Install and import complete at $(Get-Date -UFormat '%H:%M:%S')"
Write-Host "=========================================================="
Stop-Transcript