Advertisement
Guest User

Untitled

a guest
Apr 20th, 2017
628
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. set-adserverstettings -viewentireforrest:$true
  2. get-mailbox Administrator | fl
  3.  
  4. Name,Alias,ServerName,ProhibitSendQuota
  5. Administrator,admin,ex01,unlimited
  6.  
  7. var command = new Command("get-mailbox");
  8. command.Parameters.Add("Identity", "Administrator");
  9. pipeline.Commands.AddScript("Set-ADServerSettings -ViewEntireForest:$true");
  10. pipeline.Commands.Add(command);
  11.  
  12. Nothing/EMPTY/NULL
  13.  
  14. pipeline.Commands.AddScript("Get-Mailbox -identity Administrator");
  15.  
  16. Administrator (Global Admin Account)
  17.  
  18. string runasUsername = "admin@abc.at";
  19. string runasPassword = "MyPassword";
  20.  
  21. System.Security.SecureString ssRunasPassword = new System.Security.SecureString();
  22.  
  23. foreach (char x in runasPassword)
  24. ssRunasPassword.AppendChar(x);
  25.  
  26. PSCredential credentials = new PSCredential(runasUsername, ssRunasPassword);
  27. var connInfo = new WSManConnectionInfo(new Uri("http://ex01.abc.at/PowerShell"), "http://schemas.microsoft.com/powershell/Microsoft.Exchange", credentials);
  28. connInfo.AuthenticationMechanism = AuthenticationMechanism.Kerberos;
  29.  
  30. var runspace = RunspaceFactory.CreateRunspace(connInfo);
  31.  
  32. string script = @"Set-ADServerSettings -ViewEntireForest:$true
  33. get-mailbox Administrator | format-table";
  34.  
  35. runspace.Open();
  36. var pipeline = runspace.CreatePipeline();
  37.  
  38. pipeline.Commands.AddScript(script);
  39. Collection<PSObject> resultss = pipeline.Invoke();
  40. string str = "";
  41.  
  42. foreach (PSObject psObject in resultss)
  43. {
  44. str = str + psObject;
  45. }
  46.  
  47. runspace.Dispose();
  48. Label1.Text = str;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement