[英]how can access to schema remote powershell?
I have a C# code for accessing remote PowerShell and got this error after running: access in denied. 我有一个用于访问远程PowerShell的C#代码,运行后出现此错误:拒绝访问。 the code is :
代码是:
string shell = "http://schemas.microsoft.com/powershell/Microsoft.PowerShell";
var target = new Uri("http://Computername/wsman");
Pipeline p = runSpace.CreatePipeline();
SecureString passing = new SecureString();
string password = "pass";
foreach (char c in password)
{
passing.AppendChar(c);
}
passing.MakeReadOnly();
var cred = new PSCredential(@"Domain\User", passing);
var connectionInfo = new WSManConnectionInfo(target, shell, cred); runSpace = RunspaceFactory.CreateRunspace(connectionInfo);
runSpace.Open();
this error is occurred because I can not access to this address: http://schemas.microsoft.com/powershell/Microsoft.PowerShell 发生此错误,因为我无法访问此地址: http : //schemas.microsoft.com/powershell/Microsoft.PowerShell
after enter this address for connecting to it , show this message: An error occurred while processing your request. 输入用于连接的地址后,显示以下消息:处理您的请求时出错。
Is there another address for schema or another way to write this code? 是否有用于模式的其他地址或用于编写此代码的其他方式?
please help me. 请帮我。 thanks,
谢谢,
First, try to access the remote machine from PowerShell first. 首先,尝试首先从PowerShell访问远程计算机。 It will be easier to debug the connection problem there IMO (instead of C#).
在IMO(而不是C#)中调试连接问题会更加容易。 Can you connect with the following command (from a 64-bit console):
你可以用下面的命令(从64位控制台)连接:
$config = 'Microsoft.PowerShell'
$connuri = 'http://Computername:5985/wsman'
$s = New-PSSession -ConnectionUri $connuri -ConfigurationName $config -Credential (Get-Credential)
Invoke-Command -Session $s -ScriptBlock {Get-PSSessionConfiguration} | Format-List *
If that works then perhaps you're just missing the port number or there's a coding issue in your C#. 如果可行,则可能是您只是缺少端口号,或者C#中存在编码问题。 However that would at least rule out a PowerShell configuration issue (which I suspect).
但是,这至少可以排除PowerShell配置问题(我怀疑)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.