SecureString password = new SecureString(); string str_password = "123"; string username = "xyz"; string liveIdconnectionUri = "http://exchange.abc.com/Powershell?serializationLevel=Full"; foreach (char x in str_password) { password.AppendChar(x); } PSCredential credential = new PSCredential(username, password); WSManConnectionInfo connectionInfo = new WSManConnectionInfo((new Uri(liveIdconnectionUri)), "http://schemas.microsoft.com/powershell/Microsoft.Exchange", credential); connectionInfo.AuthenticationMechanism = AuthenticationMechanism.Default; Runspace runspace = System.Management.Automation.Runspaces.RunspaceFactory.CreateRunspace(connectionInfo); PowerShell powershell = PowerShell.Create(); PSCommand command = new PSCommand(); command.AddCommand("Enable-Mailbox"); command.AddParameter("Identity", "Peter England"); command.AddParameter("Alias", "peter.england"); command.AddParameter("Database", "MBX_SBG_01"); powershell.Commands = command; try { runspace.Open(); powershell.Runspace = runspace; powershell.Invoke(); } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { runspace.Dispose(); runspace = null; powershell.Dispose(); powershell = null; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)