简体   繁体   English

PowerShell 不从 SQL 服务器执行脚本

[英]PowerShell not executing script from SQL server

I have a powershell script that I need to execute from a SQL server on a schedule.我有一个 powershell 脚本,需要按计划从 SQL 服务器执行。 I don't think it matters, but in case it does, the script is sending the command to refresh a powerbi.com dataset.我认为这并不重要,但如果确实如此,脚本会发送命令以刷新 powerbi.com 数据集。 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.为了澄清起见,powershell 版本以及执行策略都匹配。 I have listed them here:我在这里列出了它们:

PS Version 5.1.14409.1005 PS 版本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.我觉得我缺少一个服务器设置,但我使用管理员凭据登录并以管理员身份运行 powershell。 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?如果您是从 SQL Server 执行它 - 我假设它正在使用 SQL 代理?

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?请注意 SQL Server 代理在其中执行的上下文 - 您是否使用定义的凭据创建了 SQL 代理代理以确保上下文?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM