我正在尝试从c#运行一个power外壳脚本。仅当运行power shell脚本时,它才能成功运行。但是,当尝试从c#运行相同的脚本时。我收到错误消息"The term 'New-CsOnlineSession‘is not recognized as the name of a cmdlet“
代码如下:
public static void GetLyncUsers(string userName, string password)
{
using (PowerShell powerShellInstance = P
我有下面的powershell脚本文件
C:\user\桌面\script1.ps1
脚本的内容如下:
get-process
我正在尝试创建一个C#控制台应用程序,以便在控制台上获得这个脚本的输出。当我在C#之外执行脚本时,它运行得很好,但是当我在C#中执行它时,它不会产生任何结果。我正在尝试使用addscript并调用。
C#代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.M
我正在尝试从Add-AppxPackage调用C# cmdlet。我在上找到了MSDN的文章。我引用了System.Management.Automation程序集并尝试了以下代码片段,所有这些代码段在尝试调用powerShell.Invoke()时都会产生相同的异常:
System.Management.Automation.CommandNotFoundException未被处理
术语“AppxPackage”不被识别为cmdlet、函数、脚本文件或可操作程序的名称。检查名称的拼写,或者如果包含路径,请验证路径是否正确,然后再试一次。
片段1:
var powerShell = P
我尝试在C#中运行PowerShell脚本。但是它抛出了错误:
PowerShell doesn't available in current context.
我在谷歌上搜索,但没有得到解决方案,请帮助。这是我的代码:
string text = System.IO.File.ReadAllText(@"C:\Program Files (x86)\Backup Reporter\Required\edit_website.ps1");
using (PowerShell PowerShellInstance = PowerShell.Create())
{
C#9中Powershell对象的问题
我正在尝试使用C#对象检索system.management.powershell中的物理磁盘。当我尝试使用cmdlet“Get-Process”时,powershell对象将正确检索所有进程。
using (PowerShell PowerShellInstance = PowerShell.Create())
{
// this works
//PowerShellInstance.AddCommand("Get-Process");
PowerShellInstance.A
我有一个包含多个函数的powershell脚本文件。我想使用C#调用其中一个函数。当我调用命令时,它会抛出一个错误。
"The term 'LogIn-System' is not recognized as the name of a cmdlet,
function, script file, or operable program. Check the spelling of the name,
or if a path was included, verify that the path is correct and try again."