bootstrap/bootstrap-Windows.ps1
2024-08-09 13:01:03 +01:00

71 lines
2.7 KiB
PowerShell

$is_elevated = [bool]([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")
$choices = '&Yes', '&No'
if (-Not $is_elevated) {
# Not running with elevated permissions
# 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"
Start-Process $ps -Verb runas -ArgumentList "& '$script'"
exit
}
# Code to execute after elevation
Write-Host "Running as Administrator. Performing privileged actions..."
# 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
# # 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 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'
# }
# # 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'
# }
# # Get the shell application object
# $shellApp = New-Object -ComObject "Shell.Application"
# # Run the command without elevation
# $shellApp.ShellExecute("powershell.exe", "-NoProfile -Command `"& { $nonElevatedCommand }`"", "", "open", 0)
# # 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 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'
# }