'Set-AzureWebsite'无法识别为cmdlet的名称,

我试图在我的azurewebsite上运行以下powershell cmdlet

public string RunPowerShellScript()
    {

        try
        {
            RunspaceConfiguration runspaceConfiguration = RunspaceConfiguration.Create();
            Runspace runspace = RunspaceFactory.CreateRunspace(runspaceConfiguration);
            runspace.Open();
            RunspaceInvoke scriptInvoker = new RunspaceInvoke(runspace);
            Pipeline pipeline = runspace.CreatePipeline();
            //Here's how you add a new script with arguments            
            Command myCommand = new Command("Set-AzureWebsite");
            myCommand.Parameters.Add("Name", "rmssimple");
            myCommand.Parameters.Add("HostNames ", "@('test.posxyz.com', 'xyz.com')");

            pipeline.Commands.Add(myCommand);
            var results = pipeline.Invoke();

            return Content(results[0].ToString());
        }
        catch (Exception ex)
        {
            return Content(ex.Message);
        }


    }

但我得到了吼叫错误

“Set-AzureWebsite”一词不被识别为cmdlet,函数,脚本文件或可操作程序的名称 . 检查名称的拼写,或者如果包含路径,请验证路径是否正确,然后重试 .

回答(1)

3 years ago

第一个问题:你为什么要这样做呢?第二,如果你想这样做,你需要先导入模块,然后需要安装Powershell工具 . 导入模块如下所示:PoSh:import-module Azure