-远程会话尝试将消息传递到网络上的计算机时出现 ConnectionUri 参数错误

-ConnectionUri parameter error with Remote Session trying to pass message to computer on network

我目前正在尝试使用 asp.net 和 C# 制作一个基于 IIS 的应用程序,作为一个通知系统,告知有人来我们前台会见某人,这样我们就不必去追他们了吃下。我不断收到 visual studio.

调试器中的 "One or more computer names are not valid. If you are trying to pass a URI, use the -ConnectionUri parameter, or pass URI objects instead of strings" 错误

我曾尝试使用凭据,认为这是对远程问题的许可,我已尝试将其设为 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);
}

结果应该是后面一台不是用户 "frontdesk" 计算机的计算机上的消息框。

通过使用值对象来解决它,因为它注册为类型字符串以通过此错误现在有一个不同的问题,但这与 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);}