【问题标题】:How could I avoid credential popup powershell window in sql server agent?如何避免 sql server 代理中的凭据弹出 powershell 窗口?
【发布时间】:2020-09-29 01:26:10
【问题描述】:

我一直在努力使我的 powershell 脚本能够通过 SQL 代理从 Sharepoint 列表中提取数据到 sql 服务器。为此,我使用了SharePointPnPPowerShellOnline 模块并添加了以下代码以自动获取凭据。

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

但是当我把它放在 sql 代理中时,它不像在 powershell 甚至在任务调度程序中那样工作。

The error message 通过错误消息,我发现问题出在此凭据弹出窗口上。那我怎么能避免这种情况呢?如果不放置这行代码,我怎么能连接到共享点站点。

下图显示了我的设置,最后一行代码导致了错误。 My current job settings

此致,我将不胜感激。

【问题讨论】:

    标签: .net powershell sharepoint powershell-3.0 sharepoint-online


    【解决方案1】:

    嗨,路易斯·安东尼奥·埃斯皮诺萨,

    如果您不希望 cmdlet Connect-PnPOnline 弹出登录窗口,为什么不在脚本中硬编码您的凭据:

    $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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-05-27
      • 2022-01-22
      • 1970-01-01
      • 2023-03-10
      • 1970-01-01
      • 2020-11-19
      • 2013-09-18
      • 1970-01-01
      相关资源
      最近更新 更多