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

  • SEARCH
  • Home
  • 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 5957251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:22:26+00:00 2026-05-22T18:22:26+00:00

I have a user created stored procedure in a database server that queries active

  • 0

I have a user created stored procedure in a database server that queries active directory for user information and inserts the data into a table. We wish to remove the operation from the database server and perform the initial AD query and data insert in an external call (PowerShell or C#).

The stored procedure uses the sp_OA procedures to create an ADsDSOObject to do the actual AD query. It appears that the ADsDSOObject is returning the objectSID in hex by default. Following is an example output value.

-- ADsDSOObject: 0x010500000000000515000000D94242061941C67FC9004A20EE030000

When I run an ADSI query through PowerShell, I get a byte array for the objectSID which I can turn into a string via the .NET System.Security.Principal.SecurityIdentifier (<objectSID>, 0).

This returns the actual string SID identifier in it’s proper SID form.

-- Byte Array: {1, 5, 0, 0, 0, 0, 0, 5, 21, 0, 0, 0, 217, 66, 66, 6, 25, 65, 198, 127, 201, 0, 74, 32, 245, 1, 0, 0}

-- .NET SID: S-1-5-21-105005785-2143699225-541720777-501

However, I need to store the data as binary in order to replace the procedure in the database with a .NET solution in order to avoid any changes in the application.

Using PowerShell or C#, does anyone know how to either convert the byte array to hex or how to convert the string SID representation to hex?

  • 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-22T18:22:27+00:00Added an answer on May 22, 2026 at 6:22 pm

    Here is a solution :

    PS> $sid = New-Object System.Security.Principal.SecurityIdentifier ("S-1-5-21-105005785-2143699225-541720777-501")
    PS> $c = New-Object 'byte[]' $sid.BinaryLength
    PS> $sid.GetBinaryForm($c, 0)
    

    $c contains the byte array you need.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a stored procedure (see below) which inserts data into a physical table
We have an stored procedure that we created so that user can write comma
We have an stored procedure that we created so that user can write comma
I have an user defined table function in SQL Server that aggregate data from
I have created an application that runs in the taskbar. When a user clicks
Using SQL Server 2008, I have a requirement that email addresses in my user
I have a stored procedure in a test instance of a sql server (named
Let's say that I have a form which runs a stored procedure. This stored
I have created one stored procedure which runs on 5000 users in tbluser table
I have created a user control to handle adding comments to certain business entities,

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.