Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- string runasUsername = "admin@abc.at";
- string runasPassword = "MyPassword";
- System.Security.SecureString ssRunasPassword = new
- System.Security.SecureString();
- foreach (char x in runasPassword)
- ssRunasPassword.AppendChar(x);
- PSCredential credentials = new PSCredential(runasUsername, ssRunasPassword);
- var connInfo = new WSManConnectionInfo(new
- Uri("http://ex01.abc.at/PowerShell"),
- "http://schemas.microsoft.com/powershell/Microsoft.Exchange", credentials);
- connInfo.AuthenticationMechanism = AuthenticationMechanism.Kerberos;
- var runspace = RunspaceFactory.CreateRunspace(connInfo);
- string script = @"Set-ADServerSettings -ViewEntireForest:$true
- get-mailbox Administrator | format-table";
- runspace.Open();
- var pipeline = runspace.CreatePipeline();
- pipeline.Commands.AddScript(script);
- Collection<PSObject> resultss = pipeline.Invoke();
- string str = "";
- foreach (PSObject psObject in resultss)
- {
- str = str + psObject;
- }
- runspace.Dispose();
- Label1.Text=str;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement