C# 使用C在Powershell脚本中将Windows凭据作为PSCredential传递#
我有一个WCF服务,它执行远程powershell脚本并将结果返回给客户端。但当这个WCF托管在IIS上时,我在调用行中得到以下错误C# 使用C在Powershell脚本中将Windows凭据作为PSCredential传递#,c#,wcf,powershell,iis,C#,Wcf,Powershell,Iis,我有一个WCF服务,它执行远程powershell脚本并将结果返回给客户端。但当这个WCF托管在IIS上时,我在调用行中得到以下错误 using (var powershell = PowerShell.Create()) { var command = new PSCommand(); command.AddCommand("New-PSSession"); command.
using (var powershell = PowerShell.Create())
{
var command = new PSCommand();
command.AddCommand("New-PSSession");
command.AddParameter("ConfigurationName", "Microsoft.Exchange");
command.AddParameter("ConnectionUri", connectTo);
command.AddParameter("Authentication", "Kerberos");
powershell.Commands = command;
powershell.Runspace = runspace;
var result = powershell.Invoke();//Error
psSessionConnection = result[0];
}
处理来自远程服务器的数据#EXCHANGESERVERNAME#失败,并显示以下错误消息:[AuthZRequestId=ac0dedbe-a345-4eac-bb8d-cd5b8eab327c][FailureCategory=AuthZ CmdletAccessDeniedException]未将用户#MACHINENAME#分配给任何管理角色
我怎么排这条线
AddParameter(“身份验证”、“Kerberos”)
传递用户凭据?哪个帐户正在运行承载服务的应用程序池?根据错误消息,我的第一个猜测是该帐户没有适当的权限(但我不熟悉PowerShell)。如果您没有使用本地域身份验证
Kerberos
,则可能无法工作,您可以使用Basic
,还需要添加凭据对象,如:command.AddParameter(“Credential”,yourcredentialobject);
@Tim WCF正在使用ApplicationPoolIdentity的默认池下运行。@Avshalom Adding command.AddParameter(“Credential”,yourcredentialobject);起作用,但这不是目的。我不想硬编码凭据。只有特定的AD组才能访问此WCF,并且可以在command.AddParameter(“身份验证”、“Kerberos”)中传递其凭据;哪个帐户正在运行承载服务的应用程序池?根据错误消息,我的第一个猜测是该帐户没有适当的权限(但我不熟悉PowerShell)。如果您没有使用本地域身份验证Kerberos
可能无法工作,您可以使用Basic
,还需要添加凭据对象,如:command.AddParameter(“凭据”,您的凭据对象);
@Tim WCF正在使用ApplicationPoolIdentity的默认池下运行。@Avshalom Adding命令。AddParameter(“Credential”,yourcredentialobject);起作用,但不是目的。我不想硬编码凭据。只有特定的AD组才能访问此WCF,并且可以在命令中传递其凭据。AddParameter(“身份验证(“Kerberos”);