> For the complete documentation index, see [llms.txt](https://docs.scepman.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.scepman.com/pt/gestao-de-certificados/api-certificates/api-enrollment/windows-server.md).

# Windows Server

{% hint style="info" %}
Aplicável à versão 2.9 do SCEPman e superior
{% endhint %}

Pode usar o módulo SCEPmanClient do PowerShell para solicitar certificados para o seu servidor Windows. Consulte o artigo principal do módulo para os pré-requisitos:

{% content-ref url="/pages/2aae8b86d34060f6dfbcb6513b3b49e3570aadb3" %}
[SCEPmanClient](/pt/gestao-de-certificados/api-certificates/scepmanclient.md)
{% endcontent-ref %}

## Descrição do caso de uso

Embora o módulo seja capaz de solicitar certificados inicialmente, poderá não ser desejável armazenar as credenciais do Service Principal numa máquina que possa ser usada para solicitar certificados arbitrários.

Assim, se o seu cenário incluir a implementação de um certificado usando o Certificate Master, pode renová-lo automaticamente usando *SCEPmanClient* fornecendo um certificado já existente para autenticação:

<pre class="language-powershell"><code class="lang-powershell"><strong>$Subject = $env:COMPUTERNAME
</strong><strong>$ValidityThreshold = 30
</strong>
<strong>$CertificateToRenew = Get-ChildItem Cert:\LocalMachine\My `
</strong>                        | Where-Object NotAfter -lt (Get-Date).AddDays($ValidityThreshold) `
                        | Where-Object Subject -match $Subject

New-SCEPmanCertificate -Certificate $CertificateToRenew -SaveToStore 'LocalMachine'

# Com o novo certificado em vigor, podemos remover o antigo
# Remove-Item $CertificateToRenew.PSPath
</code></pre>

Este exemplo irá encontrar certificados a expirar no próximo mês e usá-lo para autenticar o pedido de renovação.

## Pedido inicial

Se quiser solicitar certificados no seu servidor inicialmente, pode fazê-lo fornecendo um Service Principal para autenticação que tenha a função **CSR DB Requesters** atribuída. Consulte o guia seguinte sobre como implementar um Service Principal desse tipo:

{% content-ref url="/pages/d93fe80282e16b063db56892eb639ba9ec09c676" %}
[Registo por API](/pt/gestao-de-certificados/api-certificates/api-enrollment.md)
{% endcontent-ref %}

```powershell
$Parameters = @{
    'Url'              = 'scepman.contoso.com'
    'ClientId'         = '569fbf51-aa63-4b5c-8b26-ebbcfcde2715'
    'TenantId'         = '8aa3123d-e76c-42e2-ba3c-190cabbec531'
    'ClientSecret'     = 'csa8Q~aVaWCLZTzswIBGvhxUiEvhptuqEyJugb70'
    'Subject'          = 'CN=WebServer'
    'DNSName'          = 'Webserver.domain.local'
    'ExtendedKeyUsage' = 'ServerAuth'
    'SaveToStore'      = 'LocalMachine'
}

New-SCEPmanCertificate @Parameters
```

Se agora quisermos renovar um certificado, podemos ignorar o Service Principal e usar um certificado já emitido para autenticação. Isto utilizará os detalhes do certificado existente para construir um novo CSR e enviá-lo ao SCEPman para um novo certificado.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.scepman.com/pt/gestao-de-certificados/api-certificates/api-enrollment/windows-server.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
