I have a file "test.ps1" and its content is as below:
$getRSDBName =
{
Add-PSSnapIn Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
$rsdb = Get-SPRSDatabase
return $rsdb
}
$rsdb = invoke-command -scriptblock $getRSDBName
$rsdb
It work if I call it as:
powershell -f c:\test.ps1
I get an error if I use WinRS:
winrs -r:xxxxx -u:xxxxxx -p:xxxxx powershell -f c:\test.ps1
I also tried it by inputting -Authentication CredSSP -Credential $creds
as parameters of Invoke-Command
, but I got the same result as before. In both instances, the error is:
The local farm is not accessible. Cmdlets with FeatureDependencyId are not registered. Get-SPRSDatabase : Cannot access the local farm. Verify that the local farm is properly configured, currently available, and that you have the appropriate per missions to access the database before trying again. At C:\clean.ps1:181 char:29 + $rsdb = Get-SPRSDatabase <<<< + CategoryInfo : InvalidData: (Microsoft.Repor...ServiceDatabase: GetReportingServiceDatabase) [Get-SPRSDatabase], SPCmdletException + FullyQualifiedErrorId : Microsoft.ReportingServices.SharePoint.PowerShell.GetReportingServiceDatabase
Could someone explain what is happening?