-
Notifications
You must be signed in to change notification settings - Fork 3
/
Download-and-Install-Azure-Portal-app.ps1
133 lines (91 loc) · 6.25 KB
/
Download-and-Install-Azure-Portal-app.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<#
.SYNOPSIS
A script used to download and install the Microsoft Azure Portal app.
.DESCRIPTION
A script used to download the Azure Portal app on a Windows Server 2016/2019/2022 or Windows 10/11.
The .exe file will be downloaded in the Azure Portal app folder under the Temp folder.
After installation the Azure Portal app folder and the .exe file will be deleted.
.NOTES
Filename: Download-and-Install-Azure-Portal-app.ps1
Created: 02/01/2020
Last modified: 02/09/2022
Author: Wim Matthyssen
OS: Windows Server 2016/2019/2022 or Windows 10/11
PowerShell: 5.1
Requires: -RunAsAdministrator
OS: Windows 10, Windows 11, Windows Server 2016, Windows Server 2019 and Windows Server 2022
Version: 2.1
Action: Change variables were needed to fit your needs.
Disclaimer: This script is provided "As Is" with no warranties.
.EXAMPLE
Download-and-Install-Azure-Portal-app.ps1
.LINK
https://wmatthyssen.com/2020/01/02/download-and-install-the-azure-portal-app-with-powershell/
#>
## ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
## Variables
$tempFolderName = "Temp"
$tempFolder = "C:\" + $tempFolderName +"\"
$itemType = "Directory"
$azurePortalAppFolderName = "Azure Portal app"
$tempAzurePortalAppFolder = $tempFolder + $azurePortalAppFolderName
$azurePortalAppUrl = "https://portal.azure.com/app/Download?acceptLicense=true"
$azurePortalAppExe = "AzurePortalInstaller.exe"
$azurePortalAppPath = $tempAzurePortalAppFolder + "\" + $azurePortalAppExe
$global:currenttime= Set-PSBreakpoint -Variable currenttime -Mode Read -Action {$global:currenttime= Get-Date -UFormat "%A %m/%d/%Y %R"}
$foregroundColor1 = "Red"
$foregroundColor2 = "Yellow"
$writeEmptyLine = "`n"
$writeSeperatorSpaces = " - "
## ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
## Check if running as Administrator, otherwise close the PowerShell window
$currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
$isAdministrator = $currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
if ($isAdministrator -eq $false) {
Write-Host ($writeEmptyLine + "# Please run PowerShell as Administrator" + $writeSeperatorSpaces + $currentTime)`
-foregroundcolor $foregroundColor1 $writeEmptyLine
Start-Sleep -s 5
exit
}
## ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
## Start script execution
Write-Host ($writeEmptyLine + "# Script started. Without any errors, it will need around 1 minute to complete" + $writeSeperatorSpaces + $currentTime)`
-foregroundcolor $foregroundColor1 $writeEmptyLine
## ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
## Create C:\Temp folder if not exists
If(!(test-path $tempFolder))
{
New-Item -Path "C:\" -Name $tempFolderName -ItemType $itemType -Force | Out-Null
}
Write-Host ($writeEmptyLine + "# $tempFolderName folder available" + $writeSeperatorSpaces + $currentTime)`
-foregroundcolor $foregroundColor2 $writeEmptyLine
## ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
## Create Azure Portal app folder in C:\Temp if not exists
If(!(test-path $tempAzurePortalAppFolder))
{
New-Item -Path $tempFolder -Name $azurePortalAppFolderName -ItemType $itemType | Out-Null
}
Write-Host ($writeEmptyLine + "# $azurePortalAppFolderName folder available $tempFolderName folder" + $writeSeperatorSpaces + $currentTime)`
-foregroundcolor $foregroundColor2 $writeEmptyLine
## ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
## Download the Azure Portal app to Temp folder
(New-Object System.Net.WebClient).DownloadFile($azurePortalAppUrl, $azurePortalAppPath)
Write-Host ($writeEmptyLine + "# $azurePortalAppExe available" + $writeSeperatorSpaces + $currentTime)`
-foregroundcolor $foregroundColor2 $writeEmptyLine
## ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
## Install the Azure Portal app
& $azurePortalAppPath
Write-Host ($writeEmptyLine + "# The $AzurePortalAppFolderName is installed, you can now logon with your credentials" + $writeSeperatorSpaces + $currentTime)`
-foregroundcolor $foregroundColor2 $writeEmptyLine
## ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
## Remove AzurePortalInstaller.exe file and Azure Portal app folder from Temp folder after installation
Start-Sleep -s 6
Get-ChildItem -Path $tempAzurePortalAppFolder -Force -Recurse | Remove-Item -Force -Recurse
Remove-Item $tempAzurePortalAppFolder -Force -Recurse
Write-Host ($writeEmptyLine + "# $azurePortalAppExe and $AzurePortalAppFolderName folder are removed" + $writeSeperatorSpaces + $currentTime)`
-foregroundcolor $foregroundColor2 $writeEmptyLine
## ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
## Write script completed
Write-Host ($writeEmptyLine + "# Script completed" + $writeSeperatorSpaces + $currentTime)`
-foregroundcolor $foregroundColor1 $writeEmptyLine
## ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------