How to add a filter to a variable.

  • Hello,

    I hope someone can offer some guidance. I have written a function to set some SSRS settings. It all worked well until I added a couple more SSRS instances. Now, even though I specify the instance name when I call it, the script tries to do all the SSRS instances it finds. I just want it to do the one I specify when I call it. From what I understand I need to apply a filter, but I am not sure where or how, and whether I could apply the filter at the global variable level, rather than on each of the functions that contains the variable. The variable is "SQLInstanceName".

    Here is my code...

    function fn-Set-SSRS-ReportServer-VirtualDirectory ([String]$SQLInstanceName, [String]$SSRSDatabaseServerName, [String]$SSRSDatabaseServerTcpPort, [String]$InstID)

    {

    Try

    {

    $SSRSConMgr = Get-WmiObject -Namespace "root\Microsoft\SqlServer\ReportServer\RS_$SQLInstanceName\v11\Admin" -Class MSReportServer_ConfigurationSetting -ComputerName $ManagedComputer

    $SSRSConMgr.SetDatabaseConnection("$SSRSDatabaseServerName,$SSRSDatabaseServerTcpPort","ReportServer", 2, "", "")

    $SSRSConMgr.SetVirtualDirectory("ReportServerWebService", "ReportServer", "3081")

    $SSRSConMgr.ReserveURL("ReportServerWebService","http://+:80","3081")

    $SSRSConMgr.ReserveURL("ReportServerWebService","http://+:443","3081")

    $SSRSConMgr.SetVirtualDirectory("ReportManager", "Reports", "3081")

    $SSRSConMgr.ReserveURL("ReportManager","http://+:80","3081")

    $SSRSConMgr.ReserveURL("ReportManager","https://+:443","3081")

    $XML=[XML](Get-Content "E:\Program Files\Microsoft SQL Server\MSRS11.$SQLInstanceName\Reporting Services\ReportServer\rsreportserver.config")

    $InstID = $XML.DocumentElement.InstallationID.Trim("{","}")

    $SSRSConMgr.DeleteEncryptedInformation()

    $SSRSConMgr.InitializeReportServer($InstID)

    $Result = $SSRSConMgr.Isinitialized

    if ($Result -ne 'True')

    {

    Throw "$Result and $Error[0]"

    }

    }

    Catch

    {

    Write-Error $Result

    }

    }

    Thank you for reading.

    Kind regards,

    D.

  • Hi,

    Maybe some help here: http://blogs.msdn.com/b/jgalla/archive/2010/05/26/rs-powershell-gems-the-wmi-provider.aspx

    or here: https://msdn.microsoft.com/en-us/library/ms152836%28v=sql.105%29.aspx

    Gaz

    -- Stop your grinnin' and drop your linen...they're everywhere!!!

  • Did you get it sorted?

    If so please confirm your solution for others.

    If not then feel free to ask for more assistance.

    Gaz

    -- Stop your grinnin' and drop your linen...they're everywhere!!!

  • I did indeed, sorry for the late reply, I've been away. I had to add in some variables which sorted it. Here is the relevant bit of code I ended up with...

    Try

    {

    $SSRSConMgr = Get-WmiObject -Namespace "root\Microsoft\SqlServer\ReportServer\RS_$SQLInstanceName\v11\Admin" -Class MSReportServer_ConfigurationSetting -ComputerName $ManagedComputer

    $SSRSConMgr.SetDatabaseConnection("$SSRSDatabaseServerName,$SSRSDatabaseServerTcpPort","ReportServer", 2, "", "")

    $SSRSConMgr.SetVirtualDirectory("ReportServerWebService", "ReportServer", "3081")

    $SSRSConMgr.ReserveURL("ReportServerWebService","http://+:80","3081")

    $SSRSConMgr.ReserveURL("ReportServerWebService","https://$ManagedComputer"+":443","3081")

    $SSRSConMgr.SetVirtualDirectory("ReportManager", "Reports", "3081")

    $SSRSConMgr.ReserveURL("ReportManager","http://+:80","3081")

    $SSRSConMgr.ReserveURL("ReportManager","https://$ManagedComputer"+":443","3081")

    $XML=[XML](Get-Content "E:\Program Files\Microsoft SQL Server\$InstanceName\MSRS11.$SQLInstanceName\Reporting Services\ReportServer\rsreportserver.config")

    $InstID = $XML.DocumentElement.InstallationID.Trim("{","}")

    $SSRSConMgr.DeleteEncryptedInformation()

    $SSRSConMgr.InitializeReportServer($InstID)

    $Result = $SSRSConMgr.Isinitialized

    Pop-Location

    if ($Result -ne 'True')

    I hope it helps someone else one day!

    Regards,

    D.

  • Thanks for sharing.

    Gaz

    -- Stop your grinnin' and drop your linen...they're everywhere!!!

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply