Solved

Enable-Mailbox Not Recognised

Posted on 2010-09-17
7
3,904 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
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.

 
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

Free eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

Question has a verified solution.

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

Suggested Solutions

My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
In this video we show how to create a Contact 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 Recipients >> Contact ta…
In this Micro Video tutorial you will learn the basics about Database Availability Groups and How to configure one using a live Exchange Server Environment. The video tutorial explains the basics of the Exchange server Database Availability grou…

732 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