Hi,
I'm trying to run a powershell script on a Virtual Machine remotely (From the Hyper-V host).
Here is the powershell script:
Enable-PSRemoting -force $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 New-PSSession -ComputerName tempDC1 -Credential $TestAdminCred1 #Set the IP address, MAC address and DNS function Set-IPAddress { param( [string]$networkinterface = "MyTest", [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) } invoke-command -computername tempDC1 -Credential $TestAdminCred1 -scriptblock { Set-IPAddress }
But, I'm getting 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
I have a connectivity between the hyperv host and its VM (called tempDC1), so by running the commnadping tempDC1 from the hyperv host, I get a replies.
Please, I need your help in order to fix the above problem,
Regards,
Bader