Grant and Remove Team Permissions
The following code is an example on how to grant and remove team permissions.
Try
Dim BadTeams As New List(Of String) 'List of Teams I want removed
BadTeams.Add("03C9166B-CE89-DF11-A66C-001F29CA342A")
BadTeams.Add("8704A81D-CF89-DF11-A66C-001F29CA342A")
BadTeams.Add("AA56ED52-CF89-DF11-A66C-001F29CA342A")
BadTeams.Add("AC494B6A-CF89-DF11-A66C-001F29CA342A")
BadTeams.Add("A3C7FC8A-CF89-DF11-A66C-001F29CA342A")
BadTeams.Add("36F82DE4-DD89-DF11-A66C-001F29CA342A")
BadTeams.Add("F0793E66-D789-DF11-91F5-001F29CAD3C8")
BadTeams.Add("D23AE484-D789-DF11-91F5-001F29CAD3C8")
BadTeams.Add("41325332-D889-DF11-91F5-001F29CAD3C8")
BadTeams.Add("C4AF799C-D889-DF11-91F5-001F29CAD3C8")
BadTeams.Add("801BAF0B-D989-DF11-91F5-001F29CAD3C8")
BadTeams.Add("2E0ED619-D989-DF11-91F5-001F29CAD3C8")
BadTeams.Add("0B706FC0-D989-DF11-91F5-001F29CAD3C8")
BadTeams.Add("4D541CEA-D989-DF11-91F5-001F29CAD3C8")
BadTeams.Add("FBAFA7F4-D989-DF11-91F5-001F29CAD3C8")
BadTeams.Add("0A67EB37-DA89-DF11-91F5-001F29CAD3C8")
Dim service As New CrmService
service.Credentials = System.Net.CredentialCache.DefaultCredentials
service.Url = "http://LOCALHOST:5555/MSCrmServices/2006/crmservice.asmx"
Dim fetchXml As String = "" & _
"<fetch mapping=""logical"">" & _
" <entity name=""account"">" & _
" <attribute name=""accountid"" />" & _
" <filter>" & _
" <condition attribute=""statecode"" operator=""eq"" value=""active"" />" & _
" <condition attribute=""ownerid"" operator=""eq"" value=""89998053-F9BC-DF11-842C-005056961DD7"" />" & _
" </filter>" & _
" </entity>" & _
"</fetch>"
Dim sss As String = service.Fetch(fetchXml)
Dim lll As New System.Xml.XmlDocument
lll.LoadXml(sss)
Dim Accounts As New List(Of String)
For Each n As System.Xml.XmlNode In lll.SelectNodes("//accountid")
Accounts.Add(n.InnerText)
Next
Dim I As Integer = 0
For Each account In Accounts
For Each badteam In BadTeams
Dim principal As New SecurityPrincipal()
principal.Type = SecurityPrincipalType.Team
principal.PrincipalId = New Guid(badteam)
Dim principalAccess As New PrincipalAccess()
principalAccess.Principal = principal
principalAccess.AccessMask = Nothing 'if we wanted to add permissions for the team instead of take permissions away from the team...replace nothing with something like "AccessRights.ReadAccess"
'also need to replace modifyaccessrequests/response WITH GrantAccessRequests/reponses
Dim target As New TargetOwnedAccount 'replace targetowned with whatever needed... in this example we use account
target.EntityId = New Guid(account)
Dim UNgrant As New ModifyAccessRequest() '
UNgrant.PrincipalAccess = principalAccess
UNgrant.Target = target
Dim granted As ModifyAccessResponse = DirectCast(service.Execute(UNgrant), ModifyAccessResponse)
Next
I += 1
Next
Catch ex As System.Web.Services.Protocols.SoapException
MsgBox(ex.Detail.InnerXml.ToString, MsgBoxStyle.Information)
Catch ex As Exception
MsgBox(ex.Message.ToString, MsgBoxStyle.Information)
End Try
|
<<Back