Advertisement
Guest User

Untitled

a guest
Apr 20th, 2017
576
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. string runasUsername = "admin@abc.at";
  2. string runasPassword = "MyPassword";
  3. System.Security.SecureString ssRunasPassword = new
  4. System.Security.SecureString();
  5. foreach (char x in runasPassword)
  6. ssRunasPassword.AppendChar(x);
  7. PSCredential credentials = new PSCredential(runasUsername, ssRunasPassword);
  8. var connInfo = new WSManConnectionInfo(new
  9. Uri("http://ex01.abc.at/PowerShell"),
  10. "http://schemas.microsoft.com/powershell/Microsoft.Exchange", credentials);
  11. connInfo.AuthenticationMechanism = AuthenticationMechanism.Kerberos;
  12.  
  13. var runspace = RunspaceFactory.CreateRunspace(connInfo);
  14.  
  15. string script = @"Set-ADServerSettings -ViewEntireForest:$true
  16. get-mailbox Administrator | format-table";
  17.  
  18. runspace.Open();
  19. var pipeline = runspace.CreatePipeline();
  20.  
  21. pipeline.Commands.AddScript(script);
  22. Collection<PSObject> resultss = pipeline.Invoke();
  23. string str = "";
  24.  
  25. foreach (PSObject psObject in resultss)
  26. {
  27. str = str + psObject;
  28. }
  29. runspace.Dispose();
  30. Label1.Text=str;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement