-
Notifications
You must be signed in to change notification settings - Fork 1
/
Deploy-PSPortableLight.ps1
86 lines (68 loc) · 2.82 KB
/
Deploy-PSPortableLight.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
Function Deploy-PSPortableLight {
#Remove old package
if (Test-Path $env:ProgramData\PS7x64) {
Remove-Item $env:ProgramData\PS7x64 -Recurse -Force
}
#Download new package as zip file
Function Invoke-DLPSPortable {
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$url = "https://github.com/thetaylorlee/psportable/archive/main.zip"
$output = "$env:ProgramData\PS7x64.zip"
$wc = New-Object System.Net.WebClient
$wc.DownloadFile($url, $output)
}; Invoke-DLPSPortable
#Unzip to path download package
function Invoke-Unzip {
<#
.DESCRIPTION
Provides robust zip file extraction by attempting 3 possible methods.
.Parameter zipfile
Specify the zipfile location and name
.Parameter outpath
Specify the extract path for extracted files
.EXAMPLE
Extracts folder.zip to c:\folder
Invoke-Unzip -zipfile c:\folder.zip -outpath c:\folder
.Link
https://github.com/TheTaylorLee/AdminToolbox
#>
[cmdletbinding()]
param(
[string]$zipfile,
[string]$outpath
)
if (Get-Command expand-archive -ErrorAction 'SilentlyContinue') {
Expand-Archive -Path $zipfile -DestinationPath $outpath
}
else {
try {
#Allows for unzipping folders in older versions of powershell if .net 4.5 or newer exists
Add-Type -AssemblyName System.IO.Compression.FileSystem
[System.IO.Compression.ZipFile]::ExtractToDirectory($zipfile, $outpath)
}
catch {
#If .net 4.5 or newer not present, com classes are used. This process is slower.
[void] (New-Item -Path $outpath -ItemType Directory -Force)
$Shell = New-Object -com Shell.Application
$Shell.Namespace($outpath).copyhere($Shell.NameSpace($zipfile).Items(), 4)
}
}
}
Invoke-Unzip -zipfile "$env:ProgramData\PS7x64.zip" -outpath "$env:ProgramData"
Rename-Item "$env:ProgramData\PSPortable-main" "$env:ProgramData\PS7x64"
Remove-Item "$env:ProgramData\PS7x64.zip" -Force
#Pin shortcut to taskbar
Invoke-Item "$env:ProgramData\PS7x64\PS7-x64\pwsh.exe.lnk"
Function Show-Statement {
Write-Host "
***************************************************
* *
*" -ForegroundColor Green -NoNewline
Write-Host " Pin the open PSPortable window to the Taskbar" -ForegroundColor Yellow -NoNewline
Write-Host " *
* *
***************************************************
" -ForegroundColor Green
}
Show-Statement
}; Deploy-PSPortableLight