【发布时间】:2020-03-01 08:20:42
【问题描述】:
我正在尝试从在 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,也许我可以以某种方式引用程序集,这样我就不必指定了?
该问题似乎仅在由作业运行或我在 Kudu 控制台中使用 .\scriptname.ps1 启动脚本时出现,当我在 Kudu 控制台复制粘贴中执行代码时,它似乎工作正常。 ..
在我看来,这似乎只是 azure 工作系统中的一个固有缺陷,它只会解释 litteral 类型,而不能像在客户端上那样运行。
【问题讨论】:
-
您还有其他顾虑吗?如果您没有其他顾虑,您能接受答案吗?它可能会帮助更多有类似问题的人。