Need to setspn in bulk for computer objects

Welcome Forums General PowerShell Q&A Need to setspn in bulk for computer objects

This topic contains 3 replies, has 2 voices, and was last updated by

 
Participant
1 week, 4 days ago.

  • Author
    Posts
  • #113284

    Participant
    Points: 0
    Rank: Member

    I have to populate a list of AD Computer objects with a backedup array of SPNs from a csv

    the csv is in the form of:

    name,ServicePrincipalName
    host1,SPN#1;SPN#2;SPN#3; etc

    How can I script the setting of these SPNs?

    Thank you,

  • #113287

    Participant
    Points: 10
    Rank: Member

    Just parse the file, address those semi colon for the SPN collection and loop thru your list while use setspn.exe.

        # Create SPNs for target hosts
        ('host00','host01','host03') | 
        % { 
            setspn -s "SPN#1/$_ $env:USERDOMAIN\$env:USERNAME"
            setspn -s "SPN#2/$_ $env:USERDOMAIN\$env:USERNAME"
            setspn -s "SPN#3/$_ $env:USERDOMAIN\$env:USERNAME"
        }
    
        # View SPN's of target hosts
        ('host00','host01','host03') | 
        % { setspn -L $_ }
    

    If you are saying that SPN collection is unknown then something like this normal parse/split and loop.

    $SPNList = Import-Csv -Path 'D:\Scripts\SPNList.csv'
    
    ForEacH ($SPNTarget in $SPNList)
    {
        "Processing SPNs for $($SPNTarget.Name)"
        ForEach($SPNName in ($SPNTarget.ServicePrincipalName -split ';'))
        { setspn -s "$SPNName/$($SPNTarget.Name) $env:USERDOMAIN\$env:USERNAME" }
    }
    

    I can't test the above right now.

    • #113539

      Participant
      Points: 0
      Rank: Member

      thank you postanote

    • #113554

      Participant
      Points: 10
      Rank: Member

      No worries

You must be logged in to reply to this topic.