Hello everybody,
I am trying to execute a PowerShell Skript using SQL Server Agent, which imports a Module (ReportingServicesTools).
There seems to be some permission issue and I am not sure whether the cause is in SQL Server Agent, or PowerShell.
To simply everything I set up a clean VM running Windows Server 2022 Standard, SQL Server 2022 Developer.
Then I installed the Module using Windows Powershell 5.1.
This is my PowerShell Code, I have saved to C:\test\test.ps1:
if (-not (Get-Module ReportingServicesTools)) { Import-Module ReportingServicesTools -WarningAction SilentlyContinue -DisableNameChecking }
Connect-RsReportServer -ComputerName localhost -ReportServerInstance MSSQLSERVER
$ReportServerUri = "http://localhost/reportserver"
$catalogItems = Get-RsCatalogItems -RsFolder / -Recurse -ReportServerUri $ReportServerUri
It works fine under these conditions:
- Execute locally from PowerShell 5.1 command line (local Admin or normal user)
- Execute from SQL Server (using SQL Server Agent job step) running under SQL Server Agent Account or a local Administrator as a proxy account
It does not work in this case:
- Execute from SQL Server (using SQL Server Agent job step) running under local user as a proxy account
Since we do not want our scripts to run as admin to follow the principle of least privilege, I like to find out, what we not do to get a PowerShell Skript running as a local user or AD Service account.
My error message is (partly in German):
Ausgeführt als Benutzer: ''WIN-FAAUJQ8NNM0\Mark''. Der Typ [Microsoft.ReportingServicesTools.SqlServerVersion] wurde nicht gefunden. In C:\Program Files\WindowsPowerShell\Modules\ReportingServicesTools\0.0.7.3\Functions\Utilities\Connect-RsReportServer.ps1:67 Zeichen:9 + [Microsoft.ReportingServicesTools.SqlServerVersion] + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (Microsoft.Repor...qlServerVersion:TypeName) [], RuntimeException + FullyQualifiedErrorId : TypeNotFound Der Typ [Microsoft.ReportingServicesTools.ConnectionHost] wurde nicht gefunden. In C:\Program Files\WindowsPowerShell\Modules\ReportingServicesTools\0.0.7.3\Functions\Utilities\New-RsWebServiceProxy.ps1:62 Zeichen:24 + ... edential = ([Microsoft.ReportingServicesTools.ConnectionHost]::Creden ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (Microsoft.Repor....ConnectionHost:TypeName) [], RuntimeException + FullyQualifiedErrorId : TypeNotFound Es ist nicht möglich, eine Methode für einen Ausdruck aufzurufen, der den NULL hat. In C:\Program Files\WindowsPowerShell\Modules\ReportingServicesTools\0.0.7.3\Functions\CatalogItems\Get-RsFolderContent.ps1:85 Zeichen:17 + $Proxy.ListChildren($Item, $Recurse) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : InvokeMethodOnNull. Prozessexitcode 1. Fehler bei Schritt.
So it seems the user cannot read the library.ps1 file from the ReportingServicesTools module, although all users have read and execute permissions in C:\Program Files\WindowsPowerShell\Modules.
There must be something else.
Anyone any idea?
I would be glad for any help :)
Mark