forked from chris-dalrymple/posh-gvm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGetPoshGvm.ps1
66 lines (54 loc) · 2.44 KB
/
GetPoshGvm.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
<#
Paragon for the installation script is PsGet
#>
function Install-Posh-Gvm() {
$poshGvmZipUrl = 'https://github.com/azusa/posh-gvm/archive/master.zip'
$poshGvmPath = Find-Module-Location
try {
# create temp dir
$tempDir = [guid]::NewGuid().ToString()
$tempDir = Join-Path -Path $env:TEMP -ChildPath $tempDir
New-Item -ItemType Directory $tempDir | Out-Null
# download current version
$poshGvmZip = "$tempDir\posh-gvm-master.zip"
Write-Output "Downloading posh-gvm from $poshGvmZipUrl"
$client = (New-Object Net.WebClient)
$client.Proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$client.DownloadFile($poshGvmZipUrl, $poshGvmZip)
# unzip archive
$shell = New-Object -com shell.application
$shell.namespace($tempDir).copyhere($shell.namespace($poshGvmZip).items(), 0x14)
# check if unzip successfully
if ( Test-Path "$tempDir\posh-gvm-master" ) {
if ( !(Test-Path $poshGvmPath) ) {
New-Item -ItemType Directory $poshGvmPath | Out-Null
}
Copy-Item "$tempDir\posh-gvm-master\*" $poshGvmPath -Force -Recurse
Write-Output "posh-gvm installed!"
Write-Output "Please see https://github.com/chris-dalrymple/posh-gvm#usage for details to get started."
Write-Warning "Execute 'Import-Module posh-gvm -Force' so changes take effect!"
} else {
Write-Warning 'Could not unzip archive containing posh-gvm. Most likely the archive is currupt. Please try to install again.'
}
} finally {
# clear temp dir
Remove-Item -Recurse -Force $tempDir
}
}
function Find-Module-Location {
$moduleDescriptor = Get-Module posh-gvm
if ( $moduleDescriptor ) {
return (Get-Item ($moduleDescriptor).Path).Directory.FullName
} else {
$modulePaths = @($Env:PSModulePath -split ';')
# set module path to posh default
$targetModulePath = Join-Path -Path ([Environment]::GetFolderPath('MyDocuments')) -ChildPath WindowsPowerShell\Modules
# if its not use select the first defined
if ( $modulePaths -inotcontains $targetModulePath ) {
$targetModulePath = $modulePaths | Select-Object -Index 0
}
return "$targetModulePath\posh-gvm"
}
}
Install-Posh-Gvm