-
Notifications
You must be signed in to change notification settings - Fork 212
/
Install.ps1
108 lines (95 loc) · 2.92 KB
/
Install.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
[CmdletBinding()]
param (
[string]$Path,
[string]$Version = 'master'
)
$localpath = $(Join-Path -Path (Split-Path -Path $profile) -ChildPath '\Modules\ReportingServicesTools')
try
{
if ($Path.length -eq 0)
{
if ($PSCommandPath.Length -gt 0)
{
$path = Split-Path $PSCommandPath
if ($path -match "github")
{
$path = $localpath
}
}
else
{
$path = $localpath
}
}
}
catch
{
$path = $localpath
}
if ($path.length -eq 0)
{
$path = $localpath
}
if ((Get-Command -Module ReportingServicesTools).count -ne 0)
{
Write-Output "Removing existing ReportingServiceTools Module..."
Remove-Module ReportingServicesTools -ErrorAction Stop
}
$url = "https://github.com/Microsoft/ReportingServicesTools/archive/$Version.zip"
$temp = ([System.IO.Path]::GetTempPath()).TrimEnd("\")
$zipfile = "$temp\ReportingServicesTools.zip"
if (!(Test-Path -Path $path))
{
try
{
Write-Output "Creating directory: $path..."
New-Item -Path $path -ItemType Directory | Out-Null
}
catch
{
throw "Can't create $Path. You may need to Run as Administrator!"
}
}
else
{
try
{
Write-Output "Deleting previously installed module..."
Remove-Item -Path "$path\*" -Force -Recurse
}
catch
{
throw "Can't delete $Path. You may need to Run as Administrator!"
}
}
Write-Output "Downloading archive from ReportingServiceTools GitHub..."
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
try
{
Invoke-WebRequest $url -OutFile $zipfile
}
catch
{
#try with default proxy and usersettings
Write-Output "...Probably using a proxy for internet access. Trying default proxy settings..."
(New-Object System.Net.WebClient).Proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
Invoke-WebRequest $url -OutFile $zipfile -ErrorAction Stop
}
# Unblock if there's a block
Unblock-File $zipfile -ErrorAction SilentlyContinue
# Keep it backwards compatible
Write-Output "Unzipping archive..."
$shell = New-Object -COM Shell.Application
$zipPackage = $shell.NameSpace($zipfile)
$destinationFolder = $shell.NameSpace($temp)
$destinationFolder.CopyHere($zipPackage.Items())
Move-Item -Path "$temp\ReportingServicesTools-$Version\*" $path
Write-Output "ReportingServicesTools has been successfully downloaded to $path!"
Write-Output "Cleaning up..."
Remove-Item -Path "$temp\ReportingServicesTools-$Version"
Remove-Item -Path $zipfile
Write-Output "Importing ReportingServicesTools Module..."
Import-Module "$path\ReportingServicesTools\ReportingServicesTools.psd1" -Force
Write-Output "ReportingServicesTools Module was successfully imported!"
Get-Command -Module ReportingServicesTools
Write-Output "`n`nIf you experience any function missing errors after update, please restart PowerShell or reload your profile."