?
Solved

Problems running powershell script

Posted on 2012-08-15
10
Medium Priority
?
1,017 Views
Last Modified: 2013-12-04
I am trying to run a powershell script from .Net framework 4.0 and I am getting this error.  I have checked and made sure that there are no firewalls and I need another solution.  Any help you can give me would be great!

Connecting to remote server failed with the following error message : The WinRM client cannot process the request. If the authentication scheme is different from Kerberos, or if the client computer is not joined to a domain, then HTTPS transport must be used or the destination machine must be added to the TrustedHosts configuration setting. Use winrm.cmd to configure TrustedHosts. Note that computers in the TrustedHosts list might not be authenticated. You can get more information about that by running the following command: winrm help config. For more information, see the about_Remote_Troubleshooting Help topic.
0
Comment
Question by:dillonconsulting
10 Comments
 
LVL 13

Expert Comment

by:Xaelian
ID: 38298262
Can you attach the Powershell script so we can modify it to run perfectly?
0
 
LVL 3

Expert Comment

by:Akulsh
ID: 38298287
Use this tool c:\windows\system32\sconfig  to enable remote management.

See this article for more details:
http://blogs.msdn.com/b/virtual_pc_guy/archive/2010/11/11/configuring-remote-management-of-hyper-v-server-in-a-workgroup.aspx
0
 
LVL 71

Expert Comment

by:Qlemo
ID: 38298553
That message is caused by a missing or wrong WinRM configuration (as hinted in the error message). WinRM is used for executing PowerShell commands (a) remotely or (b) locally as a background task (with Start-Job).

In most cases it is sufficient to run   winrm quickconfig   on the machine the script is targeted at. But there are some steps more to take if you are not using the same domain (or a domain at all).

Showing us the script (or the relevant part of it) will help us to help you.
0
Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

 

Author Comment

by:dillonconsulting
ID: 38301166
Here is the script
New-Mailbox -Name "777777" -UserPrincipalName "777777@ourdomain.com" -database "database" -Org "ou=Email Accounts,DC=ourdomain,DC=com" -Password (ConvertTo-SecureString "sup123" -AsPlainText -Force) -RetentionPolicy "ArcMail Retention Policy"
0
 
LVL 71

Expert Comment

by:Qlemo
ID: 38301481
Did you try that on a client or on a server with an Exchange role? If the former, try on a server, and if that works we can work out a way for you to execute it on a client.
0
 

Author Comment

by:dillonconsulting
ID: 38301870
It is on a server here is the code that runs the script

    Public Shared Function RunScriptRemote(ByVal scriptText As String) As String
        Try
                  'Powershell script as following
                  'New-Mailbox -Name "123457" -UserPrincipalName  "123457@xxxx.ca" -database xxxxx -OrganizationalUnit "ou=xxxxx,DC=xxxx,DC=ca" -Password (ConvertTo-SecureString "sup123" -AsPlainText -Force) -RetentionPolicy "ArcMail Retention Policy"
           
                  Dim runasUsername As String = "xxxxxxxx"
            Dim runasPassword As String = "xxxxxxxx"

            Dim ssRunasPassword As SecureString = New SecureString
            For Each a As Char In runasPassword
                ssRunasPassword.AppendChar(a)
            Next
            Dim credentials As PSCredential = New PSCredential(runasUsername, ssRunasPassword)

            Dim Conninfo = New WSManConnectionInfo(New Uri("http://xxxxx.xxxxx.ca/PowerShell/?serializationLevel=Full"), "http://schemas.microsoft.com/powershell/Microsoft.Exchange", credentials)

            Conninfo.AuthenticationMechanism = AuthenticationMechanism.Basic
            '' create Powershell runspace
            Dim myRunSpace As Runspace
            myRunSpace = RunspaceFactory.CreateRunspace(Conninfo)

            Dim powershell As PowerShell
            powershell = powershell.Create()

            Dim command As PSCommand = New PSCommand

            command.AddCommand("get-mailbox")
            powershell.Commands = command
            powershell.Commands.AddScript(scriptText)
            ' open it
            myRunSpace.Open()

            powershell.Runspace = myRunSpace
            Dim results As Collection(Of PSObject) = powershell.Invoke()

            ' close the runspace
            myRunSpace.Close()

            myRunSpace.Dispose()

            ' convert the script result into a single string
            Dim MyStringBuilder As New StringBuilder()

            For Each obj As PSObject In results
                MyStringBuilder.AppendLine(obj.ToString())
            Next

            ' return the results of the script that has
            ' now been converted to text
            Return MyStringBuilder.ToString()
        Catch ex As Exception
            Return ex.Message.ToString
        End Try

    End Function
0
 
LVL 71

Expert Comment

by:Qlemo
ID: 38302102
The issue might be that you change the user context, and then try to execute the PS script. The standard authentication mechanisms allowed when using remote commands are very restricted.

Does it work if you execute that on in an interactive PS session?
0
 

Author Comment

by:dillonconsulting
ID: 38306217
Yes. It is working in an interactive PS session.

I did some configuration on Winrm services today. I run the script again. Now I got an error like "Connecting to remote server failed with the following error message : Access is denied. For more information, see the about_Remote_Troubleshooting Help topic. "

Do you know what kind of rights that user can create the emailbox in exchange server?

Thanks
0
 
LVL 71

Accepted Solution

by:
Qlemo earned 2000 total points
ID: 38306681
It's more about Remoting rights and config than Exchange privileges. Read the recommended help page (get-help about_Remoting_Troubleshooting), it explains the requirements for successful user authentication when using WinRM.
0
 

Author Closing Comment

by:dillonconsulting
ID: 38441358
We adjusted the Remoting rights and it is working now
0

Featured Post

NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

Question has a verified solution.

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

In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
In the absence of a fully-fledged GPO Management product like AGPM, the script in this article will provide you with a simple way to watch the domain (or a select OU) for GPOs changes and automatically take backups when policies are added, removed o…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…

839 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