-
Notifications
You must be signed in to change notification settings - Fork 2
/
ImportFromURL.psm1
63 lines (42 loc) · 1.78 KB
/
ImportFromURL.psm1
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
function ImportFromURL {
param(
[Parameter(Mandatory = $false,ValueFromPipeLine = $true)]
[string]$URL,
[Parameter(Mandatory = $false)]
[switch]$DLL,
[Parameter(Mandatory = $false)]
[switch]$Ps1,
[Parameter(Mandatory = $false)]
[switch]$Psm1
)
process {
if (($URL -as [System.URI]).IsAbsoluteUri -eq $False) {
Write-Verbose "URL is Missing http:// or https://"
break
}
if ($URL -match ".DLL" -or $DLL -eq $true) {
try{
Import-Module ([System.Reflection.Assembly]::Load((Invoke-WebRequest -UseBasicParsing -Uri $URL).content)) -ErrorAction SilentlyContinue > $null
}catch{
Write-Verbose "Import-Module Failed to Import DLL, Make sure the Url is a direct link to the file."
}
break
}
if ($URL -match ".psm1" -or $Psm1 -eq $true) {
try{
New-Module -Name "$URL" -ScriptBlock ([Scriptblock]::Create((New-Object System.Net.WebClient).DownloadString($URL))) -ErrorAction SilentlyContinue > $null
}catch{
Write-Verbose "Import-Module Failed to Import Psm1 Module, Make sure the Url is a direct link to the raw code"
}
break
}
if ($URL -match ".ps1" -or $Ps1 -eq $true) {
iex ((New-Object System.Net.WebClient).DownloadString($URL))
Write-Verbose "Attempting to invoke the Ps1 script (There is no error handling for .Ps1 scripts)"
Write-Verbose "Windows Bug Tip: If a script prompts for UAC and then force closes the Session, Try running the session as admin"
break
}
Write-Verbose "The URL does not conatin any of file extensions: .DLL, .Ps1, or Psm1, or is Invailed."
Write-Verbose "Please add the -DLL, -Ps1 or -Psm1 parameter to let the function know what file type it is."
}
}