Quantcast
Channel: SQL Server Manageability forum
Viewing all articles
Browse latest Browse all 1519

Invoke-PolicyEvaluation TargetObject Issue

$
0
0

Hello everyone.

I am really stumped here and was hoping that I can get some help as I haven't been able to find anything on my own.  

I am working with Policy Based Management (PBM) to start auditing our environment for things like backups, etc.  I need to run this across a few hundred servers, and really don't want to loop through each of the servers.  I see in the Invoke-PolicyEvaluation cmdlet, that it has the option of -TargetObject.  In reading the notes on Invoke-PolicyEvaluation, I see this statement:

  • -TargetObjects takes an object or array of objects that represent the SQL Server objects in the target set. For example, you could create an array of Database class objects to pass in to -TargetObjects.

However, when I pull a list of database objects from CMS, it won't work.  Below is a code sample of what I am trying to do.  

How can I get this process multi-threaded for a large number of databases, rather than having to loop through each server?

## params
[string]$EvalMode="Check"
[string]$CentralManagementServer = "TS001-EQLT586\dev_sql2012"
[string]$HistoryDatabase = "DBASupport"
[string]$ConfigurationGroup="ProductionCluster"
[string]$PolicyCategoryFilter="ProductionBackups"

#Get server list
$CMSGroupFolders = Get-ChildItem -Recurse -Path "SQLSERVER:\SQLRegistration\Central Management Server Group\$CentralManagementServer" | ? {$_.Mode -ieq "d"}
$ServerList = $CMSGroupFolders | ? {$_.Name -ieq $ConfigurationGroup} | Get-ChildItem -recurse | ?{$_.Mode -ieq "-"}

#Get policy list
$PolicyList = Get-ChildItem -Path SQLSERVER:\SQLPolicy\$CentralManagementServer\Policies | ? {$_.Name -ilike "*Full*"}

FOREACH ($Policy in $PolicyList)
{
    Invoke-PolicyEvaluation -Policy $Policy -TargetObjects $ServerList -AdHocPolicyEvaluationMode $EvalMode -OutputXML > C:\OUTPUT.XML
}

Thank you all for you help in advance.  

Sincerely,

Nathan


Viewing all articles
Browse latest Browse all 1519

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>