2

I have already installed Report server database(SSRS 2016). I know how to configure Report server through RS Configuration Manager, but I want to do this automatically with power shell. I want to change Webservice and WebPortal URL to "https" and bind a certificate which is already imported to Trusted Root Certification Authorities. And Certificate present at location C:\Temp.

I m trying the below script

$httpsPort = 443;
$ipAddress = "0.0.0.0";
$certpwd = '******abc'
$certpwd1 = ConvertTo-SecureString -String $certpwd -Force –AsPlainText
$Thumbprint = (Get-PfxData -Password $certpwd1 -FilePath  
C:\Temp\INBLRSHCPR12371.pfx).EndEntityCertificates.Thumbprint.ToLower()
$wmiName = (Get-WmiObject –namespace root\Microsoft\SqlServer\ReportServer 
-Filter "Name='$env:COMPUTERNAME'"  –class __Namespace).Name
$version = (Get-WmiObject –namespace 
root\Microsoft\SqlServer\ReportServer\$wmiName  –class __Namespace).Name
$rsConfig = Get-WmiObject –namespace 
"root\Microsoft\SqlServer\ReportServer\$wmiName\$version\Admin" -class 
MSReportServer_ConfigurationSetting
$rsConfig.ReserveURL("ReportServerWebApp","https://+:$httpsPort",(Get- 
Culture).Lcid)
$rsConfig.ReserveURL("ReportServerWebService","https://+:$httpsPort",(Get- 
Culture).Lcid)
$rsConfig.CreateSSLCertificateBinding('ReportServerWebApp', $Thumbprint, 
$ipAddress, $httpsport, (Get-Culture).LCID)
$rsConfig.CreateSSLCertificateBinding('ReportServerWebService', 
$Thumbprint, $ipAddress, $httpsport, (Get-Culture).Lcid) 
$rsconfig.SetServiceState($false, $false, $false)
$rsconfig.SetServiceState($true, $true, $true)

I am getting below error when running the script:

Get-WmiObject : Invalid parameter 
At line:7 char:13
+ $version = (Get-WmiObject –namespace root\Microsoft\SqlServer\ReportS ...
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidOperation: (:) [Get-WmiObject], 
ManagementException
+ FullyQualifiedErrorId : 
GetWMIManagementException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

Any code or link for resolving the error is appreciable Thank You in Advance

  • And what have you tried yourself already? SO is meant to help people with their code, but you don't show any.. – Theo May 05 '21 at 09:06
  • As of now, I created Self signed certificate with powershell Script and Imported that to Trusted Root Certificate Authorities using below script `$certpwd = '****' $certpwd1 = ConvertTo-SecureString -String $certpwd -Force –AsPlainText Import-PfxCertificate -FilePath C:\Temp\INBLRSHCPR12371.pfx -CertStoreLocation Cert:` Now I need to bind this certificate and change URLs to "https" in RS configuration Manager with powershell – Karthik Karnam May 05 '21 at 09:37
  • Then please [edit](https://stackoverflow.com/posts/67398140/edit) your question and add the formatted code you have in there. Also explain what works/doens't work, what is missing, what error messages you are receiving if any. Please do not post code in a comment because it will lose all formatting there. – Theo May 05 '21 at 09:40

2 Answers2

1

I got to know my issue : The correct working script is below:

$ipAddress = "0.0.0.0";
$certpwd = '******abc'
$certpwd1 = ConvertTo-SecureString -String $certpwd -Force –AsPlainText
$Thumbprint = (Get-PfxData -Password $certpwd1 -FilePath  
C:\Temp\INBLRSHCPR12371.pfx).EndEntityCertificates.Thumbprint.ToLower()
$wmiName=(Get-WmiObject -namespace root\Microsoft\SqlServer\ReportServer  -class 
__Namespace -ComputerName $env:COMPUTERNAME).Name
$version = (Get-WmiObject –namespace 
root\Microsoft\SqlServer\ReportServer\$wmiName  –class __Namespace).Name
$rsConfig = Get-WmiObject –namespace 
"root\Microsoft\SqlServer\ReportServer\$wmiName\$version\Admin" -class 
 MSReportServer_ConfigurationSetting
 $rsConfig.ReserveURL("ReportServerWebApp","https://+:$httpsPort",(Get- 
 Culture).Lcid)
 $rsConfig.ReserveURL("ReportServerWebService","https://+:$httpsPort",(Get- 
 Culture).Lcid)
 $rsConfig.CreateSSLCertificateBinding('ReportServerWebApp', $Thumbprint, 
 $ipAddress, $httpsport, (Get-Culture).LCID)
 $rsConfig.CreateSSLCertificateBinding('ReportServerWebService', 
 $Thumbprint, $ipAddress, $httpsport, (Get-Culture).Lcid) 
 $rsconfig.SetServiceState($false, $false, $false)
 $rsconfig.SetServiceState($true, $true, $true)
0

Try executing your script as Administrator.

The problem lies in this statement: $rsConfig = Get-WmiObject –namespace "root\Microsoft\SqlServer\ReportServer$wmiName$version\Admin" -class MSReportServer_ConfigurationSetting

CarlDog
  • 23
  • 2
  • Hi CarlDog, I have found out my mistake. Its with $wmiName. It need to be like this $wmiName=(Get-WmiObject -namespace root\Microsoft\SqlServer\ReportServer -class __Namespace -ComputerName $env:COMPUTERNAME).Name – Karthik Karnam Sep 08 '22 at 09:27