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?


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

            Dim pCommand As PSCommand = New PSCommand
            pCommand.AddParameter("identity", "DomainName\UserName")
            pCommand.AddParameter("EmailAddresses", "@{add=''}")
            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=''}' 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