-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.ps1
61 lines (49 loc) · 1.49 KB
/
setup.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
$DATE = Get-Date -UFormat '%Y%m%d_%H%M%S'
$URL_BASE = 'https://raw.githubusercontent.com/andylytical/powershell/main'
function Backup-File {
param(
[Parameter(Mandatory = $true)]
[string]$filepath
)
if ( Test-Path -Path $filepath -PathType Leaf ) {
get-item $filepath | rename-item -newname { $_.Name + $DATE }
}
}
function Install-FileFromURL {
param(
[Parameter(Mandatory = $true)]
[string]$url,
[Parameter(Mandatory = $true)]
[string]$target_dir,
[Parameter()]
[string]$target_filename = ''
)
if ( $target_filename.Length -lt 1 ) {
$target_filename = $url.split('/')[-1]
}
$outfile = [IO.Path]::Combine( $target_dir, $target_filename )
Backup-File $outfile
Invoke-WebRequest -OutFile $outfile $url
}
# Dictionary of filename -> target install dir
$files = @{
'custom_startup.ps1' = [IO.Path]::Combine( $env:OneDrive, 'Startup' )
'Microsoft.PowerShell_profile.ps1' = [IO.Path]::Combine( $env:USERPROFILE, 'Documents', 'WindowsPowerShell' )
}
$files.GetEnumerator() | ForEach-Object {
$fn = $_.Key
$target_dir = $_.Value
Install-FileFromURL `
-url "${URL_BASE}/${fn}" `
-target_dir $target_dir
}
# # custom_startup
# $fn = 'custom_startup.ps1'
# Install-FileFromURL `
# -url "${URL_BASE}/${fn}" `
# -target_dir ( [IO.Path]::Combine( $env:OneDrive, 'Startup' ) )
# # Powershell profile
# $fn = (get-item $profile).Name
# Install-FileFromURL `
# -url "${URL_BASE}/${fn}" `
# -target_dir (get-item $profile).Directory.FullName