Upon receiving this, the module must be imported in its full path, and for the execution policy for the 64-bit command line and 32-bit command line, you must set the value to "Unlimited" (or something else, except limited depending on your case) , Here is the code:
static void Main(string[] args) { InitialSessionState initial = InitialSessionState.CreateDefault(); initial.ImportPSModule(new string[] {"C:\\Program Files\\Common Files\\Microsoft Lync Server 2010\\Modules\\Lync\\Lync.psd1"} ); Runspace runspace = RunspaceFactory.CreateRunspace(initial); runspace.Open(); PowerShell ps = PowerShell.Create(); ps.Runspace = runspace; ps.Commands.AddCommand("Get-csuser"); foreach (PSObject result in ps.Invoke()) { Console.WriteLine(result.Members["Identity"].Value); } }
source share