Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

How to Loop Through Central Management Server in SQL Server 2012 Using PowerShell

$
0
0

I am trying to learn PowerShell.  I want to use it to gather information from a Central Management Server and input the information into a table in a database.

 


In Windows PowerShell ISE I am trying to run the following.  I am just running a test to see how it loops through the Central Management Server.  Maybe this example I found on http://sqlvariant.com/2011/01/powershell-week-at-sql-university-post-5/ isn't a good example?

---------------------
$filter = Set-AgentJobHistoryFilter -startDate $(get-date).AddDays(-3) -endDate $(get-date) -outcome 'Failed'

foreach ($RegisteredSQLs in dir -recurse SQLSERVER:\SQLRegistration\'Database Engine Server Group'\Test\ | where {$_.Mode -ne "d"} )
{
Get-AgentJobHistory $RegisteredSQLs.ServerName $filter | where-object {$_.StepID -ne 0}
}

---------------------

 


I am getting the following error message:
---------------------
dir : SQL Server PowerShell provider error: Invalid Path: 'SQLSERVER:\SQLRegistration\Database Engine Server Group\Test'.
At line:3 char:29
+ foreach ($RegisteredSQLs in dir -recurse SQLSERVER:\SQLRegistration\'Database En ...
+                             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-ChildItem], GenericProviderException
    + FullyQualifiedErrorId : Microsoft.SqlServer.Management.PowerShell.GenericProviderException,Microsoft.PowerShell.Commands.GetChildItemCommand
---------------------

But I do not know how to fix it.  Can anyone explain to me why this isn't working?

 


lcerni


Viewing all articles
Browse latest Browse all 21975

Trending Articles



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