简体   繁体   English

如何访问架构远程Powershell?

[英]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.

相关问题 如何在整个程序中维护Powershell远程会话? - How can maintain the powershell remote session throughout the program? 使用PowerShell和WinRM访问远程计算机上的GUI - Access to GUI on remote machine using PowerShell and WinRM 如何在C#中修改Access DB的架构 - How can I modify the schema for an Access DB in C# 使用HotChocolate拼接时,如何重命名远程模式的类型? - When Stitching using HotChocolate, How Can A Remote Schema's Type Be Renamed? 如何在远程访问中显示自定义错误页面? - How can I show the custom error page on remote access? 如何在C#中访问PowerShell标准错误输出? - How can I access PowerShell standard error output in C#? 如何使用C#和Powershell类远程到ActiveDirectory Server - How I can remote to my ActiveDirectory Server with C# and Powershell Class 如何创建可由客户端调用的“远程Powershell”服务器对象? - How do I create a “Remote Powershell” server object that can be called by clients? 从PowerShell或C#使用WMI-如何获得远程主机时间(包括毫秒)? - Using WMI from PowerShell or C# - how can I get remote host time, including milliseconds? 使用PowerShell在远程计算机上启动监视应用程序时的性能计数器访问 - Performance counter access when launching monitoring app on remote machine with PowerShell
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM