Automação com Powershell - configuração de rede e ativação (dica do MCT)



Este post entrega um script rápido muito útil para o dia a dia da automação... vamos que vamos.

#################################################
#     Ver.6.0.1                                 #
#     Script de configuração de Servidores      #
#     Configurações globais e Compliance        #
#     By Eduardo Popovici                       #
#     Fev - 2019                                #
#################################################

#################################################
#         Permitir execução de scripts          #
#################################################

set-executionpolicy remotesigned

#################################################
#        Desligar Firewall do Windows           #
#################################################

netsh.exe advfirewall set allprofiles state off
netsh.exe advfirewall show allprofiles state

#################################################
# Desativa o IE Enhanced Security Configuration #
#################################################

function Disable-InternetExplorerESC {
    $AdminKey = "HKLM:\SOFTWARE\Microsoft\Active Setup\Installed Components\{A509B1A7-37EF-4b3f-8CFC-4F3A74704073}"
    $UserKey = "HKLM:\SOFTWARE\Microsoft\Active Setup\Installed Components\{A509B1A8-37EF-4b3f-8CFC-4F3A74704073}"
    Set-ItemProperty -Path $AdminKey -Name "IsInstalled" -Value 0 -Force
    Set-ItemProperty -Path $UserKey -Name "IsInstalled" -Value 0 -Force
    Stop-Process -Name Explorer -force
    Write-Host "IE Enhanced Security Configuration (ESC) has been disabled." -ForegroundColor Green
}
Disable-InternetExplorerESC

#################################################
#          Desativa o UAC do Windows            #
#################################################

function Disable-UserAccessControl {
    Set-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" -Name "ConsentPromptBehaviorAdmin" -Value 00000000 -Force
    Write-Host "User Access Control (UAC) has been disabled." -ForegroundColor Green    
}
Disable-UserAccessControl

#################################################
#             Configura a ETH                   #
#################################################

$NIC = "GERENCIA"
$IP_ADDR = "192.168.1.10"
$GW = "192.168.1.1"
$CDIR = "24"
$DNS = ("8.8.8.8","8.8.4.4")

netsh interface show interface
Get-NetAdapter | where status -eq Up | Rename-NetAdapter -NewName $NIC
Disable-NetAdapterBinding -InterfaceAlias $NIC -ComponentID ms_tcpip6
New-NetIPAddress –IPAddress $IP_ADDR -DefaultGateway $GW -PrefixLength $CDIR -InterfaceIndex (Get-NetAdapter).InterfaceIndex
Set-DNSClientServerAddress –InterfaceIndex (Get-NetAdapter).InterfaceIndex –ServerAddresses $DNS

REG ADD  "HKLM\Software\policies\Microsoft\Windows NT\DNSClient"
REG ADD  "HKLM\Software\policies\Microsoft\Windows NT\DNSClient" /v " EnableMulticast" /t REG_DWORD /d "0" /f

# OldConfig
# netsh interface ipv4 set address name="GERENCIA" static 192.168.1.10  255.255.255.0 192.168.1.1
# netsh interface ipv4 set dns name="GERENCIA" static 8.8.8.8 


#################################################
#         Instalar chave de ativação            #
#################################################

# WS2016
slmgr.vbs -ipk [CHAVE-DE-ATIVACAO]
Start-Sleep -s 10
slmgr.vbs -ato
slmgr.vbs -xpr
Start-Sleep -s 10
shutdown -f -r -t 0



Postar um comentário

Comente sem faltar com respeito - ;-)

Postagem Anterior Próxima Postagem