Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用C在Powershell脚本中将Windows凭据作为PSCredential传递#_C#_Wcf_Powershell_Iis - Fatal编程技术网

C# 使用C在Powershell脚本中将Windows凭据作为PSCredential传递#

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.

我有一个WCF服务,它执行远程powershell脚本并将结果返回给客户端。但当这个WCF托管在IIS上时,我在调用行中得到以下错误

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”);