-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpowerash.ps1
39 lines (36 loc) · 1.68 KB
/
powerash.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
Function is_elevated{
If (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(`
[Security.Principal.WindowsBuiltInRole] "Administrator")) {
Write-warning "This script requires elevated privileges to change Install Windows Features and change files."
Write-Host "Please re-launch the Powershell Session as Administrator." -foreground "red" -background "black"
break
}
}
Function choco{
try {
Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
#Force refresh env vars at all new powershell sessions for all users.
Add-Content -Path $PsHome\profile.ps1 -Value '$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")'
Add-Content -Path $PsHome\profile.ps1 -Value 'Remove-Item alias:curl -erroraction ignore'
Add-Content -Path $PsHome\profile.ps1 -Value 'new-alias grep findstr -erroraction ignore'
}
catch {
Write-Error "fail to install chocolatey"
break
}
}
Function aliases{
try {
Add-Content -Path $PsHome\profile.ps1 -Value 'Remove-Item alias:curl -erroraction ignore'
Add-Content -Path $PsHome\profile.ps1 -Value 'new-alias grep findstr -erroraction ignore'
&$PSHOME\profile.ps1
}
catch {
Write-Error "fail to set aliases"
break
}
}
is_elevated
choco
aliases