Skip to content

Instantly share code, notes, and snippets.

@adilio
Last active October 3, 2018 02:02
Show Gist options
  • Save adilio/829d47acd11ebff61aa86540db956d3c to your computer and use it in GitHub Desktop.
Save adilio/829d47acd11ebff61aa86540db956d3c to your computer and use it in GitHub Desktop.
Preliminary config for win servers
# AnisbleMe.ps1
# Preliminary conifguration for a windows host
# Make sure Network profile is Private
$InterfaceId = (Get-NetConnectionProfile | Select-Object -ExpandProperty InterfaceIndex)
Set-NetConnectionProfile -InterfaceIndex $InterfacId -NetworkCategory Private
Write-Output "Interface Id $InterfaceId Network Profile set to Private"
# Enable Remote Desktop
Get-NetFirewallRule -DisplayGroup "Remote Desktop" | Set-NetFirewallRule -Enabled true -Profile Private, Domain
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\' -Name 'fDenyTSConnections' -Value 0
Write-Output "RDP enabled"
# Download and run prereq for Ansible remoting
$AnsibleYes= Read-Host -Prompt "Configure Ansible remoting? (y/n)"
If ($AnsibleYes -eq 'y') {
Invoke-WebRequest -Uri https://raw.githubusercontent.com/ansible/ansible/devel/examples/scripts/ConfigureRemotingForAnsible.ps1 -OutFile ConfigureRemotingForAnsible.ps1
.\ConfigureRemotingForAnsible.ps1 -Verbose
}
# Rename and set password for local admin, if not changed already
If (Get-LocalUser -Name Administrator -ErrorAction SilentlyContinue) {
$RenameAdmin = Read-Host -Prompt "Enter new Local Admin username"
Rename-LocalUser -Name "Administrator" -NewName $RenameAdmin
$Password = Read-Host -AsSecureString -Prompt "Enter new Local Admin pw"
Set-LocalUser -Name $RenameAdmin -Password $Password -PasswordNeverExpires $true
Write-Output "Admin credentials updated"
}
Else {
Write-Output "Admin account already renamed"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment