I'm working on a program that needs to connect to a lync trusted app pool and execute a variety of tasks. This is the installer, where I'm setting up the pool, the app, and basically getting all my ducks in a row.

I'm able to create the app pool with the code below:

        var cmd = string.Format("new-csTrustedApplicationPool -Identity {0} -Registrar {1} -Site {2} -ComputerFqdn {3}", txtPoolIdentity.Text, registrar, site, localhost);

        try
        {
            _ps.Commands.Clear();
            _ps.AddScript(cmd);
            _ps.Invoke();

            if (_ps.Streams.Error.Any())
            {
                foreach (var errorRecord in _ps.Streams.Error)
                {
                    MessageBox.Show(errorRecord.ToString());
                }
            }
            else
            {
                MessageBox.Show(string.Format("Trusted Application Pool {0} created", txtPoolIdentity.Text));
            }
        }
        catch (Exception ex)
        {
           //Handling code
        }

As I said, that works fine. However, when I try to execute the following code, the process fails with an 'invalid argument' error.

try
        {
            _ps.Commands.Clear();
            _ps.AddScript("enable-CSTopology");
            _ps.Invoke();
            if (_ps.Streams.Error.Any())
            {
                foreach (var errorRecord in _ps.Streams.Error)
                {
                    MessageBox.Show(errorRecord.ToString());
                }
            }
        }
        catch (Exception ex)
        {
             //handling code
        }

Except "enable-CsTopology" takes no arguments. I've googled around, but I'm not getting any traction here. Any help is appreciated!

有帮助吗?

解决方案

Feeling intensely stupid, I later discovered that the PS object wasn't running with elevated privileges, which caused the topology change to fail. Using the powershell command found here solved the issue for me.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top