Public LiveUri As String = "http://***********/Powershell?serializationLevel=Full"
Sub InitWsMan()
Dim AdminPassSecure = New SecureString
For Each c As Char In AdminPass
AdminPassSecure.AppendChar(c)
Next
Dim cred = New PSCredential(AdminUser, AdminPassSecure)
WS = New WSManConnectionInfo(New Uri(LiveUri), "http://schemas.microsoft.com/powershell/Microsoft.Exchange", cred)
WS.AuthenticationMechanism = AuthenticationMechanism.Default
RS = RunspaceFactory.CreateRunspace(WS)
PS = PowerShell.Create
ServicePointManager.ServerCertificateValidationCallback = New Security.RemoteCertificateValidationCallback(AddressOf SSlOk)
End Sub
Sub EnableMailbox(ByVal Username As String, ByVal [Alias] As String)
Dim cmd = New PSCommand
cmd.AddCommand("Enable-Mailbox")
cmd.AddParameter("Identity", Username)
cmd.AddParameter("Alias", [Alias])
PS.Commands = cmd
PS.Runspace = RS
Try
RS.Open()
Dim i = PS.Invoke
RS.Close()
Catch ex As Remoting.PSRemotingTransportException
End Try
End Sub
|