This commit is contained in:
Kenneth Benzie 2024-08-09 12:54:43 +01:00
parent 2e60d0c414
commit fa5d7af0c0

View File

@ -3,85 +3,93 @@ $choices = '&Yes', '&No'
if (-Not $is_elevated) {
# Not running with elevated permissions
Write-Host "Not running as Administrator. Performing unprivileged actions..."
# Install Scoop
$scoop_installer = "$env:USERPROFILE/Downloads/ScoopInstaller.ps1"
Invoke-WebRequest -Uri https://get.scoop.sh -OutFile $scoop_installer
&$scoop_installer -ScoopDir "$env:LocalAppData/Scoop" -ScoopGlobalDir "$env:ProgramData/Scoop"
# $scoop_installer = "$env:USERPROFILE/Downloads/ScoopInstaller.ps1"
# Invoke-WebRequest -Uri https://get.scoop.sh -OutFile $scoop_installer
# &$scoop_installer -ScoopDir "$env:LocalAppData/Scoop" -ScoopGlobalDir "$env:ProgramData/Scoop"
# Get the current script's path
$ScriptPath = $MyInvocation.MyCommand.Definition
# Create a new process to run the script as administrator
$StartInfo = New-Object System.Diagnostics.ProcessStartInfo
$StartInfo.FileName = "powershell.exe"
# The command you want to run with elevated privileges
$Command = "Set-ExecutionPolicy Bypass -Scope Process -Force; " +
"[System.Net.ServicePointManager]::SecurityProtocol = " +
"[System.Net.ServicePointManager]::SecurityProtocol -bor 3072; " +
"iex ((New-Object System.Net.WebClient).DownloadString('https://git.infektor.net/config/bootstrap/raw/update/bootstrap-Windows.ps1'))"
# Add parameters to the command-line arguments
$StartInfo.Arguments = "-NoProfile -ExecutionPolicy Bypass -File `"$ScriptPath`""
# Create a temporary batch file
$batchFile = [System.IO.Path]::GetTempFileName() + ".bat"
$batchContent = "@echo off`r`n" + `
"powershell.exe -NoProfile -ExecutionPolicy Bypass -Command `"$Command`"`r`n" + `
"pause"
# Elevate privileges
$StartInfo.Verb = "runas"
# Write the batch content to the file
Set-Content -Path $batchFile -Value $batchContent
# Ensure output is visible to the user
$StartInfo.UseShellExecute = $true
$StartInfo.RedirectStandardOutput = $false
$StartInfo.RedirectStandardError = $false
$StartInfo.CreateNoWindow = $false
# Start the batch file with elevated privileges
$StartInfo = New-Object System.Diagnostics.ProcessStartInfo
$StartInfo.FileName = $batchFile
$StartInfo.Verb = "runas"
$StartInfo.UseShellExecute = $true
# Start the elevated process
[System.Diagnostics.Process]::Start($StartInfo) | Out-Null
[System.Diagnostics.Process]::Start($StartInfo) | Out-Null
# Exit the current (non-admin) process
exit
# Exit the current (non-admin) process
exit
}
# Running with elevated permissions
# Code to execute after elevation
Write-Host "Running as Administrator. Performing privileged actions..."
# Install 1Password
$decision = $Host.UI.PromptForChoice('Install 1Password', 'Proceed?', $choices, 0)
if ($decision -eq 0) {
$1password_installer = "$env:USERPROFILE/Downloads/1PasswordSetup-latest.exe"
Invoke-WebRequest -Uri "https://downloads.1password.com/win/1PasswordSetup-latest.exe" -OutFile "$1password_installer"
&$1password_installer
Remove-Item $1password_installer
} else {
echo 'Skipping 1Password'
}
# Pause the script so you can see any output
Write-Host "Press Enter to exit..."
Start-Sleep -Seconds 3600 # Sleep for an hour, effectively pausing the script
# Enable Hyper-V
$decision = $Host.UI.PromptForChoice('Enable Hyper-V', 'Proceed?', $choices, 0)
if ($decision -eq 0) {
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All
} else {
echo 'Skipping Hyper-V'
}
# # Install 1Password
# $decision = $Host.UI.PromptForChoice('Install 1Password', 'Proceed?', $choices, 0)
# if ($decision -eq 0) {
# $1password_installer = "$env:USERPROFILE/Downloads/1PasswordSetup-latest.exe"
# Invoke-WebRequest -Uri "https://downloads.1password.com/win/1PasswordSetup-latest.exe" -OutFile "$1password_installer"
# &$1password_installer
# Remove-Item $1password_installer
# } else {
# echo 'Skipping 1Password'
# }
# Enable Containters
$decision = $Host.UI.PromptForChoice('Enable Containers', 'Proceed?', $choices, 0)
if ($decision -eq 0) {
Enable-WindowsOptionalFeature -Online -FeatureName Containers -All
} else {
echo 'Skipping Containers'
}
# # Enable Hyper-V
# $decision = $Host.UI.PromptForChoice('Enable Hyper-V', 'Proceed?', $choices, 0)
# if ($decision -eq 0) {
# Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All
# } else {
# echo 'Skipping Hyper-V'
# }
# Get the shell application object
$shellApp = New-Object -ComObject "Shell.Application"
# # Enable Containters
# $decision = $Host.UI.PromptForChoice('Enable Containers', 'Proceed?', $choices, 0)
# if ($decision -eq 0) {
# Enable-WindowsOptionalFeature -Online -FeatureName Containers -All
# } else {
# echo 'Skipping Containers'
# }
# Run the command without elevation
$shellApp.ShellExecute("powershell.exe", "-NoProfile -Command `"& { $nonElevatedCommand }`"", "", "open", 0)
# # Get the shell application object
# $shellApp = New-Object -ComObject "Shell.Application"
# Start-Process -NoNewWindow -Credential "$env:UserDomain\$env:UserName" -FilePath "powershell.exe" -ArgumentList "-NoProfile -Command & { & $($command) }"
# Start-Process -FilePath "powershell.exe" -ArgumentList "-NoProfile -Command & { & $($command) }" -Credential $user -WindowStyle Hidden
# # Run the command without elevation
# $shellApp.ShellExecute("powershell.exe", "-NoProfile -Command `"& { $nonElevatedCommand }`"", "", "open", 0)
# Install Chocolatey
iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
# # Start-Process -NoNewWindow -Credential "$env:UserDomain\$env:UserName" -FilePath "powershell.exe" -ArgumentList "-NoProfile -Command & { & $($command) }"
# # Start-Process -FilePath "powershell.exe" -ArgumentList "-NoProfile -Command & { & $($command) }" -Credential $user -WindowStyle Hidden
# Install SSH Server
$decision = $Host.UI.PromptForChoice('Install SSH Server', 'Proceed?', $choices, 0)
if ($decision -eq 0) {
choco install --yes "--package-parameters=/SSHServerFeature" openssh
Start-Service sshd
Set-Service -Name sshd -StartupType 'Automatic'
} else {
echo 'Skipping SSH Server'
}
# # Install Chocolatey
# iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
# # Install SSH Server
# $decision = $Host.UI.PromptForChoice('Install SSH Server', 'Proceed?', $choices, 0)
# if ($decision -eq 0) {
# choco install --yes "--package-parameters=/SSHServerFeature" openssh
# Start-Service sshd
# Set-Service -Name sshd -StartupType 'Automatic'
# } else {
# echo 'Skipping SSH Server'
# }