1

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

3 Answers 3

1

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"
1

First off, is it a valid class?

Try this: PS>get-wmiobject -list -namespace "root\Microsoft\SqlServer"

Does that class get listed?

Shortcut: PS>get-wmiobject -list -namespace "root\Microsoft\SqlServer"|where{$_.name -eq "MSReportServer_Instance"}

I have a VM running Server 2008 with SQL 2008 and can try this out tomorrow.

If you're not sure of the namespace: PS> Get-WmiObject -Namespace "root" -Class "__NAMESPACE" | Format-List Name

(That's from: http://www.eggheadcafe.com/conversation.aspx?messageid=31024041&threadid=31024027)

1
  • Actually, as per that link you provided, your namespace needs to look like this: root\Microsoft\SqlServer\ReportServer\<InstanceName>\v10 This works from a Microsoft VM: PS> get-wmiobject -class "MSReportServer_Instance" -namespace "root\Microsoft\SqlServer\ReportServer\rs_mssqlserver\v10"
    – Marco Shaw
    Jun 22, 2009 at 15:48
1

If what you're trying to do requires WMI this may be missing the point, but SQL Server 2008 ships with managed extensions that means most automation tasks no longer need to be perfromed with WMI.

For example on a machine with the client extensions installed either select the DB with open in powershell right click context menu command or load the extensions in any powershell session (http://blogs.msdn.com/mwories/archive/2008/06/14/SQL2008_5F00_Powershell.aspx) and you can do the following:

PS > cd SQLSERVER
PS > Set-Location \sql\MyServer\ReportServer

You can now manage the database objects just like you would manipulate your locla file system in PowerShell (for example try running dir . | Get-Member to see some properties to interact with).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .