Solved

Enable-Mailbox Not Recognised

Posted on 2010-09-17
7
3,490 Views
Last Modified: 2012-08-14
Hi All,

Im trying to run the command "Enable-Mailbox" remotely and im getting this error

"The term 'Enable-Mailbox' 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"

i remember something about permissions, i just cant remember what it was

Heres my code

    Shared Function EnableMailbox(ByVal username As String, ByVal aliasname As String) As String
        Dim schema1 = "http://schemas.microsoft.com/powershell/Microsoft.Exchange"
        Dim LivePath = AppSettings("ExLiveUri")

        Dim pw As New SecureString
        For Each c As Char In AppSettings("SystemPass")
            pw.AppendChar(c)
        Next

        Dim cred As New PSCredential(AppSettings("SystemUser"), pw)

        Dim wsman As New WSManConnectionInfo(New Uri(LivePath), schema1, cred)
        wsman.AuthenticationMechanism = AuthenticationMechanism.Default
        Dim RS = RunspaceFactory.CreateRunspace(wsman)
        Dim PS = PowerShell.Create()
        Dim CMD As New PSCommand

        CMD.AddCommand("Enable-Mailbox")
        CMD.AddParameter("Identity", username)
        CMD.AddParameter("Alias", aliasname)
        CMD.AddParameter("Database", "MDB1")

        PS.Commands = CMD
        Dim resp As String = ""
        Try
            RS.Open()
            Dim i = PS.Invoke()
            For Each ob As PSObject In i
                Dim nm = ob.BaseObject.ToString
                resp &= nm & "<br>"
            Next
            RS.Close()
            RS.Dispose()
            Return resp
        Catch ex As Exception
            Return ex.Message
        End Try

    End Function


0
Comment
Question by:Chrissalter
  • 3
  • 3
7 Comments
 
LVL 14

Expert Comment

by:Shabarinath Ramadasan
ID: 33699611
Do you have exchange shell installed on the computer where you are running the code?

Good luck
Shaba
0
 
LVL 7

Author Comment

by:Chrissalter
ID: 33699632
no,

the code is being run on one server (our web server) and exchange is on the other (exchange server)

its as though its not loading the exchange snapin

0
 
LVL 14

Expert Comment

by:Shabarinath Ramadasan
ID: 33699644
I feel that the computer you are running this command couldn't recognize the cmdlet. enable-mailbox is a part for exchange commandlets which comes in after installing the exchange management tools.

Good luck
Shaba
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 14

Expert Comment

by:Shabarinath Ramadasan
ID: 33699654
You need to run the setup for exchange and just select the Exchange management tools.
That will get this fixed.

Good luck
Shaba
0
 
LVL 7

Author Comment

by:Chrissalter
ID: 33699657
confirmed,

the exchange snapin is not being loaded

How do i load a snapin using wsman?

0
 
LVL 7

Author Comment

by:Chrissalter
ID: 33699662
but im not running the command on the web server im using wsman to run it on the exchange server
0
 
LVL 28

Accepted Solution

by:
sunnyc7 earned 500 total points
ID: 33699891
From your powershell window
run this

winrm quickconfig
http://scorpiotek.com/blog/?p=770

then establish a PSSession first before you start running other commands
http://technet.microsoft.com/en-us/library/dd819505.aspx
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Utilizing an array to gracefully append to a list of EmailAddresses
This article will help you understand what HashTables are and how to use them in PowerShell.
In this video we show how to create a mailbox database in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Servers >> Data…
To show how to create a transport rule in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Mail Flow >> Rules tab.:  To cr…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now