< Back

Set-DbaSpn

Mon Jan 13, 2020 5:42 pm

NAME Set-DbaSpn



SYNOPSIS

Sets an SPN for a given service account in active directory (and also enables delegation to the same SPN by

default)





SYNTAX

Set-DbaSpn [-SPN] <String> [-ServiceAccount] <String> [[-Credential] <Pscredential>] [-NoDelegation <Switch>]

[-EnableException <Switch>] [<CommonParameters>]





DESCRIPTION

This function will connect to Active Directory and search for an account. If the account is found, it will attempt

to add an SPN. Once the SPN is added, the function will also set delegation to that service, unless -NoDelegation

is specified. In order to run this function, the credential you provide must have write access to Active Directory.



Note: This function supports -WhatIf





PARAMETERS

-Credential [<Pscredential>]

The credential you want to use to connect to Active Directory to make the changes



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-EnableException [<Switch>]

By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message.

This avoids overwhelming you with "sea of red" exceptions, but is inconvenient because it basically disables

advanced scripting.

Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own

try/catch.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-NoDelegation [<Switch>]

Skips setting the delegation



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-ServiceAccount [<String>]

The account you want the SPN added to



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-SPN [<String>]

The SPN you want to add



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,

ErrorAction, ErrorVariable, WarningAction, WarningVariable,

OutBuffer, PipelineVariable, and OutVariable. For more information, see

about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).



INPUTS



OUTPUTS



NOTES





Tags: SPN

Author: Drew Furgiuele (@pittfurg), http://www.port1433.com



Website: https://dbatools.io

Copyright: (c) 2018 by dbatools, licensed under MIT

License: MIT https://opensource.org/licenses/MIT



-------------------------- EXAMPLE 1 --------------------------



PS C:\\>Set-DbaSpn -SPN MSSQLSvc/SQLSERVERA.domain.something -ServiceAccount domain\\account



PS C:\\> Set-DbaSpn -SPN MSSQLSvc/SQLSERVERA.domain.something -ServiceAccount domain\\account -EnableException



Connects to Active Directory and adds a provided SPN to the given account.

Connects to Active Directory and adds a provided SPN to the given account, suppressing all error messages and

throw exceptions that can be caught instead

-------------------------- EXAMPLE 2 --------------------------



PS C:\\>Set-DbaSpn -SPN MSSQLSvc/SQLSERVERA.domain.something -ServiceAccount domain\\account -Credential ad\\sqldba



Connects to Active Directory and adds a provided SPN to the given account. Uses alternative account to connect to

AD.

-------------------------- EXAMPLE 3 --------------------------



PS C:\\>Set-DbaSpn -SPN MSSQLSvc/SQLSERVERA.domain.something -ServiceAccount domain\\account -NoDelegation



Connects to Active Directory and adds a provided SPN to the given account, without the delegation.

-------------------------- EXAMPLE 4 --------------------------



PS C:\\>Test-DbaSpn -ComputerName sql2016 | Where-Object { $_.isSet -eq $false } | Set-DbaSpn



Sets all missing SPNs for sql2016

-------------------------- EXAMPLE 5 --------------------------



PS C:\\>Test-DbaSpn -ComputerName sql2016 | Where-Object { $_.isSet -eq $false } | Set-DbaSpn -WhatIf



Displays what would happen trying to set all missing SPNs for sql2016



RELATED LINKS

https://dbatools.io/Set-DbaSpn