Skip to content

Instantly share code, notes, and snippets.

@MFKDGAF
Last active May 5, 2016 18:04
Show Gist options
  • Save MFKDGAF/8bd7be65cddb4fa540015daffaf7976e to your computer and use it in GitHub Desktop.
Save MFKDGAF/8bd7be65cddb4fa540015daffaf7976e to your computer and use it in GitHub Desktop.
#########################################################################################
# Computer Setup Script
#########################################################################################
#******************************************************************************
# File: NewComputer-Setup.ps1
# Date: 03/31/2016
# Version: 1.0.0
#
# Purpose: To automate the basic setup of a server.
#
# Requirements: Administraor access
#
# Revisions:
# ----------
# 1.0.0 03/31/2016 Created script.
# 1.0.1 05/04/2016 Restructed script.
#
#******************************************************************************
#*******************************************************************
# Activates Balanced Power Settings Profile
# Sets Hibernation to Never
# Sets Hard Disks to Turn Off After Never
# Sets to Turn Display Off After Never
# Sets Allow Hybird Sleep to Never
# Sets Sleep After to Never
# Commits Changes to Balance Power Settings Profile
#*******************************************************************
(gwmi -NS root\cimv2\power -Class win32_PowerPlan -Filter "ElementName ='Balanced'").Activate()
$aa = (gwmi -NS root\cimv2\power -Class win32_PowerPlan -Filter { ElementName ='Balanced'}).instanceid.split("\")[1]
$ba = (gwmi -NS root\cimv2\power -Class win32_PowerSetting -Filter { Elementname = 'Hibernate after' }).instanceid.split("\")[1]
$bb = (gwmi -NS root\cimv2\power -Class win32_powersettingdataindex -Filter "InstanceID like '%$aa%ac%$ba'")
$bb.settingindexvalue = 0
$bb.Put()
$ca = (gwmi -NS root\cimv2\power -Class win32_PowerSetting -Filter { Elementname = 'Turn off hard disk after' }).instanceid.split("\")[1]
$cb = (gwmi -NS root\cimv2\power -Class win32_powersettingdataindex -Filter "InstanceID like '%$aa%ac%$ca'")
$cb.settingindexvalue = 0
$cb.Put()
$da = (gwmi -NS root\cimv2\power -Class win32_PowerSetting -Filter { Elementname = 'Turn off display after' }).instanceid.split("\")[1]
$db = (gwmi -NS root\cimv2\power -Class win32_powersettingdataindex -Filter "InstanceID like '%$aa%ac%$da'")
$db.settingindexvalue = 1500
$db.Put()
$ea = (gwmi -NS root\cimv2\power -Class win32_PowerSetting -Filter { Elementname = 'Allow hybrid sleep' }).instanceid.split("\")[1]
$eb = (gwmi -NS root\cimv2\power -Class win32_powersettingdataindex -Filter "InstanceID like '%$aa%ac%$ea'")
$eb.settingindexvalue = 0
$eb.Put()
$fa = (gwmi -NS root\cimv2\power -Class win32_PowerSetting -Filter { Elementname = 'Sleep after' }).instanceid.split("\")[1]
$fb = (gwmi -NS root\cimv2\power -Class win32_powersettingdataindex -Filter "InstanceID like '%$aa%ac%$fa'")
$fb.settingindexvalue = 0
$fb.Put()
#*******************************************************************
# Create User 'UserName'
#*******************************************************************
#Connect to ADSI
$Computername = $env:COMPUTERNAME
$ADSIComp = [adsi]"WinNT://$Computername"
$Username = 'UserName'
$NewUser = $ADSIComp.Create('User',$Username)
#Set password on account
$NewUser.SetPassword("Password")
$NewUser.SetInfo()
#Set Description
$NewUser.Description ='Local Admin'
#Set Password to never expire
$flag=$NewUser.UserFlags.value -bor 0x10000
$NewUser.put("userflags",$flag)
#Commit Changes
$NewUser.SetInfo()
#Add User To Administrators Group
[ADSI]$group="WinNT://$Computername/Administrators,Group"
$NewUser.path
$group.Add($NewUser.path)
#*******************************************************************
# Disable Administrator Account
#*******************************************************************
#Specifiy Local User
$UserName = "Administrator"
#Specify Computer
$Computername = $env:COMPUTERNAME
#Connect to Local User on Local Computer
$User = [adsi]"WinNT://$Computername/$UserName,user"
#Disable Specified User
$User.AccountDisabled = $True
#Commit Changes
$User.SetInfo()
#*******************************************************************
# Sets Computer Description
#*******************************************************************
Push-Location
Set-Location HKLM:\System\CurrentControlSet\Services\LanmanServer\Parameters
$value = Read-Host "Please Set The Description For This System"
Set-ItemProperty . srvcomment “$value”
Pop-Location
#*******************************************************************
# Sets The OEM Information
#*******************************************************************
pushd
Set-Location HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\
$Manufacturer = Read-Host "Please Enter The Manuafacturer"
$Model = Read-Host "Please Enter The Model"
New-ItemProperty -Name Manufacturer -PropertyType string -path OEMInformation -Value “$Manufacturer”
New-ItemProperty -Name Model -PropertyType string -path OEMInformation -Value “$Model”
popd
#*******************************************************************
# Tell User To Restart
#*******************************************************************
Read-Host -Prompt "Please Restart the System..."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment