【问题标题】:-ConnectionUri parameter error with Remote Session trying to pass message to computer on network-ConnectionUri 参数错误,远程会话尝试将消息传递到网络上的计算机
【发布时间】:2019-08-19 13:06:13
【问题描述】:

我目前正在尝试使用 asp.net 和 C# 制作一个基于 IIS 的应用程序,以作为通知系统,通知有人来我们前台找人,这样我们就不必去追他们了。我不断收到错误消息,显示“一个或多个计算机名称无效。如果您尝试传递 URI,请使用 -ConnectionUri 参数,或在 Visual Studio 的调试器中传递 URI 对象而不是字符串”。

我尝试使用凭据,认为这是远程问题的权限,我尝试将其设置为 var,如下所示。我尝试了一个 string.format 也认为它可能不喜欢这种类型。

ComputerName 的变量只是为计算机提供的基本计算机名称,而不是接下来要尝试的完整计算机名称。

var ComputerName = c.Attribute("CN");

InitialSessionState initial = InitialSessionState.CreateDefault();
Runspace runspace = RunspaceFactory.CreateRunspace(initial);
runspace.Open();
PowerShell ps = PowerShell.Create();
ps.Runspace = runspace;
ps.AddCommand("invoke-command"); 
ps.AddParameter("ComputerName", ComputerName);
ScriptBlock calldown = ScriptBlock.Create("Get-childitem C:\\windows");
ps.AddParameter("ScriptBlock", calldown);

foreach (PSObject obj in ps.Invoke()){
string message = string.Format("You currently have a client waiting for you at the front desk, please check the lobby system to find out more");
string title = string.Format ("Lobby Alert");

MessageBox.Show(message, title);
}

结果应该是后面的计算机上的一个消息框,而不是用户“前台”计算机。

【问题讨论】:

  • 感谢您在此处提及输入代码,伙计们的错误,它拒绝在不知道为什么的情况下遮蔽框。
  • 感谢 James 帮助编辑此处问题的输入代码

标签: c# asp.net .net powershell cmdlet


【解决方案1】:

通过使用值对象解决了这个问题,因为它注册为类型字符串以通过此错误现在有一个不同的问题,但这与 Powershell 无关,因此我在 C# 部分针对该错误发布了一个更准确的问题我我有。

var ComputerName = c.Attribute("CN");

InitialSessionState initial = InitialSessionState.CreateDefault();
Runspace runspace = RunspaceFactory.CreateRunspace(initial);
runspace.Open();
PowerShell ps = PowerShell.Create();
ps.Runspace = runspace;
ps.AddCommand("invoke-command"); 
ps.AddParameter("ComputerName", ComputerName.Value);
ScriptBlock calldown = ScriptBlock.Create("Get-childitem C:\\windows");
ps.AddParameter("ScriptBlock", calldown);

foreach (PSObject obj in ps.Invoke()){
string message = string.Format("You currently have a client waiting for you at the 
front desk, please check the lobby system to find out more");
string title = string.Format ("Lobby Alert");

MessageBox.Show(message, title);}

【讨论】:

    猜你喜欢
    • 2022-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-31
    • 2015-04-03
    相关资源
    最近更新 更多