Solved

Enable-Mailbox Not Recognised

Posted on 2010-09-17
7
3,578 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Marketers need statistics and metrics like everybody else needs oxygen. In this article we explain how to enable marketing campaign statistics for Microsoft Exchange mail.
A brief introduction to what I consider to be the best editor for PowerShell.
To show how to generate a certificate request 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 >> Certificates…
The basic steps you have just learned will be implemented in this video. The basic steps are shown to configure an Exchange DAG in a live working Exchange Server Environment and manage the same (Exchange Server 2010 Software is used in a Windows Ser…

912 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

27 Experts available now in Live!

Get 1:1 Help Now