Invoke-PolicyEvaluation and -TargetExpression

  • hello

    I have set up a condition and policy to check if datafiles have a @GrowthType of KB. This works fine when i execute in management studio but i'm having problems using powershell. I'm not sure what to set the -TargetExpression to. This is the code i'm trying to execute...

    $DatabaseName = 'master'

    $ServerInstance = 'localhost'

    $TargetExpression = "Server[@Name='$ServerInstance']/Database[@Name='$DatabaseName']"

    Set-Location "SQLSERVER:\SQLPolicy\localhost\Policies\"

    $pol = (Get-ChildItem | Where-Object {$_.DisplayName -eq "DataFileGrowth"}) | Invoke-PolicyEvaluation -TargetServerName "$ServerInstance" -TargetExpression $TargetExpression

    $ReturnedValue = $pol.Result

    $ReturnedValue

  • The target expression defines what the policy will be evaluating (internally referred to as the Object Set). Normally you define the target when you create the policy, but this parameter allows you to override that at evaluation time. If you've properly defined the target in the policy you don't need this expression at all.

    Hope that helps.

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply