Skip to content

Instantly share code, notes, and snippets.

@mkropat
Forked from mkropat/provision-base-box.ps1
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mkropat/01be595b6ca9b162cb6d to your computer and use it in GitHub Desktop.
Save mkropat/01be595b6ca9b162cb6d to your computer and use it in GitHub Desktop.
# provision-win81-box.ps1 - Prepare Windows 8.1 box for general use
# To run:
#
# powershell -ExecutionPolicy Bypass -Command "& .\provision-win81-box.ps1"
function main {
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -force
Disable-UAC
Write-Status "User Access Control (UAC) has been disabled."
Enable-RemoteDesktop
Write-Status "Remote desktop enabled."
Disable-Firewall
Write-Status "Windows Firewall has been disabled."
Install-Chocolatey
Write-Status "Chocolatey installed."
Disable-Screensaver
Write-Status "Screensaver has been disabled."
Enable-Autologon "dev" "dev"
Write-Status "User 'dev' will automatically be logged in on boot."
Write-Host "Restarting Computer." -ForegroundColor Yellow
Restart-Computer
}
function Disable-UAC {
New-ItemProperty -Path 'HKLM:Software\Microsoft\Windows\CurrentVersion\Policies\System' -Name EnableLUA -PropertyType DWord -Value 0 -Force | Out-Null
}
function Enable-RemoteDesktop {
# Reference: http://social.technet.microsoft.com/Forums/windowsserver/en-US/323d6bab-e3a9-4d9d-8fa8-dc4277be1729/enable-remote-desktop-connections-with-powershell
$tsSettings = Get-WmiObject Win32_TerminalServiceSetting -Namespace root\cimv2\TerminalServices
$tsSettings.SetAllowTsConnections(1,1) | Out-Null
$tsGeneralSettings = Get-WmiObject -Class "Win32_TSGeneralSetting" -Namespace root\cimv2\TerminalServices -Filter "TerminalName='RDP-tcp'"
$tsGeneralSettings.SetUserAuthenticationRequired(0) | Out-Null
}
function Disable-Firewall {
Run-Silently netsh advfirewall set allprofiles state off
}
function Install-Chocolatey {
iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))
}
function Disable-Screensaver {
$key = 'HKCU:\Software\Policies\Microsoft\Windows\Control Panel\Desktop\'
New-Item $key -Force | Out-Null
New-ItemProperty -Path $key -Name ScreenSaveTimeOut -Value 0 -Force | Out-Null
New-ItemProperty -Path $key -Name ScreenSaveActive -Value 0 -Force | Out-Null
New-ItemProperty -Path $key -Name ScreenSaverIsSecure -Value 0 -Force | Out-Null
}
function Enable-Autologon($username, $password) {
$key = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon'
New-ItemProperty -Path $key -Name AutoAdminLogon -Value 1 -Force | Out-Null
New-ItemProperty -Path $key -Name DefaultUserName -Value $username -Force | Out-Null
New-ItemProperty -Path $key -Name DefaultPassword -Value $password -Force | Out-Null
}
function Run-Silently {
param(
[string]$script,
[parameter(ValueFromRemainingArguments=$true)] $args
)
$output = & $script $args 2>&1 | Out-String
if (-not $?) {
Write-Output $output
}
}
function Write-Status($text) {
Write-Host $text -ForegroundColor Green
}
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment