Last active
August 10, 2020 03:28
-
-
Save realtebo/445a7133ecb7461c974ce8c3092904ce to your computer and use it in GitHub Desktop.
Configure the local Windows 10 machine for be controlled remotely from ansible
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############################################################################################################## | |
# https://docs.ansible.com/ansible/latest/user_guide/windows_setup.html#upgrading-powershell-and-net-framework | |
# | |
# The username and password parameters are stored in plain text in the registry. Make sure the Remove-Item | |
# commands are run, check them after the script finishes to ensure no credentials are still stored on the host. | |
# | |
# The ConfigureRemotingForAnsible.ps1 script is intended for training and development purposes only and | |
# should not be used in a production environment, since it enables settings (like Basic authentication) | |
# that can be inherently insecure. | |
############################################################################################################## | |
$url = "https://raw.githubusercontent.com/jborean93/ansible-windows/master/scripts/Upgrade-PowerShell.ps1" | |
$file = "$env:temp\Upgrade-PowerShell.ps1" | |
$username = "Administrator" | |
$password = "Password" | |
(New-Object -TypeName System.Net.WebClient).DownloadFile($url, $file) | |
Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Force | |
###################################################################################################### | |
# NOW WE EXECUTE THE REMOTE POWERSHELL FILE | |
# -> https://raw.githubusercontent.com/jborean93/ansible-windows/master/scripts/Upgrade-PowerShell.ps1 | |
# BE SURE OF TO KNOW WHAT THE REMOTE FILE IS DOING !!! | |
###################################################################################################### | |
# version can be 3.0, 4.0 or 5.1 | |
Write-Host "Esguo " + $file | |
&$file -Version 5.1 -Username $username -Password $password -Verbose | |
Write-Host "Esguito " + $file | |
# this isn't needed but is a good security practice to complete | |
Set-ExecutionPolicy -ExecutionPolicy Restricted -Force | |
Write-Host "Abilito il login con nome utente e password" | |
$reg_winlogon_path = "HKLM:\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" | |
Set-ItemProperty -Path $reg_winlogon_path -Name AutoAdminLogon -Value 0 | |
Remove-ItemProperty -Path $reg_winlogon_path -Name DefaultUserName -ErrorAction SilentlyContinue | |
Remove-ItemProperty -Path $reg_winlogon_path -Name DefaultPassword -ErrorAction SilentlyContinue | |
Write-Host "Fatto" | |
###################################################################################################### | |
# HOTFIX FOR MEMORY LIMIT PROBLEM | |
# -> https://raw.githubusercontent.com/jborean93/ansible-windows/master/scripts/Install-WMF3Hotfix.ps1 | |
# BE SURE OF TO KNOW WHAT THE REMOTE FILE IS DOING !!! | |
###################################################################################################### | |
Write-Host "Hotfix per memory limit" | |
$url = "https://raw.githubusercontent.com/jborean93/ansible-windows/master/scripts/Install-WMF3Hotfix.ps1" | |
$file = "$env:temp\Install-WMF3Hotfix.ps1" | |
(New-Object -TypeName System.Net.WebClient).DownloadFile($url, $file) | |
powershell.exe -ExecutionPolicy ByPass -File $file -Verbose | |
Write-Host "Completato" | |
############################################################################################################## | |
# READY TO CONFIGURE | |
# -> https://raw.githubusercontent.com/ansible/ansible/devel/examples/scripts/ConfigureRemotingForAnsible.ps1 | |
# BE SURE OF TO KNOW WHAT THE REMOTE FILE IS DOING !!! | |
############################################################################################################## | |
# The ConfigureRemotingForAnsible.ps1 script is intended for training and development purposes only and | |
# should not be used in a production environment, since it enables settings (like Basic authentication) | |
# that can be inherently insecure. | |
############################################################################################################### | |
Write-Host "Eseguo configurazione remota per ansible..." | |
$url = "https://raw.githubusercontent.com/ansible/ansible/devel/examples/scripts/ConfigureRemotingForAnsible.ps1" | |
$file = "$env:temp\ConfigureRemotingForAnsible.ps1" | |
(New-Object -TypeName System.Net.WebClient).DownloadFile($url, $file) | |
powershell.exe -ExecutionPolicy ByPass -File $file | |
Write-Host "Fatto" | |
############################################################################################################## | |
# AND NOW ? | |
# The WinRM services listens for requests on one or more ports. Each of these ports must have a listener | |
# created and configured. | |
# | |
# To view the current listeners that are running on the WinRM service, run the following command: | |
# | |
# winrm enumerate winrm/config/Listener | |
# winrm get winrm/config/Service | |
# winrm get winrm/config/Winrs | |
# | |
# Remember to check service and listeners for security !!! | |
# | |
############################################################################################################### |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment