Share via


RS PowerShell Gems – The WMI Provider

For IT administration of a Report Server instance, you will occasionally need to use WMI.  We try to ease this to some extent by exposing a command line tool rsconfig.exe as well as the RS Configuration Tool UI. That said, sometimes you just need to talk to WMI directly – and for that PowerShell is a great tool!

Here are a couple of script fragments that I have used in the past:

# Gem 1 - Enumerate All Instances
#

$computer = "JGALLA7"
$namespaces = gwmi -class "__NAMESPACE" -namespace "root\Microsoft\SqlServer\ReportServer" -computer $computer
[string]$fn = $namespaces[0].Name

# any of the namespaces can be used to enumerate all instances
$instances = gwmi -class MSReportServer_Instance -namespace "root\Microsoft\SqlServer\ReportServer\$fn\v10" -computer $computer
$instances | ft InstanceName,EditionName,Version

#InstanceName                            EditionName                             Version
#------------                            -----------                             -------
#MSSQLSERVER                             ENTERPRISE EVALUATION EDITION            ####
#ELEND                                   ENTERPRISE EVALUATION EDITION            ####
#VIN                                     ENTERPRISE EVALUATION EDITION            ####
#SAZED                                   DEVELOPER EDITION                        ####

# Gem 2 - get service account of each instance

$configurations = gwmi -class MSReportServer_ConfigurationSetting -namespace "root\Microsoft\SqlServer\ReportServer\$fn\v10\Admin" -computer $computer
$configurations | ft InstanceName,ServiceName,WindowsServiceIdentityConfigured

#InstanceName                            ServiceName                             WindowsServiceIdentityConfigured
#------------                            -----------                             --------------------------------
#MSSQLSERVER                             ReportServer                            redmond\####
#ELEND                                   ReportServer$ELEND                      NT Authority\NetworkService
#VIN                                     ReportServer$VIN                        NT Authority\NetworkService
#SAZED                                   ReportServer$SAZED                      NT AUTHORITY\NETWORK SERVICE

# Gem 3 - Update Service Account Password of each instance using a particular user name
$username = "redmond\####"
$newpassword = "mynewpassword"
foreach ($update in $configurations | where {$_.WindowsServiceIdentityConfigured -eq $username})
{
  $update.SetWindowsServiceIdentity(0, $username, $newpassword)
}

Some additional useful links: