-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGetAzurePowershellModule.ps1
More file actions
78 lines (70 loc) · 2.29 KB
/
Copy pathGetAzurePowershellModule.ps1
File metadata and controls
78 lines (70 loc) · 2.29 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
69
70
71
72
73
74
75
76
77
78
function Get-AzurePowershellModule
{
[cmdletbinding()]
Param(
[switch]$ShowVersion,
[switch]$Install,
[string]$Path=$null
)
BEGIN
{
If ($ShowVersion.IsPresent)
{
$Modules = Get-Module -ListAvailable
$InstalledVersion = ($Modules | Where-Object {$_.Name -eq "Azure"}).Version.ToString()
Write-Output "Installed: $InstalledVersion"
}
}
PROCESS {
Try
{
$WebSite = Invoke-WebRequest -Uri "https://github.com/Azure/azure-sdk-tools/releases/latest" -Method Get -TimeoutSec 30
}
Catch
{
Throw "Failed to get Web Content for Azure Powershell Module: $($_.Exception.Message)"
}
if ($ShowVersion.IsPresent)
{
$LatestVersion = ($WebSite.Links | Where-Object {$_.href -eq $WebSite.BaseResponse.ResponseUri.AbsolutePath}).innerText
Write-Verbose "LatestVersion = $LatestVersion"
Write-Output "Latest: $LatestVersion"
}
$DownloadURL = ($WebSite.Links | Where-Object {$_.InnerHTML -eq "Windows Standalone"}).href
Write-Verbose "DownloadURL = $DownloadURL"
If ($Path -ne $null)
{
if ((Test-Path $Path) -eq $false)
{
$OutFilePathRoot = (Get-Item $Path).Directory
}
}
if ($OutFilePathRoot -eq $null)
{
$OutFilePathRoot = $env:TEMP
}
$OutFilePath = "$($OutFilePathRoot)\$($DownloadURL.Split("/")[-1])"
Write-Verbose "OutFilePath = $($OutFilePath)"
Invoke-WebRequest -Uri $DownloadURL -OutFile $OutFilePath -Method Get -TimeoutSec 60
$LogPath = $OutFilePath.Split(".")
$LogPath[-1] = "log"
$LogPath = $LogPath -join "."
Write-Verbose "LogPath = $($LogPath)"
If ($Install.IsPresent)
{
Start-Process $OutFilePath -ArgumentList "/quiet /norestart /log $($LogPath)" -Wait -PassThru
}
else
{
Write-Output "Azure Powershell Module downloaded to: $($OutFilePath)"
}
}
END
{
If ($Install.IsPresent)
{
Remove-Item -Path $OutFilePath -Force -Verbose
}
}
}
#Get-AzurePowershellModule -Install -Verbose