I have a powershell script that I need to execute from a SQL server on a schedule. I don't think it matters, but in case it does, the script is sending the command to refresh a powerbi.com dataset. I can run it successfully locally and on one of my servers, but when I try it on the other one, I get the error below.
For clarification, the powershell versions match as well as the execution policies. I have listed them here:
PS Version 5.1.14409.1005
Execution Policy
Scope ExecutionPolicy
Machine Policy Undefined
User Policy Undefined
Process Undefined
CurrentUser Undefined
LocalMachine RemoteSigned
The error I get on one of the servers is below:
Connect-PowerBIServiceAccount : Failed to populate environments in settings
At
DatasetRefresh_NoParam_Simple.ps1:9
char:1
+ Connect-PowerBIServiceAccount -Credential $myCred
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : WriteError: (Microsoft.Power...IServiceAccount:ConnectPowerBIServiceAccount) [Connect-Po
werBIServiceAccount], Exception
+ FullyQualifiedErrorId : Failed to populate environments in settings,Microsoft.PowerBI.Commands.Profile.ConnectPo
werBIServiceAccount
Invoke-PowerBIRestMethod : Login first with Login-PowerBIServiceAccount
At
DatasetRefresh_NoParam_Simple.ps1:19
char:1
+ Invoke-PowerBIRestMethod -Url $RefreshDSURL -Method Post -Body $MailF ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Invoke-PowerBIRestMethod], Exception
+ FullyQualifiedErrorId : System.Exception,Microsoft.PowerBI.Commands.Profile.InvokePowerBIRestMethod
I feel like there is a server setting that I'm missing, but I'm logged into both with admin credentials and running powershell as administrator. Any help would be appreciated.
EDIT
I tried to run a different script to also show the other error I am getting.
\\BlahServerName\WorkSpace\PowerBI\BDW_Resources\Admin\DatasetRefresh_PS\DatasetRefresh_Param_onlyDataset.ps1 : File
\\BlahServerName\WorkSpace\PowerBI\BDW_Resources\Admin\DatasetRefresh_PS\DatasetRefresh_Param_onlyDataset.ps1 cannot be
loaded. The file
\\BlahServerName\WorkSpace\PowerBI\BDW_Resources\Admin\DatasetRefresh_PS\DatasetRefresh_Param_onlyDataset.ps1 is not
digitally signed. You cannot run this script on the current system. For more information about running scripts and
setting execution policy, see about_Execution_Policies at http://go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1
+ \\BlahServerName\WorkSpace\PowerBI\BDW_Resources\Admin\DatasetRefresh_ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : SecurityError: (:) [], PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess
This is the one I got too that led me to look at the execution policies, but if both of my servers have the same policy settings, why am I able to execute on one and not the other? (Again, I'm logged in as myself on both with admin privileges)
If you are executing it from SQL Server - I assume that is using SQL Agent?
Be aware of the context that SQL Server Agent executes in - have you created a SQL Agent Proxy using a defined credential to ensure the context?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.