Powershell – How to use Powershell 2 Get-WmiObject to find an instance of SQL Server Reporting Services (SQL2008) on Windows Server 2008 R2

powershellsqlssrswmi

I'm trying to use the powershell 2 "Get-WmiObject" command to find the reporting service instance using this command

 get-wmiobject -class "MSReportServer_Instance" -namespace "root\Microsoft\SqlServer\ReportServer"

THE ERROR I GET BACK

Get-WmiObject : Invalid class
At line:1 char:14
+ get-wmiobject <<<<  -class "MSReportServer_Instance" -namespace "root\Microsoft\SqlServer"
    + CategoryInfo          : InvalidOperation: (:) [Get-WmiObject], ManagementException
    + FullyQualifiedErrorId :     GetWMIManagementException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

NOTES

  • This is Powershell 2
  • OS = Windows Server 2008 R2 RC (x64)
  • SQL = SQL 2008 SP1 (x64)
  • Reporting Services is installed and works – have several reports running)
  • Everything is running on the same box (the script, SQL, SSRS)
  • Link to WMI info for SSRS: http://msdn.microsoft.com/en-us/library/ms152858.aspx
  • I've tried (guessing) different variations on the namespace but nothing worked

THE ANSWER (2009-06-22)

The code below finds the instance and places it into $rs_instance

$ns = Get-WmiObject -class "__NAMESPACE" -namespace "root\Microsoft\SqlServer\ReportServer"
$rs_instance_name = "root\Microsoft\SqlServer\ReportServer\" + $ns.Name + "\v10"
$rs_instance = Get-WmiObject -class "MSReportServer_Instance" -namespace $rs_instance_name

Best Answer

Using WmiExplorer.ps1 script I can see the instance name in __NAMESPACE and this query returns my instance name:

gwmi -class "__NAMESPACE" -namespace "root\Microsoft\SqlServer\ReportServer"

To get to MSReporterServer_Instance you must supply the instance name in this example my instance name is RS_SQL2K8:

gwmi -class "MSReportServer_Instance" -namespace "root\Microsoft\SqlServer\ReportServer\RS_SQL2K8\v10"