vbs get visual svn user and permissions


'
' Print permissions in the form: user_name,path,level
'
strComputer = "."
Set wmi = GetObject("winmgmts:" _
  & "{impersonationLevel=impersonate}!\\" _
  & strComputer & "\root\VisualSVN")

Set win = GetObject("winmgmts:" _
  & "{impersonationLevel=impersonate}!\\" _
  & strComputer & "\root\cimv2")

' Return text representation for the Access Level
Function AccessLevelToText(level)
  If level = 0 Then
    AccessLevelToText = "No Access"
  ElseIf level = 1 Then
    AccessLevelToText = "Read Only"
  ElseIf level = 2 Then
    AccessLevelToText = "Read/Write"
  Else
    AccessLevelToText = "Unknown"
  End If
End Function

' Return repository path for the object
Function GetPath(obj)
  cname = assoc.Path_.Class
  If cname = "VisualSVN_Service" Then
    GetPath = "Repositories Root"
  ElseIf cname = "VisualSVN_Repository" Then
    GetPath = associate.Name
  ElseIf cname = "VisualSVN_RepositoryEntry" Then
    GetPath = assoc.RepositoryName & ": " & assoc.Path
  Else
    GetPath = "Unknown"
  End If
End Function

' Convert SID to user name
Function SidToUserName(sid)
  Set account = win.Get("Win32_SID.SID='" & sid & "'")
  user = account.AccountName
  domain = account.ReferencedDomainName
  SidToUserName = domain & "\" & user
End Function

' Return user name associated with account
Function GetAccountName(account)
  If account.Path_.Class = "VisualSVN_WindowsAccount" Then
    GetAccountName = SidToUserName(account.SID)
  Else
    GetAccountName = account.Name
  End If
End Function

' Iterate over all security descriptions
Set objs = wmi.ExecQuery("SELECT * FROM VisualSVN_SecurityDescriptor")
For Each obj In objs
  Set assoc = wmi.Get(obj.AssociatedObject)

  For Each perm in obj.Permissions
    name = GetAccountName(perm.Account)
    level = AccessLevelToText(perm.AccessLevel)

    Wscript.Echo name & "," & GetPath(assoc) & "," & level
  Next
Next

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326437203&siteId=291194637