# Finding duplicate SPN with PowerShell

Duplicate SPNs aren’t very common but can happen in any Active Directory as there’s no built-in way that tracks and prevent duplicate SPN’s. One has to either know all SPN’s in the environment, track them or check each time whether it already exists or not. Things get more complicated with larger Active Directory environments as people change, new apps are added, old apps are forgotten, but SPNs prevail.

blog

07 Dec 2021 pl

![Finding duplicate SPN with PowerShell](/wp-content/uploads/2021/12/img_61ab990ee4078.png)

[Zobacz obrazy (2)](#pf-content-image-1-0)

**Duplicate SPNs** aren't very common but can happen in any **Active Directory** as there's no built-in way that tracks and prevent duplicate SPN's. One has to either know all **SPN's** in the environment, track them or check each time whether it already exists or not. Things get more complicated with larger **Active Directory** environments as people change, new apps are added, old apps are forgotten, but SPNs prevail.

### 💡 Duplicate SPN

As I invest more time in proper **AD Compliance & Hardening** tools for my Active Directory, I've added yet another test to [Testimo](https://github.com/EvotecIT/Testimo).

[!\[Duplicate SPNs\](/wp-content/uploads/2021/12/img_61ab990ee4078.png)](/wp-content/uploads/2021/12/img_61ab990ee4078.png)

The report above, like any other report from over **80 reports** from [Testimo](https://github.com/EvotecIT/Testimo) can be generated with a single line of code.

```powershell
Invoke-Testimo -Sources ForestDuplicateSPN
```

Of course, the report above shows there are no duplicate SPNs, but I have tiny AD and keep things tidy 🙂 But your production environment may not be as clean as you think it is.

### 💡 Duplicate SPN in Testimo/ADEssentials

**Testimo** is a **PowerShell** module that doesn't have **Active Directory** code. It's a bit more like a wrapper around multiple other modules. It integrates [GPOZaurr](https://github.com/EvotecIT/GPOZaurr), [ADEssentials](https://github.com/EvotecIT/ADEssentials), [PSSharedGoods](https://github.com/EvotecIT/PSSharedGoods), [PSWriteHTML](https://github.com/EvotecIT/PSWriteHTML) or [PSEventViewer](https://github.com/EvotecIT/PSEventViewer). All written by me, all are doing their part. **ADEssentials** contains a command used by Testimo to provide a graphical representation of it. By using **Get-WinADDuplicateSPN** without any parameters, you can quickly find duplicate **SPN's**.

```powershell
Get-WinADDuplicateSPN | ft
```

You can also use **All** switch if you would like to see all **SPN** entries instead of just duplicates.

```powershell
Get-WinADDuplicateSPN -All | ft
```

[!\[Duplicate SPNs\](/wp-content/uploads/2021/12/img_61ab9d4bd4109.png)](/wp-content/uploads/2021/12/img_61ab9d4bd4109.png)

In Testimo, I wrap around it and assess how good or bad the given data is. The assessment, of course, is based on my judgment, and you can disagree. It's more of a guidance than anything else, so make sure you diagnose why this is rather than going through and fixing everything it tells you to improve. In Testimo, I also try to add descriptions and links that you may find helpful in figuring whether the test makes sense to your environment.

### 💡 Summary

If you want to find out more on **ADEssentials**, **Testimo**, or **GPOZaurr** I encourage you to search my blog for those terms and you'll find a description of how to utilize those to your advantage. Those modules provide an easy way for AD Compliance & Hardening to tell you what's wrong and how you can fix it.

- 🌐 The code is published on [GitHub](https://github.com/EvotecIT/Testimo)
- 🌐 Issues should be reported on [GitHub](https://github.com/EvotecIT/Testimo/issues)
- 🌐 Code is published as a module on [PowerShellGallery](https://www.powershellgallery.com/packages/Testimo/)

The module is signed with a certificate, like any new modules that I create or update.

```powershell
Install-Module Testimo -Force
```

GO Ahead! Have fun! Make sure to report any issues, or if you feel like something would require covering more ground, let me know.

## Powiązane projekty

Projekty powiązane z tagami, kategoriami i treścią tego wpisu.

[Wszystkie projekty](/projekty/)

Trwa dopasowywanie projektów...

[Powrót do bloga](/blog/)

## Powiązane wpisy

- [Check an API write after a PowerShell timeout](/blog/verify-uncertain-api-outcomes-powershell/)
- [Inspect and convert mixed Office archives with PSWriteOffice](/blog/inspect-and-convert-mixed-office-archives-pswriteoffice/)
- [Compose PDF reports and automate page workflows with PSWriteOffice](/blog/automate-pdf-reports-and-page-workflows-pswriteoffice/)

<!-- PowerForge markdown artifact sha256:CB617C65B76011031150115DFC7E95F2892927E144EBB28EAD258349C2BD7EB9 -->
