KB Article #73205
List all existing policies in EMF
SQL query to list all existing EMF policies. It helps reviewing the policy logic or when you need to recreate the policies in MailGate.
Resolution
* Use SQL Query Analyzer or relevant tool to execute the query
use EMFMail
go
set nocount on
-- variable declaration section
declare @polId uniqueidentifier
declare @polName nvarchar(128)
declare @polContext int
declare @polSummary nvarchar(3500)
declare @parDN nvarchar(255)
declare @rdn nvarchar(100)
declare @polState nvarchar(10)
declare @polOvrRide nvarchar(10)
-- end variable declaration section
declare policies_cursor cursor for
select policyId, policyName, policyContext, policySummary
from directoryPolicies
order by policyName
open policies_cursor
fetch next from policies_cursor into @polId, @polName, @polContext, @polSummary
while @@fetch_status=0
begin
print '=================================================================================================='
print ''
print 'Policy Name: ' + @polName
if (@polContext=1)
begin
print 'Applies to: Sender'
end
else
begin
print 'Applies to: Recipient'
end
declare whereUsed_cursor cursor for
select parentDN, rdn, policyDisabled
from DirectoryHierarchy as dh
join DirectoryPolicySet as dps
on dh.directoryId=dps.directoryId
where dps.policyId=@polId
open whereUsed_cursor
fetch next from whereUsed_cursor into @parDN, @rdn, @polState
if (@@fetch_status != 0)
begin
print ''
print 'Policy in not applied to any object!'
end
else
begin
print ''
print '----------+----------------------------------------------------------------------------'
print 'Status | Applied to Object: '
print '----------+----------------------------------------------------------------------------'
end
while @@fetch_status=0
begin
if (@polState=1)
begin
print 'Disabled | ' + @parDN + @rdn
print '----------+----------------------------------------------------------------------------'
end
else
begin
print 'Enabled | ' + @parDN + @rdn
print '----------+----------------------------------------------------------------------------'
end
fetch next from whereUsed_cursor into @parDN, @rdn, @polState
end
close whereUsed_cursor
deallocate whereUsed_cursor
print ''
if (@polSummary != '')
begin
print 'Policy Summary: '
print ' '
print @polSummary
end
else
begin
print 'No Policy Summary Text Available!'
end
print ''
fetch next from policies_cursor into @polId, @polName, @polContext, @polSummary
end
close policies_cursor
deallocate policies_cursor