Connect-PnPOnline-找不到接受参数'System.Management.Automation.PSCredential

问题描述 投票:0回答:1
的位置参数

[我试图连接到Azure应用服务中运行的PowerShell作业的共享点站点,每当我尝试连接它都会给我以下错误:

Authentication failed: A positional parameter cannot be found that accepts argument 'System.Management.Automation.PSCredential'.

[在为位置参数-Credentials查找方法Connect-PnPOnline的源代码时,它期望使用CredentialPipeBind,它是类public sealed class CredentialPipeBind

该类看起来像是要在Windows凭据管理器的凭据或Powershell凭据对象之间切换。Azure作业可能想从位置参数获取文字类型?我尝试给它一个

Function Set-SpsConnection ($url, $creds) {
    $crpb = [SharePointPnP.PowerShell.Commands.Base.PipeBinds.CredentialPipeBind]::new($creds)
    Connect-PnPOnline –Url $sharepointurl –Credentials $crpb
}

但无济于事,现在它认为我使用的是SharePointPnP.PowerShell.Commands.Base.PipeBinds.CredentialPipeBind而不是CredentialPipeBind,也许我可以以某种方式引用程序集,这样我就不必指定了?

我认为这似乎是天青工作系统中的一个固有缺陷,它只会解释乱码类型,而不会像在客户端上那样运行。

powershell azure-webjobs
1个回答
0
投票

根据我的研究,如果要使用PowerShell中的凭据连接到共享站点,则参数Credentials应该是PSCredential对象或字符串(Windows凭据管理器中的证书名称凭据)。有关更多详细信息,请参阅articleissuedocumententer image description here

例如

$name = "username"
$password = "password"
$secpasswd = ConvertTo-SecureString $password -AsPlainText -Force
$mycreds = New-Object System.Management.Automation.PSCredential ($name, $secpasswd)
Connect-PnPOnline -Url https://hanxia.sharepoint.com/ -Credentials $mycreds
Get-PnPList

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.