forked from psget/psget
-
Notifications
You must be signed in to change notification settings - Fork 1
/
GetPsGet.ps1
54 lines (46 loc) · 2.11 KB
/
GetPsGet.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
function Install-PsGet {
$ModulePaths = @($Env:PSModulePath -split ';')
# $PsGetDestinationModulePath is mostly needed for testing purposes,
if ((Test-Path -Path Variable:PsGetDestinationModulePath) -and $PsGetDestinationModulePath) {
$Destination = $PsGetDestinationModulePath
if ($ModulePaths -notcontains $Destination) {
Write-Warning 'PsGet install destination is not included in the PSModulePath environment variable'
}
} else {
$ExpectedUserModulePath = Join-Path -Path ([Environment]::GetFolderPath('MyDocuments')) -ChildPath WindowsPowerShell\Modules
$Destination = $ModulePaths | Where-Object { $_ -eq $ExpectedUserModulePath}
if (-not $Destination) {
$Destination = $ModulePaths | Select-Object -Index 0
}
}
New-Item ($Destination + "\PsGet\") -ItemType Directory -Force | out-null
Write-Host Downloading PsGet from https://github.com/psget/psget/raw/master/PsGet/PsGet.psm1
$client = (New-Object Net.WebClient)
$client.Proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
$client.DownloadFile("https://github.com/psget/psget/raw/master/PsGet/PsGet.psm1", $Destination + "\PsGet\PsGet.psm1")
$executionPolicy = (Get-ExecutionPolicy)
$executionRestricted = ($executionPolicy -eq "Restricted")
if ($executionRestricted){
Write-Warning @"
Your execution policy is $executionPolicy, this means you will not be able import or use any scripts including modules.
To fix this change your execution policy to something like RemoteSigned.
PS> Set-ExecutionPolicy RemoteSigned
For more information execute:
PS> Get-Help about_execution_policies
"@
}
if (!$executionRestricted){
# ensure PsGet is imported from the location it was just installed to
Import-Module -Name $Destination\PsGet
}
Write-Host "PsGet is installed and ready to use" -Foreground Green
Write-Host @"
USAGE:
PS> import-module PsGet
PS> install-module PsUrl
For more details:
get-help install-module
Or visit http://psget.net
"@
}
Install-PsGet