-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInstallSoftwares.ps1
59 lines (48 loc) · 1.82 KB
/
InstallSoftwares.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
Function CheckRunAsAdministrator()
{
#Get current user context
$CurrentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent())
#Check user is running the script is member of Administrator Group
if($CurrentUser.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator))
{
if ($dirpath -ne $null) {
Set-Location -Path $dirpath
}
$curDir = Get-Location
Write-host "Script is running with Administrator privileges!"
Write-Host "Current Working Directory: $curDir"
}
else
{
$curDir = Get-Location
#Create a new Elevated process to Start PowerShell
$ElevatedProcess = New-Object System.Diagnostics.ProcessStartInfo "PowerShell";
# Specify the current script path and name as a parameter
$ElevatedProcess.Arguments = "& '" + $script:MyInvocation.MyCommand.Path + "' -dirpath '" + $curDir + "'"
#Set the Process to elevated
$ElevatedProcess.Verb = "runas"
#Start the new elevated process
[System.Diagnostics.Process]::Start($ElevatedProcess)
#Exit from the current, unelevated, process
Exit
}
}
Function Install-Chocolatey()
{
Write-Host "Installing Chocolatey Package Management ";
Set-ExecutionPolicy Bypass -Scope Process -Force;
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072;
Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'));
}
Function Install-ChocolateyApps
{
$chocoApps = @(
"fnm"
)
foreach ($appName in $chocoApps) {
choco install $appName -y;
}
}
CheckRunAsAdministrator
Install-Chocolatey
Install-ChocolateyApps