none
Call Powershell Commands from VB.Net Syntax RRS feed

  • Question

  • Using VB.NET, I have created a runspace and executed the Powershell commands to enable a mailbox on Exchange 2010, which is working fine.  I now need to add a secondary SMTP address, but can't figure out the syntax.  Anyone?

    Thanks

    Working Powershell command:
    Set-Mailbox -Identity DomainName\UserName -EmailAddresses @{add='98765432@Domain.com'}

    #THIS CODE NOT WORKING
            Dim pCommand As PSCommand = New PSCommand
            pCommand.AddCommand("Set-mailbox")
            pCommand.AddParameter("identity", "DomainName\UserName")
            pCommand.AddParameter("EmailAddresses", "@{add='98765432@Domain.com'}")
            pShell.Commands = pCommand
            Dim pResult2 As Collection(Of PSObject) = pShell.Invoke

    Error Message:
    System.Management.Automation.RemoteException was unhandled
      Message=The term 'Set-MailBox -Identity DomainName\UserName -EmailAddresses @{add='98765432@Domain.com'}' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
    • Edited by SCHAIN Thursday, May 23, 2013 1:46 AM
    Wednesday, May 22, 2013 3:10 AM