IronPython CRM 2011 Script for Checking Entity Audit Settings

Recently I needed to compare three different environments to see which entities were being audited. In the interests of making a boring task into an interesting task I decided to do this with an IronPython script.

I did this using Determination my IronPython/CRM 2011 tool, when given a connection string this will run through every entity in the environment letting you know which entity is being audited and which is not.

import clr

clr.AddReference('Microsoft.Xrm.Sdk')
clr.AddReference('Microsoft.Xrm.Client')
clr.AddReference('Microsoft.Xrm.Client')

from Microsoft.Xrm.Sdk import *
from Microsoft.Xrm.Sdk.Messages import *
from Microsoft.Xrm.Sdk.Metadata import *
from Microsoft.Xrm.Client import *
from Microsoft.Xrm.Client.Services import *

def IsAuditEnabled(connectionString):
	connection = CrmConnection.Parse(connectionString)
	
	service = OrganizationService(connection)

	r = RetrieveAllEntitiesRequest()
	r.EntityFilters = EntityFilters.Entity
	r.RetrieveAsIfPublished = True
	
	re = service.Execute(r)              

	for m in re.EntityMetadata:
		if(m.DisplayName.UserLocalizedLabel != None):
		
			auditState = 'Not auditing'
			if(m.IsAuditEnabled.Value):
				auditState = 'Auditing'                                              

			print auditState + ' ' + m.DisplayName.UserLocalizedLabel.Label + ' (' + m.LogicalName + ')'

IsAuditEnabled(r'[connection string goes here]')
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s