Error at SL command

Nov 4, 2010 at 7:42 PM
Edited Nov 4, 2010 at 8:03 PM

Hi,

I´m trying to run the command:

SL C:\EPM\EPM_EnterpriseEv
aluation_3.0.0.ps1 -ConfigurationGroup "dbs02dtc" -PolicyCategoryFilter "" -EvalMode "Check"

on PowerShell, the file path is ok, but i´m getting the error bellow:

Set-Location : A parameter cannot be found that matches parameter name 'Configu
rationGroup'.
At line:1 char:65
+ SL C:\EPM\EPM_EnterpriseEvaluation_3.0.0.ps1 -ConfigurationGroup <<<<  "dbs02
dtc" -PolicyCategoryFilter "Full DataBase Recovery model" -EvalMode "Check"
    + CategoryInfo          : InvalidArgument: (:) [Set-Location], ParameterBi
   ndingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Comm
   ands.SetLocationCommand

 

Can someone help me here?!?!?!?!

Coordinator
Nov 4, 2010 at 10:53 PM

Hello caputo,

Do you have a group created on the Central Management Server named dbs02dtc?  If not, create a folder with this name and register the instances in the folder. 

Nov 5, 2010 at 10:05 AM
Edited Nov 5, 2010 at 11:13 AM

Hi Lara!

Sure, i have a CMS named dbs02dtc, and now the databases, for another test without sucessfull, are in a folder named PROD:

+dbs02dtc  

       +PROD

               (my databases(3))


I tryed the commands:

SL C:\EPM\EPM_EnterpriseEv
aluation_3.0.0.ps1 -ConfigurationGroup "dbs02dtc" -PolicyCategoryFilter "" -EvalMode "Check"

SL C:\EPM\EPM_EnterpriseEv
aluation_3.0.0.ps1 -ConfigurationGroup "PROD" -PolicyCategoryFilter "" -EvalMode "Check"

SL C:\EPM\EPM_EnterpriseEv
aluation_3.0.0.ps1 -ConfigurationGroup "dbs02dtc\PROD" -PolicyCategoryFilter "" -EvalMode "Check"

but none worked....

 

 

 

If can help you, bellow follow my sp1 file

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

 

param([string]$ConfigurationGroup=$(Throw "Paramater 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 = "DBS02DTC"
$HistoryDatabase = "MDW"
# Define the location to write the results of the
# policy evaluation.  Delete any files in the directory.
$ResultDir = "C:\EPM\Results\"
$ResultDirDel = $ResultDir + "*.xml"
Remove-Item -Path $ResultDirDel
# 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

 


But didn´t work anyway....there is some other information you need to help me?

Coordinator
Nov 5, 2010 at 11:09 AM

Just to double check: you are executing the command on one line without a carriage return:

SL C:\EPM\EPM_EnterpriseEvaluation_3.0.0.ps1 -ConfigurationGroup "dbs02dtc" -PolicyCategoryFilter "" -EvalMode "Check"

not

SL C:\EPM\EPM_EnterpriseEv
aluation_3.0.0.ps1 -ConfigurationGroup "dbs02dtc" -PolicyCategoryFilter "" -EvalMode "Check"

 

Nov 5, 2010 at 11:16 AM
Edited Nov 5, 2010 at 2:27 PM

on one line.....

SL C:\EPM\EPM_EnterpriseEvaluation_3.0.0.ps1 -ConfigurationGroup "dbs02dtc" -PolicyCategoryFilter "" -EvalMode "Check"

 

Lara, when i try the command:

.\EPM_EnterpriseEvaluation_3.0.0.ps1 -ConfigurationGroup "dbs02dtc" -PolicyCategoryFilter "" -EvalMode "Check"

I have the error bellow:

PS C:\EPM> .\EPM_EnterpriseEvaluation_3.0.0.ps1 -Configurationgroup "dbs02dtc" -
PolicyCategoryFilter "" -EvalMode "Check"
New-Object : Exception calling ".ctor" with "1" argument(s): "Failed to connect
 to server ."
At C:\EPM\EPM_EnterpriseEvaluation_3.0.0.ps1:58 char:26
+ $PolicyStore = new-object <<<<  Microsoft.SqlServer.Management.DMF.PolicyStor
e($conn);
    + CategoryInfo          : InvalidOperation: (:) [New-Object], MethodInvoca
   tionException
    + FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.Power
   Shell.Commands.NewObjectCommand

Exception calling "Open" with "0" argument(s): "Login failed for user 'DATASOLU
TION\fabrizzio.caputo'."
At C:\EPM\EPM_EnterpriseEvaluation_3.0.0.ps1:64 char:12
+ $sconn.Open <<<< ()
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

Exception calling "ExecuteReader" with "0" argument(s): "ExecuteReader requires
 an open and available Connection. The connection's current state is closed."
At C:\EPM\EPM_EnterpriseEvaluation_3.0.0.ps1:67 char:25
+ $dr = $cmd.ExecuteReader <<<< ();
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

You cannot call a method on a null-valued expression.
At C:\EPM\EPM_EnterpriseEvaluation_3.0.0.ps1:73 char:16
+ while ($dr.Read <<<< ()) {
    + CategoryInfo          : InvalidOperation: (Read:String) [], RuntimeExcep
   tion
    + FullyQualifiedErrorId : InvokeMethodOnNull

You cannot call a method on a null-valued expression.
At C:\EPM\EPM_EnterpriseEvaluation_3.0.0.ps1:97 char:10
+ $dr.Close <<<< ()
    + CategoryInfo          : InvalidOperation: (Close:String) [], RuntimeExce
   ption
    + FullyQualifiedErrorId : InvokeMethodOnNull

Invoke-Sqlcmd : Login failed for user 'DATASOLUTION\fabrizzio.caputo'.
At C:\EPM\EPM_EnterpriseEvaluation_3.0.0.ps1:101 char:14
+ Invoke-Sqlcmd <<<<  -ServerInstance $CentralManagementServer -Database $Histo
ryDatabase -Query "exec policy.epm_LoadPolicyHistoryDetail"  -ErrorAction Stop
    + CategoryInfo          : InvalidOperation: (:) [Invoke-Sqlcmd], SqlExcept
   ion
    + FullyQualifiedErrorId : SqlExectionError,Microsoft.SqlServer.Management.
   PowerShell.GetScriptCommand

Coordinator
Nov 17, 2010 at 2:15 PM

I think I see the problem.  The name of the CMS instance is dbs02dtc, right?  This is not the name of a folder, but the instance?  It appears that you have a folder named "Prod" on the CMS.  Please pass this folder name into the script as ConfigurationGroup. 

 

Nov 18, 2010 at 1:29 PM

Lara, did not work =(

 

i tryed dbs02dtc, prod and dbs02dtc\prod, but none work =(

Feb 11, 2011 at 3:34 PM

I know your message exchanges on the errors were lasy November and this reply may be too late.

But for whatever it's worth I wanted to point out that your error is happening because the first line (SL command) is a change directory command and should be typed and executed separately.

Then you should run the EPM_EnterpriseEvaluation_3.0.0.ps1 script to validate your policies for you.

I was making the same mistake at first.

Now, the problem I have is that inside of that PowerShell script the If statement is not working as it should.

This condition: if (($Policy.PolicyCategory -eq $PolicyCategoryFilter) -or ($PolicyCategoryFilter -eq ""))

Is not making a match (although Policy Category I specified on command line and one of the Policy Category filter values do match!

Any ideas?

 

Thanks,

Ben Bagheri, Dallas, texas