"Enable-PSRemoting –force" commnad fails

rated by 0 users
This post has 30 Replies | 3 Followers

Top 50 Contributor
Posts 35

Hi,

 

Please I need an explaination how to do that.

As you know tempDC1 belongs to a WORKGROUP, but the Hyperv host belongs to a known domain, so, there is no ping between the Hyperv Host and the tempDC1 VM (According the requirements, I can't join tempDC1 VM to that domain).

Regards,

Bader

Top 10 Contributor
Posts 326
Microsoft MVP
Top Contributor

You need some way of resolving the name tempdc1 to an ip address in order for the commands you showed to to work. The error message made it clear.

If you can't get tempdc1's ip address into DNS, then you could always use the HOSTS file. If your workstation and tempdc1 are on the same 'network', then netbios resolution should work...

What IP address does TempDC1 have? You could always just use the ipv4 address.

 

Top 10 Contributor
Posts 326
Microsoft MVP
Top Contributor

Looking more at this script - you have a fundamental problem here.

You want to make a connection to a system in order to get it to change it's IP address. In order for that to happen, you need to find it's IP address in the first place, either based on a static address, or based on name resolution.  Plus you need to be able to route to the address in question.

I suspect what may be happening here is that you are getting a 169.254 address in the first instance. You can add an address from this network to your IP addresses in the host.

HTH

 

Top 50 Contributor
Posts 35

Hi,

I tried the following procedure:

On tempDC1, run Enable-PSRemoting and ensure the command runs without error.

On your client computer, where you added tempDC1 to the rusted hosts list, run:

Invoke-command -computer tempdc1 -script { whatever }

But, the hyperv56 doesn't connect to tempDC1. Only if I connect tempDC1 to the hyperv56 domain, get an IP and replace it instead of tempDC1, then I can run the commnad. But, that is not the requirement, I don't want to connect tempDC1 to the domain.

According to the explaination of Done Jones, it is possible to do that, so please, I need your help to solve this issue.

 

Regards,

Bader 

Top 10 Contributor
Posts 326
Microsoft MVP
Top Contributor

What error do you get when you try to invoke the command?

I suspect this is a credentials issue - you need to specify credentials on the client machine that you then pass in the call to Invoke Command. You may need to specify the Authentication mechanism (using -Authentication parameter).  For information about the values of this parameter, see the description of the System.Management.Automation.Runspaces.AuthenticationMechanism enumeration in MSDN (http://msdn.microsoft.com/en-us/library/system.management.automation.runspaces.authenticationmechanism%28VS.85%29.aspx).

Top 50 Contributor
Posts 35

Hi,

Thanks for the reply,

I have now a coonectivity between the hyperv host and its VM (tempDC1), so by running the commnad ping tempDC1 from the hyperv host, I get a replies.

But I still get the following error message:

PS C:\> invoke-command -computername tempDC1 -Credential $TestAdminCred1 -scriptblock { Set-IPAddress }

[tempdc1] Connecting to remote server failed with the following error message : The WinRM client cannot complete the operation within the time specified. Check if the machine name is valid and is reachable over the network and firewall exception for Windows Remote Management service is enabled. For more information, see the about_Remote_Troubleshooting Help topic.

+ CategoryInfo          : OpenError: (:) [], PSRemotingTransportException

+ FullyQualifiedErrorId : PSSessionStateBroken

 

Please, I need your help in order to fix the above problem,

Regards,

Bader

Top 10 Contributor
Posts 640

That's an indication that WS-MAN isn't able to connect.

  • Make sure the WinRM service is running on the VM.
  • Make sure TCP port 5985 is open on the VM - this may include enabling exceptions on whatever software firewalls you have running.
  • On the VM, open PowerShell and run your same Invoke-Command, but use "-computername localhost". If that doesn't work, then Remoting isn't properly configured on the VM.
You can see that this is a bit difficult to troubleshoot from my end. Things are a bit easier to test with PowerShell v3 - it has some built-in diagnostics tools that v2 doesn't have. If you're able to install the v3 beta on both machines, that would help you. But, it IS beta, so I understand if you're not.

Top 50 Contributor
Posts 35

Hi,

 

Thank you very much for the help,

I opened the TCP 5985 port on the VM, but now I got the following error message:

[tempdc1] Connecting to remote server failed with the following error message : Access is denied. For more information, see the about_Remote_Troubleshooting Help topic.
    + CategoryInfo          : OpenError: (:) [], PSRemotingTransportException
    + FullyQualifiedErrorId : PSSessionStateBroken

I tried to run the the Invoke-Command from the local host, but I got a similar error message:


[localhost] Connecting to remote server localhost failed with the following error message : Access is denied. For more
information, see the about_Remote_Troubleshooting Help topic.
    + CategoryInfo          : OpenError: (localhost:String) [], PSRemotingTransportException
    + FullyQualifiedErrorId : AccessDenied,PSSessionStateBroken

According to your explaination the Remoting isn't properly configured on the VM, so, can you please explain how to handle this issue?

Note: On VM, I only ran the Enable-PSRemoting -force commnad.

Regards,

Bader

Top 10 Contributor
Posts 640

I'll assume you've already done as the error message suggests and read about_remote_troubleshooting, and tried its remedies for this problem. 

For right now, let's continue working ONLY from the localhost console on tempdc1.

Log on to tempdc1's console as a domain administrator account for tempdc1's domain.

On it, open PowerShell. Ensure that the PowerShell window title bar says "Administrator."

Run Enable-PSRemoting, and answer Yes to the various prompts (I know you've done this, but we're doing it again).

Ensure WinRM is running (Get-Service -name Windows*) look for Windows Remote Management.

Run cd wsman:\localhost and ensure that works, and that you can then run Dir to get a directory listing.

Run Enter-PSSession -comp localhost and ensure that works.

Do these commands work properly?

Top 50 Contributor
Posts 35

Hi,

Thank you very much for the reply,

According to your explaination, I ran the following commnad from the VM (localhost) and it works fine:

invoke-command -computername tempDC1 {

#Set the IP address, MAC address and DNS

function Set-IPAddress {

param( [string]$networkinterface = "OnTest",

[string]$ip = "192.168.0.1",

[string]$mask = "255.255.255.0",

[string]$dns1 = "127.0.0.1"

)

#Start writing code here

$dns = "127.0.0.1"

if($dns2){$dns =$dns1}

$index = (gwmi Win32_NetworkAdapter | where {$_.netconnectionid -eq $networkinterface}).InterfaceIndex

$NetInterface = Get-WmiObject Win32_NetworkAdapterConfiguration | where {$_.InterfaceIndex -eq $index}

$NetInterface.EnableStatic($ip, $mask)

$NetInterface.SetDNSServerSearchOrder($dns)

}

Set-IPAddress

}

 

And now I'm trying to run the commnad from the hyperv host using the following script (Based on about_remote_troubleshooting):

$TestAdminCred1 = New-Object System.Management.Automation.PSCredential -ArgumentList "TEMPDC1\Administrators",$("VMPassword" | ConvertTo-SecureString -AsPlainText -Force)

set-item wsman:\localhost\Client\TrustedHosts -Credential $TestAdminCred1 -Value tempDC1 -Force

invoke-command -computername tempDC1 -Credential $TestAdminCred1 {

#Set the IP address, MAC address and DNS

function Set-IPAddress {

param( [string]$networkinterface = "OnTest",

[string]$ip = "192.168.0.1",

[string]$mask = "255.255.255.0",

[string]$dns1 = "127.0.0.1"

)

#Start writing code here

$dns = "127.0.0.1"

if($dns2){$dns =$dns1}

$index = (gwmi Win32_NetworkAdapter | where {$_.netconnectionid -eq $networkinterface}).InterfaceIndex

$NetInterface = Get-WmiObject Win32_NetworkAdapterConfiguration | where {$_.InterfaceIndex -eq $index}

$NetInterface.EnableStatic($ip, $mask)

$NetInterface.SetDNSServerSearchOrder($dns)

}

Set-IPAddress

}

 

But I got the following error message:

[tempdc1] Connecting to remote server failed with the following error message : Access is denied. For more information, see the about_Remote_Troubleshooting Help topic.

    + CategoryInfo          : OpenError: (:) [], PSRemotingTransportException

    + FullyQualifiedErrorId : PSSessionStateBroken

 

Can you please help me solve the above problem?

Regards,

Bader

Top 10 Contributor
Posts 640

Unfortunately, it looks to me like you're doing everything correctly. I would either need to be there with you to troubleshoot this, or more likely I would call Microsoft Product Support and open an incident on this. Thats what I recommend you do next. You've tried everything I know to suggest. 

Top 50 Contributor
Posts 35

Hi,

I found that that the problem is caused as a result of the following commnad:

$TestAdminCred1 = New-Object System.Management.Automation.PSCredential -ArgumentList "TEMPDC1\Administrator",$("VMPassword" | ConvertTo-SecureString -AsPlainText -Force)

But by using the following commnad, and type the password manually, the connection works fine and all commnads executes as expected:

$TestAdminCred1 = Get-Credential -Credential $("TEMPDC1\Administrator")

Can you please, explain to me how can I prevent typing the password each time I run the script (The password never change)?

Another issue:

In some VMs I got the following error message by typing the commnad Enable-PSRemoting –force:

 Can you please help solve the above issues?

Regards,

Bader

Top 10 Contributor
Posts 326
Microsoft MVP
Top Contributor

First try setting the network type to private and try again. Like the text suggests.

Second, regarding the creation of a credential (in code).  This is NOT best practice, but it looks something like this:

$user         = 'tfl@acooldomain.comword'
$password = 'Pa$$w0rdsAreBoring'
$secpw      = ConvertTo-SecureString $password -AsPlainText -Force
$cred         = New-Object System.Management.Automation.PSCredential  $user $password

 

Top 10 Contributor
Posts 326
Microsoft MVP
Top Contributor

Ignore the above bit of code, here is a function that works better:

function New-Credential {
param (
[string] $Userid,
[string] $Pwd
)
# Create the credential
spwd = ConvertTo-SecureString -AsPlainText $pwd -Force
$cred = New-Object System.Management.Automation.PSCredential $userid,$spwd
# Now return it to the caller
return $cred
}  

# Call the function to demonstrate example

New-Credential "contoso\administrator" "Pa$$w0rd"  

Top 50 Contributor
Posts 35

Hi,

Thank you for the reply,

Can you please tell me how can I use your function with the following invoke-commnad ($remotingCreds is the required credentials):

invoke-command -computername $NPS1 -Credential $remotingCreds { .......... }

Back to the network issue above (Your reply: "First try setting the network type to private and try again. Like the text suggests."), I found that I got this error message only on client machines, but on server machine the commnad "Enable-PSRemoting –force" works as expected. I made a deep search on this issue, but I found nothing.

Note: Both client and server machine are connected to the same network adapters and both are clean of configurations. But the commnad runs well only on server machine.

Please, I need your help,

Regards,

Bader

Page 2 of 3 (31 items) < Previous 1 2 3 Next > | RSS
Copyright 2012 PowerShell.com. All rights reserved.