Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5994705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:51:22+00:00 2026-05-22T23:51:22+00:00

In Powershell, how do you set the Read/Write Service Principal Name AD user permissions?

  • 0

In Powershell, how do you set the Read/Write Service Principal Name AD user permissions?

Normally during my build process, I use ADSIedit to navigate to that object, and then go through all the security tabs to get down to put a checkmark next to:

  • Read Service Principal Name
  • Write Service Principal Name

But navigating through ADSIedit can take a long time so I’m trying to script the process. If I have a PowerShell LDAP bind with a new user created, how can I use PowerShell to set both of these properties for this user account?

The following is a hacked out code-snippet of the possible pertinent portions of my install script:

$strDomain = "dc=my,dc=com"
$objDomain = [ADSI] "LDAP://" + strDomain 
$strSCCMSQLPW = Read-Host -assecurestring "Please enter a password for the " + $strSCCMSQL + " account: "
New-ADUser -SamAccountName $strSCCMSQL + -Name $strSCCMSQL -AccountPassword $strSCCMSQLPW -Enabled $true -Path $strUsersOU + "," + $strDomain -PasswordNeverExpires $true
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T23:51:23+00:00Added an answer on May 22, 2026 at 11:51 pm

    You need to add an ActiveDirectoryAccessRule object to the ACL of the target object. For setting property specific rigths the trick is to pass in the schemaIDGUID to the attribute. So first we need to find the schemaIDGUID from the Service-Principal-Name schema entry. In the sample code i statically refer to the Service-Principal-Name, better yet would have been to search for the ldapDisplayname to find the entry but I’m sure you can sort that out. In any case this code should do the job:

    Function Set-SpnPermission {
        param(
            [adsi]$TargetObject,
            [Security.Principal.IdentityReference]$Identity,
            [switch]$Write,
            [switch]$Read
        )
        if(!$write -and !$read){
            throw "Missing either -read or -write"
        }
        $rootDSE = [adsi]"LDAP://RootDSE"
        $schemaDN = $rootDSE.psbase.properties["schemaNamingContext"][0]
        $spnDN = "LDAP://CN=Service-Principal-Name,$schemaDN"
        $spnEntry = [adsi]$spnDN
        $guidArg=@("")
        $guidArg[0]=$spnEntry.psbase.Properties["schemaIDGUID"][0]
        $spnSecGuid = new-object GUID $guidArg
    
        if($read ){$adRight=[DirectoryServices.ActiveDirectoryRights]"ReadProperty" }
        if($write){$adRight=[DirectoryServices.ActiveDirectoryRights]"WriteProperty"}
        if($write -and $read){$adRight=[DirectoryServices.ActiveDirectoryRights]"readproperty,writeproperty"}
        $accessRuleArgs = $identity,$adRight,"Allow",$spnSecGuid,"None"
        $spnAce = new-object DirectoryServices.ActiveDirectoryAccessRule $accessRuleArgs
        $TargetObject.psbase.ObjectSecurity.AddAccessRule($spnAce)
        $TargetObject.psbase.CommitChanges()    
        return $spnAce
    }
    

    Sample lines for calling the function…

    $TargetObject = "LDAP://CN=User,OU=My User Org,DC=domain,DC=net"
    $Identity = [security.principal.ntaccount]"domain\user"
    
    Set-SpnPermission -TargetObject $TargetObject -Identity $Identity -write -read
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A little background: I use PowerShell on windows xp at work and I set
I want to use Powershell to write some utilities, leveraging our own .NET components
I'm using the PowerShell script below to set anonymous user identity and authentication methods
I am trying to run a powershell script to set user password to never
I am trying to use powershell to set windowsauth on a site in IIS,
I have the following script set as my VS2010 pre-build script: cd $(ProjectDir) C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe
I have the following PowerShell loop: Set-Variable -Name YELLOW -Option ReadOnly -Value 0 Set-Variable
I am trying to write a powershell script that will set a download directory
I have a file that I set using PowerShell that contains the version number
I'm configuring a web site using PowerShell and I want to set the default

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.