# Automação

Necessário WINRM ou OpenSSH

## WinRM

Para **habilitar o WinRM (Windows Remote Management)** no Windows, siga um dos métodos abaixo — dependendo se você quer fazer isso via **linha de comando (PowerShell ou CMD)** ou via **interface gráfica**.

***

#### **Método 1 — via PowerShell**

Execute o PowerShell **como Administrador** e rode:

```powershell
Enable-PSRemoting -Force
```

Isso faz:

* Habilita o serviço **WinRM**.
* Cria uma **regra no Firewall** para permitir conexões remotas.
* Configura o listener HTTP padrão (`http://+:5985`).

***

#### **Método 2 — via CMD**

Abra o **Prompt de Comando (Administrador)** e execute:

```cmd
winrm quickconfig
```

Se o serviço estiver desativado, ele perguntará:

> WinRM is not set up to receive requests. Do you want to set it up?

Responda `y` e depois `y` novamente se ele perguntar sobre o firewall.

Isso:

* Inicia o serviço WinRM.
* Configura o listener HTTP padrão.
* Ajusta regras de firewall.

***

#### **Verificar status do WinRM**

```powershell
winrm enumerate winrm/config/listener
```

ou

```powershell
Get-Service WinRM
```

O status deve estar como:

```
Status   Name               DisplayName
------   ----               -----------
Running  WinRM              Windows Remote Management (WS-Management)
```

***

#### **Habilitar acesso remoto de hosts específicos**

Se quiser permitir conexões de uma máquina específica:

```powershell
Set-Item WSMan:\localhost\Client\TrustedHosts -Value "NOME_DO_HOST"
```

Ou permitir todos (menos seguro):

```powershell
Set-Item WSMan:\localhost\Client\TrustedHosts -Value "*"
```

***

#### **Firewall**

Certifique-se de que a porta **5985 (HTTP)** ou **5986 (HTTPS)** está liberada:

```powershell
netsh advfirewall firewall add rule name="WinRM" dir=in action=allow protocol=TCP localport=5985
```

***

Se quiser, posso te passar também o **comando Ansible** ou **Group Policy (GPO)** para habilitar WinRM automaticamente em várias máquinas.\
Quer que eu te mostre isso também?

***

## OpenSSH

<div align="left"><figure><img src="/files/NOB4nhCfSO8w0jzaJgCH" alt="" width="563"><figcaption></figcaption></figure></div>

Powershell:

{% code overflow="wrap" %}

```
# Instalar OpenSSH Server
Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH.Server*' | Add-WindowsCapability –Online

# Iniciar e configurar o serviço para automático
Set-Service -Name sshd -StartupType 'Automatic'
Start-Service sshd

# Resolver o IP atual do cliente.datadike.com (coloque o seu endereço)!
$RemoteHost = "cliente.datadike.com"
$RemoteIP = (Resolve-DnsName $RemoteHost -Type A | Select-Object -First 1 -ExpandProperty IPAddress)

Write-Host "IP resolvido para $RemoteHost: $RemoteIP"

# Criar regra de firewall restrita para o IP resolvido
New-NetFirewallRule -Name "sshd-$RemoteHost" `
    -DisplayName "OpenSSH Server (sshd) - $RemoteHost" `
    -Enabled True `
    -Direction Inbound `
    -Protocol TCP `
    -Action Allow `
    -LocalPort 22 `
    -RemoteAddress $RemoteIP

```

{% endcode %}

DISM:

```
dism /Online /Add-Capability /CapabilityName:OpenSSH.Server~~~~0.0.1.0
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://wiki.datadike.com/integracoes/windows/automacao.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
