' Retrieve User Instance Permissions



Const adVarChar = 200
Const MaxCharacters = 255

strUser="DOMAIN\USER"

On Error Resume next
Set DataList = CreateObject("ADOR.Recordset")
With DataList.Fields
    .Append "InstanceKey", adVarChar, MaxCharacters
    .Append "PermissionName", adVarChar, MaxCharacters
    .Append "ObjectKeyName", adVarChar, MaxCharacters
End With
DataList.Open

Set ProviderLoc = GetObject("winmgmts:{impersonationLevel=impersonate}!root/sms:SMS_ProviderLocation")

If err.number<>0 Then
    wscript.echo "Couldn't Get SMS Provider"
    wscript.quit
End If

For Each Location In ProviderLoc.Instances_
    If Location.ProviderForLocalSite = True Then
        Set objSWbemServices = GetObject("winmgmts:" & Location.NamespacePath)
        Exit For
    End If
Next

Wscript.Echo "Instance permissions for " + UCase(strUser)

Set colClassPermissionNames=objSwbemServices.InstancesOf("SMS_UserClassPermissionNames")
For Each objClassPermissionName In colClassPermissionNames
    If Ucase(objClassPermissionName.UserName)=Ucase(strUser) Then
        strInstanceKey = "All Instances"
        AddNewData strInstanceKey, objClassPermissionName.ObjectKey, _
          objClassPermissionName.PermissionName
    End If
Next
    
Set colInstancePermissionNames=objSwbemServices.InstancesOf("SMS_UserInstancePermissionNames")
For Each objInstancePermissionName In colInstancePermissionNames
    If Ucase(objInstancePermissionName.UserName)=Ucase(strUser) Then
        AddNewData objInstancePermissionName.InstanceKey, objInstancePermissionName.ObjectKey, _
          objInstancePermissionName.PermissionName
    End If
Next

DataList.Sort = "ObjectKeyName"

Do Until DataList.EOF
    wscript.echo Datalist.Fields.Item("ObjectKeyName") & " - " & DataList.Fields.Item("InstanceKey")_
        & " - " & DataList.Fields.Item("PermissionName")
    DataList.MoveNext
Loop

Function AddNewData (InstanceKey, ObjectKey, Permission)
    Datalist.AddNew
    Datalist("InstanceKey") = InstanceKey
    Datalist("PermissionName") = Permission
    Select Case ObjectKey
        Case 1 strObjectKeyName = "Collection"            
        Case 2 strObjectKeyName = "Package"
        Case 3 strObjectKeyName = "Advertisement"
        Case 4 strObjectKeyName = "Status Message"
        Case 6 strObjectKeyName = "Site" 'ObjectKey #5 is unused
        Case 7 strObjectKeyName = "Query"
        Case 8 strObjectKeyName = "Report"
        Case 9 strObjectKeyName = "Software Metering Rule"
        Case 10 strObjectKeyName = "Software Updates"
    End Select
    Datalist("ObjectKeyName") = strObjectKeyName
End Function

Wscript.Quit

search for scripts

VbsEdit contains all these sample scripts!





Home   Scripts

Copyright © 2001-2019 adersοft