简体   繁体   English

如何避免 sql 服务器代理中的凭据弹出 powershell window ?

[英]How could I avoid credential popup powershell window in sql server agent?

I've been struggling to make my powershell script work for pulling data from a Sharepoint list to sql server via SQL Agent.我一直在努力让我的 powershell 脚本通过 Z9778840A0100CBB03 代理从 Sharepoint 列表中提取数据到 sql 服务器。 And to do so, I'm using SharePointPnPPowerShellOnline module and added the following code to take credentials automatically.为此,我使用SharePointPnPPowerShellOnline模块并添加了以下代码以自动获取凭据。

$filePath="https://AnyCompany.sharepoint.com/teams/AnySite"
Connect-PnPOnline -Url $filePath -UseWebLogin

But when I put this in sql agent it doesn't work as it does in powershell or even in task scheduler.但是当我把它放在 sql 代理中时,它不像在 powershell 甚至在任务调度程序中那样工作。

The error message By the error message, I found that the problem is with this credential pop up window.错误消息通过错误消息,我发现问题出在此凭据弹出 window 上。 So how could I avoid this?那我怎么能避免这种情况呢? How could I get the connection to sharepoint site without putting this line of code.如果不输入这行代码,我怎么能连接到 sharepoint 站点。

The picture belows shows my settings and the last line of code is causing the error.下图显示了我的设置,最后一行代码导致了错误。 My current job settings我当前的工作设置

Sincerely, I'd appreciate any guidance.真诚地,我将不胜感激任何指导。

Hi Luis Antonio Espinoza,嗨路易斯·安东尼奥·埃斯皮诺萨,

If you do not want the cmdlet Connect-PnPOnline popup the login window, why not hard code your credential in the script:如果您不希望 cmdlet Connect-PnPOnline弹出登录 window,为什么不在脚本中硬编码您的凭据:

$Username='abc@contoso.onmicrosoft.com'
$Password = '*****'

#region Credentials
[SecureString]$SecurePass = ConvertTo-SecureString $Password -AsPlainText -Force 
[System.Management.Automation.PSCredential]$PSCredentials = New-Object 
System.Management.Automation.PSCredential($Username, $SecurePass) 
#endregion Credentials

#connect to site
Connect-PnPOnline -Url $filePath -Credentials $PSCredentials

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

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