This repository has been archived by the owner on Apr 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathInstall.ps1
executable file
·98 lines (73 loc) · 2.99 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
#requires -Version 3.0
<#
.SYNOPSIS
Basic Installer for the UniFiTooling PowerShell Module
.DESCRIPTION
Basic Installer for the enabling Technology UniFiTooling PowerShell Module
.EXAMPLE
PS C:\> Install-Module -Name 'UniFiTooling' -Scope CurrentUser
Install the module for the Current User with PowerShellGet directly from the Powershell Gallery, Preferred method
.EXAMPLE
PS C:\> Install-Module -Name 'UniFiTooling' -Scope AllUsers
Install the module for the All Users with PowerShellGet directly from the Powershell Gallery, Preferred method.
Run this in an administrative PowerShell prompt (Elevated).
.EXAMPLE
PS C:\> .\Install.ps1
Basic Installer for the UniFiTooling PowerShell Module
.EXAMPLE
PS C:\> iex (New-Object Net.WebClient).DownloadString("https://github.com/Enatec/UniFiTooling/raw/master/Install.ps1")
Basic Installer for the UniFiTooling PowerShell Module
.NOTES
This is a unsupported method to install the UniFiTooling PowerShell Module!
.LINK
#>
[CmdletBinding(ConfirmImpact = 'Low')]
param ()
begin
{
# Variables
$ModuleName = 'UniFiTooling'
$DownloadURL = 'https://github.com/Enatec/UniFiTooling/raw/master/release/UniFiTooling-current.zip'
}
process
{
try
{
# Download and install the module
$webclient = (New-Object -TypeName System.Net.WebClient)
$file = "$($env:TEMP)\$($ModuleName).zip"
Write-Output -InputObject ('Downloading latest version of {0} from {1}' -f $ModuleName, $DownloadURL)
$webclient.DownloadFile($DownloadURL, $file)
Write-Output -InputObject ('File saved to {0}' -f $file)
$targetondisk = "$($env:USERPROFILE)\Documents\WindowsPowerShell\Modules\$($ModuleName)"
$null = (New-Item -ItemType Directory -Force -Path $targetondisk)
$shell_app = (New-Object -ComObject shell.application)
$zip_file = $shell_app.namespace($file)
Write-Output -InputObject ('Uncompressing the Zip file to {0}' -f $targetondisk)
$destination = $shell_app.namespace($targetondisk)
$destination.Copyhere($zip_file.items(), 0x10)
}
catch
{
# get error record
[Management.Automation.ErrorRecord]$e = $_
# retrieve information about runtime error
$info = [PSCustomObject]@{
Exception = $e.Exception.Message
Reason = $e.CategoryInfo.Reason
Target = $e.CategoryInfo.TargetName
Script = $e.InvocationInfo.ScriptName
Line = $e.InvocationInfo.ScriptLineNumber
Column = $e.InvocationInfo.OffsetInLine
}
# output information. Post-process collected info, and log info (optional)
Write-Verbose -Message $info
Write-Error -Message ($info.Exception) -TargetObject ($info.Target) -ErrorAction Stop
break
}
}
end
{
Write-Output -InputObject 'Module has been installed!'
Write-Output -InputObject ('You can now import the module with: Import-Module -Name {0}' -f $ModuleName)
}