Quantcast
Channel: EPMFramework Discussions Rss Feed
Viewing all 138 articles
Browse latest View live

New Post: EPM and SCOM monitoring

0
0
Hi All,

Is it possible to get SCOM to monitor if a job has returned some policy failures?

EG
I have a CMS setup for the EPM. A policy is created to check that a full backup has occured in the last 24 hours.

If there are 4 instances having this policy run against and 1 instance fails with some of the databases not being backed up in this time period is it possible to raise a single alert into SCOM with the instance and database which has failed ?

This is a bit of a vague request i know.

I know that the policies using this framework are "on demand" and that they do not raise an error if they fail so not sure how it can be done - I also know that if i create this policy/condition on each server then I can set up an alert to fire into the windows event log but then that defeats the point as I may as well have scom monitor for each individual job.

The point of this is to have a single alert raised with all the relevant details in it of the failures instead of being bombarded with hundreds of alerts (which ideally shouldn't happen but hey... not a perfect world :) )

Cheers,
Chris.

New Post: EPM and SCOM monitoring

0
0
I have a trigger setup on the PolicyHistoryDetail table that emails me when the category that is evaluated has failures.

Here's the trigger code
BEGIN -- trigger
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

  DECLARE @ProfileName varchar(20) = '<< your database mail profile >>';
  DECLARE @emailRecipient varchar(200) = '<< your email address here >>';
  DECLARE @emailSubject varchar(150);
  DECLARE @emailMessage varchar(4000);
  DECLARE @policyCategory varchar(150);
  DECLARE @rtn int;
  DECLARE @err int;

  IF OBJECT_ID('Tempdb..#PolicyFailures') IS NOT NULL DROP TABLE #PolicyFailures;
  CREATE TABLE #PolicyFailures (
    [PolicyHistoryDetailID] [int] NULL,
      [EvaluatedServer] [nvarchar](128) NULL,
      [EvaluationDateTime] [datetime] NULL,
      [EvaluatedPolicy] [nvarchar](128) NULL,
      [CategoryName] [nvarchar](128) NULL,
      [EvaluatedObject] [nvarchar](256) NULL,
      [ResultDetail] [xml] NULL,
  );

  SET @emailSubject = '';
  SET @emailMessage = '';
  SET @policyCategory = '';

  -- check if a failure record was inserted
  IF EXISTS(SELECT 1 FROM inserted WHERE [PolicyResult] = 'FAIL')
  BEGIN -- failure record exists

    -- select out only the failure records
    INSERT INTO #PolicyFailures (
      [PolicyHistoryDetailID],[EvaluatedServer],[CategoryName],[EvaluatedPolicy]
      ,[EvaluatedObject],[EvaluationDateTime],[ResultDetail]
    )
    SELECT
      [PolicyHistoryDetailID],[EvaluatedServer],[CategoryName],[EvaluatedPolicy]
      ,[EvaluatedObject],[EvaluationDateTime],[ResultDetail]
    FROM inserted
    WHERE [PolicyResult] = 'FAIL';

    SET @policyCategory = ISNULL((SELECT TOP 1 dtl.[CategoryName] FROM #PolicyFailures dtl),'UNKNOWN');
    SET @emailSubject = CAST(SERVERPROPERTY('ServerName') as varchar(50)) + ': Policy evaluation failure in category ' + @policyCategory;

    -- extract details of policy failure and wrap in html TR/TD tags
    WITH errorDetail (
        [EvaluatedServer],[EvaluatedPolicy],[EvaluatedObject],[EvaluationDate]
        ,[OpType],[Value],[AttributeResultValue],[FunctionResultValue]
    )
    AS (
      SELECT 
        [EvaluatedServer],[EvaluatedPolicy],[EvaluatedObject],[EvaluationDateTime]
        ,isnull([ResultDetail].value('(/Operator/OpType)[1]', 'varchar(10)'), 'UNK') as [OpType]
        ,isnull([ResultDetail].value('(/Operator/Constant/Value)[1]', 'varchar(20)'), '0') as [Value]
        ,isnull([ResultDetail].value('(/Operator/Attribute/ResultValue)[1]', 'varchar(200)'), 'UNK') as [AttributeResultValue]
        ,isnull([ResultDetail].value('(/Operator/Function/ResultValue)[1]', 'varchar(200)'), 'UNK') as [FunctionResultValue]
      FROM #PolicyFailures dtl
    )
    SELECT @emailMessage = CAST(
        (
          SELECT 
            td = [EvaluatedServer], ''
            , td = REPLACE([EvaluatedPolicy], '_',' '), ''
            , td = REPLACE([EvaluatedObject], '\',' \'), ''
            , td = convert(varchar(30), [EvaluationDate], 120), ''
            , td = [OpType] + ' ' + [Value], ''
            , td = CASE 
                    WHEN [FunctionResultValue] = 'UNK' THEN [AttributeResultValue]
                    WHEN [FunctionResultValue] <> 'UNK' THEN [FunctionResultValue]
                    ELSE 'Undetermined result'
                    END, ''
          FROM errorDetail
          ORDER BY [EvaluationDate]
          FOR XML PATH('tr'), TYPE  
        ) 
        AS NVARCHAR(MAX));          
          
    -- wrap failure details in html body and table tags
    SET @emailMessage = N'<HTML><BODY><H3>Policy Failures in category ' + @policyCategory
      + N'</H3><table border="1"><tr><th>Evaluated Server</th>'
      + N'<th>Evaluated Policy</th><th>Evaluated Object</th>'
      + N'<th>Evaluation Date</th><th>Expected Result</th><th>Actual Result</th></tr>' 
      + @emailMessage + N'</table></BODY></HTML>';

    -- send the email
    exec [msdb].[dbo].[sp_send_dbmail]
      @profile_name = @ProfileName
      , @recipients = @emailRecipient
      , @subject = @emailSubject
      , @importance = 'HIGH'
      , @body_format = 'HTML'
      , @body = @emailMessage

    SET @err = @@ERROR;
    IF @rtn <> 0 OR @err <> 0
    BEGIN -- Error sending Policy failure message
      RAISERROR('Problem sending Policy failure message, Return Value: %i, SQL Error: %i', 16, 1, @err, @rtn);
      
    END -- Error sending Policy failure message
      
  END -- failure record exists
  
END -- trigger

New Post: EPM and SCOM monitoring

0
0
Thanks Phil,

This is certainly worth looking into.

Kind Regard,
Chris.

New Post: Cannot create a connection to data source 'PolicyDW'. (rsErrorOpeningConnection)

0
0
I've had this working for a while but thought I'd reply just in case someone else has the same problem...

I actually had multiple problems with my deployment. This is the first report I deployed and thought everything could be configured through Management Studio. While I did need to add the Active Directory group for my teammates to the SQL database and grant them the "db_datareader" role, I also needed to use Report Manager to change the security for the report to add the same AD group with the "Browser" role. I had previously thought that Report Manager was just for viewing reports - I didn't realize hoe much of the administration needs to be performed using it.

Thanks for your help.

Ken

New Post: Result Details: shredding the XML

0
0
I'm looking to do the exact same thing. Being able to easily see both the expected and existing values would be extremely helpful.

New Post: SQL Agent job runs, step succeeded; But produces no information in the tables

0
0
So my issue starts out similar to this one:
https://epmframework.codeplex.com/discussions/280330

Can get all the way through step 5 of the Configuration successfully, the command line I'm using does add data to the policy.* tables as expected if ran through PowerShell directly. Tried this both logged in with my personal account and logged in as our SQL Agent account (both are Windows auth)

When scheduling the job as a powershell script, it runs successfully, but does not update any of the tables. Truncated the base tables to be sure before running. When running through SQL Agent, no files appear to be created in the 'temp' directory

Message
Executed as user: {domain\user}. The step did not generate any output. Process Exit Code 0. The step succeeded.

Tried this without setting an explicit proxy account, then using my sysadmin account as a proxy, and using the SQL Server service account as a proxy. Same results: The step succeeded; but no data is added to the policy.* tables.

Tried editing the powershell script, commenting out all the error 'traps'; Script still runs successfully

What could I be overlooking here? Or is there a good alternative to scheduling the script?

New Post: Evaluating Policies against SQL Server in DMZ

0
0
Hello,

I'm currently working on this feature. The idea is a gateway server which can access both the MS SQL Servers in the DMZ and also the central policy server. On this gateway you could run a slightly modified version of EPM_EnterpriseEvaluation_3.0.0.ps1. This script has his own server selection and also sql authentication.

I can't really see the dependency to the SQL CMS - it's only used for storing a list of servers which should be checked, or not?

New Post: Evaluating Policies against SQL Server in DMZ

0
0
It might be possible to talk to your networking team and discuss the possibility to have a one-way trust from the Domain where the CMS is located to the DMZ. That is how I've seen many IT infrastructures with DMZs. With such a trust, any connection that originates from the CMS Domain is trusted and allowed to connect to the DMZ. However, any connection that originates from the DMZ cannot access the Domain the CMS is on. Just an idea on how to get around it. :) Hope it helps!

New Post: Inserting data in to the PolicyHistoryDetail table

0
0
Hi,
 I assume that you might have successfully implemented EPM since the last time you faced the issue of running the Powershell without specifying the policy category. Right now I am at this stage and I am not able to move forward. I have only one policy enabled in the CMS as I am in the infant stage here . There are no results when I run the query.
SELECT * FROM policy.v_PolicyHistory
GO
SELECT * FROM policy.v_EvaluationErrorHistory
GO

Also when I tried to setup the Management Data Warehouse database when I ran the first script from the codeplex library.( I received an error:)

Warning! The maximum key length is 900 bytes. The index 'IX_PolicyHistoryView' has maximum length of 1330 bytes. For some combination of large values, the insert/update operation will fail.
Warning! The maximum key length is 900 bytes. The index 'IX_EvaluatedServer' has maximum length of 1032 bytes. For some combination of large values, the insert/update operation will fail.

I appreciate your time in getting back to me with a solution.

Thanks,
Joe

New Post: Error evaluating SQL Server 2012 from SQL 2008 CMS

0
0
Hi there,

We got the error below when evaluating database setting policy on SQL 2012 from 2008 CMS:
Microsoft.SqlServer.Management.Dmf.PolicyEvaluationException: Exception encountered while executing policy '2012 DB Settings'. ---> System.NullReferenceException: Object reference not set to an instance of an object.<?char 13?> at Microsoft.SqlServer.Management.Dmf.Condition.Evaluate(Object target, AdHocPolicyEvaluationMode evaluationMode)<?char 13?> at Microsoft.SqlServer.Management.Dmf.ObjectSet.CalculateTargets(IEnumerable objectSet, Condition condition, AdHocPolicyEvaluationMode evaluationMode, Object[]& conforming, TargetEvaluation[]& violating)<?char 13?> at Microsoft.SqlServer.Management.Dmf.ObjectSet.CalculateTargets(SqlStoreConnection targetConnection, Condition condition, AdHocPolicyEvaluationMode evaluationMode, String policyCategory, Object[]& conforming, TargetEvaluation[]& violating)<?char 13?> at Microsoft.SqlServer.Management.Dmf.Policy.EvaluatePolicyUsingConnections(AdHocPolicyEvaluationMode evaluationMode, SfcQueryExpression targetQueryExpression, Int64& historyId, ISfcConnection[] targetConnections)<?char 13?> --- End of inner exception stack trace

Any idea what's causing it?

Thanks,
Mary

New Post: Error not loading any data in to PolicyHistory

0
0
I have installed the components for this and think I have everything in place. I have tried to run the powershell with filters and categories and without and still get nothing stored for PolicyHistory or PolicyHistoryDetail. Everything goes to EvaluationErrors with the error below. I am not sure why it is saying parameter missing. I have checked my policy and I can evaluate them manually without error.

System.ArgumentNullException, Value cannot be null.
Parameter name: policy

New Post: EPM Framework and SQL 2012

0
0
wonder if I can still participate in this thread. I have attempted to setup the EPM framework in SQL v2012. I am using exactly the steps mentioned here:
https://epmframework.codeplex.com/SourceControl/latest

I am inputting this into the SQL Server Powershell window:

SL "D:\directoryname\”
.\EPM_EnterpriseEvaluation_3.0.0.ps1 -ConfigurationGroup "" -PolicyCategoryFilter "" –EvalMode “Check”

NOTE: I am not putting a ConfigurationGroupName in there because on all previous attempts, when I had passed it in, the program did nothing. Having removed the ConfigGroupName, it actually does a lot. Goes along for quite some time, presumably evaluating policies. Ultimately, there is no policy data created. I just have a huge page of what appears to be the same error again and again:

Invoke-PolicyEvaluation : Property 'IsHadrEnabled' does not exist.
At D:\directoryname\EPM_EnterpriseEvaluation_3.0.0.ps1:81 char:27
  • Invoke-PolicyEvaluation <<<< -Policy $Policy -TargetServerName $
    ServerName -AdHocPolicyEvaluationMode $EvalMode -OutputXML > $OutputFile;
    • CategoryInfo : NotSpecified: (:) [Invoke-PolicyEvaluation], Mis
      singPropertyException
    • FullyQualifiedErrorId : PolicyEvaluationError,Microsoft.SqlServer.Manage
      ment.PowerShell.InvokePolicyEvaluationCommand
PS D:\directoryname >




Do any of you have any ideas?

New Post: Error not loading any data in to PolicyHistory

0
0
Hi gbargsle

I had this problem too and it took me quite some days to figure this issue out.

the issue lies in the fact that if you have installed 'SQL Server 2012 SMO' another windows assembly is created called 'Microsoft.SqlServer.Smo' that has version 11.0.0.0.

this framework seems to only work with the 10.0.0.0 version (SQL Server 2008) . Therefor the only way to make sure that the script uses the version 10 assemblies you have to specify them manually in the powershell script, like so:

Add-Type -path “C:\Windows\assembly\GAC_MSIL\Microsoft.SqlServer.Smo\10.0.0.0__89845dcd8080cc91\Microsoft.SqlServer.Smo.dll"
Add-Type -path “C:\Windows\assembly\GAC_MSIL\Microsoft.SqlServer.Dmf\10.0.0.0__89845dcd8080cc91\Microsoft.SqlServer.Dmf.dll"
Add-Type -path “C:\Windows\assembly\GAC_MSIL\Microsoft.SqlServer.SqlWmiManagement\10.0.0.0__89845dcd8080cc91\Microsoft.SqlServer.SqlWmiManagement.dll"
Add-Type -path “C:\Windows\assembly\GAC_MSIL\Microsoft.SqlServer.ConnectionInfo\10.0.0.0__89845dcd8080cc91\Microsoft.SqlServer.ConnectionInfo.dll"
Add-Type -path “C:\Windows\assembly\GAC_MSIL\Microsoft.SqlServer.SmoExtended\10.0.0.0__89845dcd8080cc91\Microsoft.SqlServer.SmoExtended.dll"
Add-Type -path “C:\Windows\assembly\GAC_MSIL\Microsoft.SqlServer.Management.RegisteredServers\10.0.0.0__89845dcd8080cc91\Microsoft.SqlServer.Management.RegisteredServers.dll"
Add-Type -path “C:\Windows\assembly\GAC_MSIL\Microsoft.SqlServer.Management.Sdk.Sfc\10.0.0.0__89845dcd8080cc91\Microsoft.SqlServer.Management.Sdk.Sfc.dll"
Add-Type -path “C:\Windows\assembly\GAC_MSIL\Microsoft.SqlServer.SqlEnum\10.0.0.0__89845dcd8080cc91\Microsoft.SqlServer.SqlEnum.dll"
Add-Type -path “C:\Windows\assembly\GAC_MSIL\Microsoft.SqlServer.RegSvrEnum\10.0.0.0__89845dcd8080cc91\Microsoft.SqlServer.RegSvrEnum.dll"
Add-Type -path “C:\Windows\assembly\GAC_MSIL\Microsoft.SqlServer.WmiEnum\10.0.0.0__89845dcd8080cc91\Microsoft.SqlServer.WmiEnum.dll"
Add-Type -path “C:\Windows\assembly\GAC_MSIL\Microsoft.SqlServer.ServiceBrokerEnum\10.0.0.0__89845dcd8080cc91\Microsoft.SqlServer.ServiceBrokerEnum.dll"
Add-Type -path “C:\Windows\assembly\GAC_MSIL\Microsoft.SqlServer.ConnectionInfoExtended\10.0.0.0__89845dcd8080cc91\Microsoft.SqlServer.ConnectionInfoExtended.dll"
Add-Type -path “C:\Windows\assembly\GAC_MSIL\Microsoft.SqlServer.Management.Collector\10.0.0.0__89845dcd8080cc91\Microsoft.SqlServer.Management.Collector.dll"
Add-Type -path “C:\Windows\assembly\GAC_MSIL\Microsoft.SqlServer.Management.CollectorEnum\10.0.0.0__89845dcd8080cc91\Microsoft.SqlServer.Management.CollectorEnum.dll"
Add-Type -path “C:\Windows\assembly\GAC_MSIL\Microsoft.SqlServer.SqlClrProvider\10.0.0.0__89845dcd8080cc91\Microsoft.SqlServer.SqlClrProvider.dll"


this codeblock needs to substitute the following part of the script:

$assemblylist =
"Microsoft.SqlServer.Dmf ",
"Microsoft.SqlServer.SqlWmiManagement ",
"Microsoft.SqlServer.ConnectionInfo ",
"Microsoft.SqlServer.Management.RegisteredServers ",
"Microsoft.SqlServer.Management.Sdk.Sfc ",
"Microsoft.SqlServer.SqlEnum ",
"Microsoft.SqlServer.RegSvrEnum ",
"Microsoft.SqlServer.WmiEnum ",
"Microsoft.SqlServer.ServiceBrokerEnum ",
"Microsoft.SqlServer.ConnectionInfoExtended ",
"Microsoft.SqlServer.Management.Collector ",
"Microsoft.SqlServer.Management.CollectorEnum"

foreach ($asm in $assemblylist)
{
$asm = [Reflection.Assembly]::LoadWithPartialName($asm)
}

once this change has been put into place, you force the script to use these assemblies and the evaluation script should work.
It appears that something has changed in the SQL 2012 SMO (probably extra parameter) that causes the current script to fail.

Hope this helps.

Kind regards,
Geoffrey

New Post: Error not loading any data in to PolicyHistory

0
0
This is great information. I cannot find where to put this update. The only file I have is the EPM_EnterpriseEvaluation_3.0.0.ps1 and do not show where it loads any assemblies. Any information on where to place these changes would be helpful.

New Post: Error not loading any data in to PolicyHistory

0
0
it seems we had updated the script a bit, anyway the code block should be put just before the initialization of the variables, so right above the following:

$CentralManagementServer = "WIN2008"
$HistoryDatabase = "MDW"

if needed I can upload our configuration (with the servernames and locations omitted ofcourse)

kind regards,
Geoffrey

New Post: Error not loading any data in to PolicyHistory

New Post: Error not loading any data in to PolicyHistory

0
0
script contents below (for future reference if someone else has this issue) usage is just change the paths + execute via powershell commandline
#
# Initialize-SqlpsEnvironment.ps1
#
# Loads the SQL Server provider extensions
#
# Usage: Powershell -NoExit -Command "& '.\Initialize-SqlPsEnvironment.ps1'"
#
# Change log:
# June 14, 2008: Michiel Wories
#   Initial Version
# June 17, 2008: Michiel Wories
#   Fixed issue with path that did not allow for snapin\provider:: prefix of path
#   Fixed issue with provider variables. Provider does not handle case yet
#   that these variables do not exist (bug has been filed)
$ErrorActionPreference = "Stop"
$sqlpsreg="HKLM:\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.SqlServer.Management.PowerShell.sqlps"
if (Get-ChildItem $sqlpsreg -ErrorAction "SilentlyContinue")
{
    throw "SQL Server Powershell is not installed."
}
else
{
    $item = Get-ItemProperty $sqlpsreg
    $sqlpsPath = [System.IO.Path]::GetDirectoryName($item.Path)
}

#
# Preload the assemblies. Note that most assemblies will be loaded when the provider
# is used. if you work only within the provider this may not be needed. It will reduce
# the shell's footprint if you leave these out.
#
#$assemblylist = 
#"Microsoft.SqlServer.Dmf ",
#"Microsoft.SqlServer.SqlWmiManagement ",
#"Microsoft.SqlServer.ConnectionInfo ",
#"Microsoft.SqlServer.Management.RegisteredServers ",
#"Microsoft.SqlServer.Management.Sdk.Sfc ",
#"Microsoft.SqlServer.SqlEnum ",
#"Microsoft.SqlServer.RegSvrEnum ",
#"Microsoft.SqlServer.WmiEnum ",
#"Microsoft.SqlServer.ServiceBrokerEnum ",
#"Microsoft.SqlServer.ConnectionInfoExtended ",
#"Microsoft.SqlServer.Management.Collector ",
#"Microsoft.SqlServer.Management.CollectorEnum"

#foreach ($asm in $assemblylist)
#{
#    $asm = [Reflection.Assembly]::LoadWithPartialName($asm)
#}

#
# Set variables that the provider expects (mandatory for the SQL provider)
#
Set-Variable -scope Global -name SqlServerMaximumChildItems -Value 0
Set-Variable -scope Global -name SqlServerConnectionTimeout -Value 30
Set-Variable -scope Global -name SqlServerIncludeSystemObjects -Value $false
Set-Variable -scope Global -name SqlServerMaximumTabCompletion -Value 1000
Add-Type -path “C:\Windows\assembly\GAC_MSIL\Microsoft.SqlServer.Smo\10.0.0.0__89845dcd8080cc91\Microsoft.SqlServer.Smo.dll"                                   
Add-Type -path “C:\Windows\assembly\GAC_MSIL\Microsoft.SqlServer.Dmf\10.0.0.0__89845dcd8080cc91\Microsoft.SqlServer.Dmf.dll"                                     
Add-Type -path “C:\Windows\assembly\GAC_MSIL\Microsoft.SqlServer.SqlWmiManagement\10.0.0.0__89845dcd8080cc91\Microsoft.SqlServer.SqlWmiManagement.dll"
Add-Type -path “C:\Windows\assembly\GAC_MSIL\Microsoft.SqlServer.ConnectionInfo\10.0.0.0__89845dcd8080cc91\Microsoft.SqlServer.ConnectionInfo.dll"          
Add-Type -path “C:\Windows\assembly\GAC_MSIL\Microsoft.SqlServer.SmoExtended\10.0.0.0__89845dcd8080cc91\Microsoft.SqlServer.SmoExtended.dll"              
Add-Type -path “C:\Windows\assembly\GAC_MSIL\Microsoft.SqlServer.Management.RegisteredServers\10.0.0.0__89845dcd8080cc91\Microsoft.SqlServer.Management.RegisteredServers.dll"
Add-Type -path “C:\Windows\assembly\GAC_MSIL\Microsoft.SqlServer.Management.Sdk.Sfc\10.0.0.0__89845dcd8080cc91\Microsoft.SqlServer.Management.Sdk.Sfc.dll"       
Add-Type -path “C:\Windows\assembly\GAC_MSIL\Microsoft.SqlServer.SqlEnum\10.0.0.0__89845dcd8080cc91\Microsoft.SqlServer.SqlEnum.dll"                             
Add-Type -path “C:\Windows\assembly\GAC_MSIL\Microsoft.SqlServer.RegSvrEnum\10.0.0.0__89845dcd8080cc91\Microsoft.SqlServer.RegSvrEnum.dll"                       
Add-Type -path “C:\Windows\assembly\GAC_MSIL\Microsoft.SqlServer.WmiEnum\10.0.0.0__89845dcd8080cc91\Microsoft.SqlServer.WmiEnum.dll"                             
Add-Type -path “C:\Windows\assembly\GAC_MSIL\Microsoft.SqlServer.ServiceBrokerEnum\10.0.0.0__89845dcd8080cc91\Microsoft.SqlServer.ServiceBrokerEnum.dll"         
Add-Type -path “C:\Windows\assembly\GAC_MSIL\Microsoft.SqlServer.ConnectionInfoExtended\10.0.0.0__89845dcd8080cc91\Microsoft.SqlServer.ConnectionInfoExtended.dll"
Add-Type -path “C:\Windows\assembly\GAC_MSIL\Microsoft.SqlServer.Management.Collector\10.0.0.0__89845dcd8080cc91\Microsoft.SqlServer.Management.Collector.dll"   
Add-Type -path “C:\Windows\assembly\GAC_MSIL\Microsoft.SqlServer.Management.CollectorEnum\10.0.0.0__89845dcd8080cc91\Microsoft.SqlServer.Management.CollectorEnum.dll"
Add-Type -path “C:\Windows\assembly\GAC_MSIL\Microsoft.SqlServer.SqlClrProvider\10.0.0.0__89845dcd8080cc91\Microsoft.SqlServer.SqlClrProvider.dll"


#
# Load the snapins, type data, format data
#
Push-Location
cd $sqlpsPath
Add-PSSnapin SqlServerCmdletSnapin100
Add-PSSnapin SqlServerProviderSnapin100
Update-TypeData -PrependPath SQLProvider.Types.ps1xml 
update-FormatData -prependpath SQLProvider.Format.ps1xml 
Pop-Location
#Write-Host -ForegroundColor Yellow 'SQL Server Powershell extensions are loaded.'
#Write-Host
#Write-Host -ForegroundColor Yellow 'Type "cd SQLSERVER:\" to step into the provider.'
#Write-Host
#Write-Host -ForegroundColor Yellow 'For more information, type "help SQLServer".'

# Evaluate specific Policies against a Server List
# Uses the Invoke-PolicyEvaluation Cmdlet

# param([string]$ConfigurationGroup = $(Throw "Parameter missing: -ConfigurationGroup ConfigGroup"),[string]$PolicyCategoryFilter=$(Throw "Parameter missing: -PolicyCategoryFilter Category"), [string]$EvalMode=$(Throw "Parameter missing: -EvalMode EvalMode"))

# Parameter -ConfigurationGroup specifies the 
# Central Management Server group to evaluate
# Parameter -PolicyCategoryFilter specifies the 
# category of policies to evaluate
# Parameter -EvalMode accepts "Check" to report policy
# results, "Configure" to reconfigure any violations 

# Declare variables to define the central warehouse
# in which to write the output, store the policies
$CentralManagementServer = "WIN2008"
$HistoryDatabase = "MDW"
# Define the location to write the results of the
# policy evaluation.  Delete any files in the directory.
$ResultDir = "e:\Results\"
$ResultDirDel = $ResultDir + "*.xml"
Remove-Item -Path $ResultDirDel
$ConfigurationGroup = "PROD"
$PolicyCategoryFilter = ""
$EvalMode = "Check"
# End of variables

#Function to insert policy evaluation results
#into SQL Server - table policy.PolicyHistory
function PolicyHistoryInsert($sqlServerVariable, $sqlDatabaseVariable, $EvaluatedServer, $EvaluatedPolicy, $EvaluationResults) 
{
   &{
    $sqlQueryText = "INSERT INTO policy.PolicyHistory (EvaluatedServer, EvaluatedPolicy, EvaluationResults) VALUES(N'$EvaluatedServer', N'$EvaluatedPolicy', N'$EvaluationResults')"
    Invoke-Sqlcmd -ServerInstance $sqlServerVariable -Database $sqlDatabaseVariable -Query $sqlQueryText -ErrorAction Stop
    }
    trap
    {
      $ExceptionText = $_.Exception.Message -replace "'", "" 
    }
}

#Function to insert policy evaluation errors 
#into SQL Server - table policy.EvaluationErrorHistory
function PolicyErrorInsert($sqlServerVariable, $sqlDatabaseVariable, $EvaluatedServer, $EvaluatedPolicy, $EvaluationResultsEscape) 
{
    &{
    $sqlQueryText = "INSERT INTO policy.EvaluationErrorHistory (EvaluatedServer, EvaluatedPolicy, EvaluationResults) VALUES(N'$EvaluatedServer', N'$EvaluatedPolicy', N'$EvaluationResultsEscape')"
    Invoke-Sqlcmd -ServerInstance $sqlServerVariable -Database $sqlDatabaseVariable -Query $sqlQueryText -ErrorAction Stop
    }
    trap
    {
      $ExceptionText = $_.Exception.Message -replace "'", "" 
    }
}

# Connection to the policy store
$conn = new-object Microsoft.SQlServer.Management.Sdk.Sfc.SqlStoreConnection("server=$CentralManagementServer;Trusted_Connection=true");
$PolicyStore = new-object Microsoft.SqlServer.Management.DMF.PolicyStore($conn);

# Create recordset of servers to evaluate
$sconn = new-object System.Data.SqlClient.SqlConnection("server=$CentralManagementServer;Trusted_Connection=true");
$q = "SELECT DISTINCT server_name FROM $HistoryDatabase.[policy].[pfn_ServerGroupInstances]('$ConfigurationGroup');"

$sconn.Open()
$cmd = new-object System.Data.SqlClient.SqlCommand ($q, $sconn);
$cmd.CommandTimeout = 0;
$dr = $cmd.ExecuteReader();

# Loop through the servers and then loop through
# the policies.  For each server and policy,
# call cmdlet to evaluate policy on server

while ($dr.Read()) { 
    $ServerName = $dr.GetValue(0);
    foreach ($Policy in $PolicyStore.Policies)
   {
        if (($Policy.PolicyCategory -eq $PolicyCategoryFilter)-or ($PolicyCategoryFilter -eq ""))
    {
        &{
            $OutputFile = $ResultDir + ("{0}_{1}.xml" -f (Encode-SqlName $ServerName ), (Encode-SqlName $Policy.Name));
            Invoke-PolicyEvaluation -Policy $Policy -TargetServerName $ServerName -AdHocPolicyEvaluationMode $EvalMode -OutputXML > $OutputFile;
            $PolicyResult = Get-Content $OutputFile -encoding UTF8;
            $PolicyResult = $PolicyResult -replace "'", "" 
            PolicyHistoryInsert $CentralManagementServer $HistoryDatabase $ServerName $Policy.Name $PolicyResult;
        }
            trap [Exception]
            { 
                  $ExceptionText = $_.Exception.Message -replace "'", "" 
                  $ExceptionMessage = $_.Exception.GetType().FullName + ", " + $ExceptionText
                  PolicyErrorInsert $CentralManagementServer $HistoryDatabase $ServerName $Policy.Name $ExceptionMessage;
                  continue;   
            }       
    }
   } 
 }

$dr.Close()
$sconn.Close()

#Shred the XML results to PolicyHistoryDetails
Invoke-Sqlcmd -ServerInstance $CentralManagementServer -Database $HistoryDatabase -Query "exec policy.epm_LoadPolicyHistoryDetail"  -ErrorAction Stop
Kind regards,
Geoffrey

New Post: EPM Framework and SQL 2012

0
0
lewisrl wrote:
Do any of you have any ideas?
Since SQL Server 2012 has System Policies for viewing the health of Availability Groups, the PowerShell script will run Invoke-PolicyEvaluation for each Policy in the store.
A System Condition used in the AlwaysOn System Policies checks the Server Property "IsHadrEnabled" , but that property doesn't exist for versions lower than SQL Server 2012.

I modified the PowerShell script to skip all policies with a name starting with "AlwaysOn" and the script ran without errors.

Replace
        if (($Policy.PolicyCategory -eq $PolicyCategoryFilter)-or ($PolicyCategoryFilter -eq "")) 
with
        if (($Policy.PolicyCategory -eq $PolicyCategoryFilter)-or ($PolicyCategoryFilter -eq "") -and ($policy.name -notlike "AlwaysOn*"))

New Post: Error not loading any data in to PolicyHistory

0
0
This still does not work. I am running SQL 2014 on Windows Server 2012 R2. I have put your script in and get Add-PSSnapin : No snap-ins have been registered for Windows PowerShell version 4.

I have installed the 2008 R2 feature pack for CLR, ShareManagementObjects and PowerShell and still no luck.

Thanks for your help though. I might try on a lower version test server to see what happens.

New Post: Enterprise Policy Management Framework 4.0 versus SQL Server 2014

0
0
I have seen that Enterprise Policy Management Framework 4.0 is working with SQL Server 2012 but is it working with a SQL Server 2014 instance ?
Maybe it is a "basic" question but I think it's an interesting one since SQ Server 2014 has been released about 3 months ago.
I would understand that it is too soon to have a new version of this framework which seems really interesting
Have a nice day
Viewing all 138 articles
Browse latest View live




Latest Images