none
PowerShell remote call. Access is denied from webserver RRS feed

  • Question

  • i write a code for remote access for exchange powershell from asp.net application to enable remote mail using vb.net and exchange 2016
    the command run successfully from my visual studio debug
    but when i put in iis web server it's giving me
    Access is denied 

    this is is the code 

       
        Function enableRemoteEmail(ByVal samaccount As String, ByVal email As String) As String
            Dim ServerUri As String = "http://{mailserver}/powershell" 'use one of CAS servers H$$C4info
            Dim SchemaUri As String = "http://schemas.microsoft.com/powershell/Microsoft.Exchange"
            Dim userName As String = AccountOperatorLogon 
            Dim password As New System.Security.SecureString
            For Each x As Char In AccountOperatorPassword
                password.AppendChar(x)
            Next
    
            Dim PSCredential As New PSCredential(userName, password)
            Dim ConnectionInfo As WSManConnectionInfo = New WSManConnectionInfo(New Uri(ServerUri), SchemaUri, PSCredential)
            ConnectionInfo.AuthenticationMechanism = AuthenticationMechanism.Basic
            Dim RemoteRunspace As Runspace = RunspaceFactory.CreateRunspace(ConnectionInfo)
            Dim RemotePowerShell As PowerShell = PowerShell.Create
            RemotePowerShell.AddCommand("Enable-RemoteMailbox")
            RemotePowerShell.AddParameter("Identity", samaccount)
            RemotePowerShell.AddParameter("RemoteRoutingAddress",email )
            RemotePowerShell.AddParameter("Credential", PSCredential)
    
            ' Open the remote runspace on the server.
            RemoteRunspace.Open()
            ' Associate the runspace with the Exchange Management Shell.
            RemotePowerShell.Runspace = RemoteRunspace
            Dim TheResult As Collection(Of PSObject)
            Dim TheResultString As String = ""
            TheResult = RemotePowerShell.Invoke
            For Each RSLT As PSObject In TheResult
                TheResultString += RSLT.ToString() + "<br/>"
            Next
            RemoteRunspace.Close()
            ' Invoke the Exchange Management Shell to run the command.
            Return TheResultString
        End Function
    


    Wednesday, May 24, 2017 4:47 PM

All replies

  • Hi HSC-TSA,

    Since this forum is discussing and asking questions about the Visual Basic programming language, IDE, libraries, samples, and tools, and your issue is more related to asp.net.

    This link about asp.net, please refer that: https://forums.asp.net/

    Thank you for participating in the forum activities.

    Best Regards,

    Cherry



    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, May 26, 2017 5:14 AM
    Moderator
  • i write a code for remote access for exchange powershell from asp.net application to enable remote mail using vb.net and exchange 2016
    the command run successfully from my visual studio debug
    but when i put in iis web server it's giving me
    Access is denied 



    That is probably what should happen. You don't want an instance of IIS to be able to hop across the network to another server and execute a powershell command. That's how hackers take over networks. :P

    If this webserver is an internal resource to your network and has no outside/public visibility then you may be able to weaken the web server security so that the two machines can talk as required.  But you should ONLY do this if the webserver is 100% in-house and ALL users of the webserver are "trusted" users.


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Friday, May 26, 2017 2:08 PM
    Moderator