Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
convert windows sid to uid for centrify express
# Convert windows sid to centrify express generated uid
import argparse
import re
def sid(value):
sidrx = re.compile('^S-1-5-\d{2}-\d+-(\d{4,10})-\d+-(\d+)$')
m = sidrx.match(value)
if (m):
# uid is the last 9 bits of the sid combined with 22, 0 padded from rid
(sid,rid) =,2)
sidbits = ('{0:b}'.format(int(sid)))[-9:]
uidbits = '{0:022b}'.format(int(rid))
return int(sidbits+uidbits,2)
msg = "'%r' is not a valid sid" % value
raise argparse.ArgumentTypeError(msg)
parser = argparse.ArgumentParser(description='Convert Windows SID to unix ID for centrify')
parser.add_argument('sid',metavar='S',type=sid,nargs="+",help="list of account sid's")
args = parser.parse_args()
for uid in args.sid:
print uid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.