appveyor / ci

AppVeyor community support repository
https://www.appveyor.com
344 stars 66 forks source link

RDP script does not work - ObjectNotFound: (Get-NetIPAddress:String) when executing enable-rdp.ps1 #3691

Closed GitMensch closed 3 years ago

GitMensch commented 3 years ago

per https://www.appveyor.com/docs/how-to/rdp-to-build-worker/ I've added

 $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))

To my build config for failures, it is actually downloaded and executed (as it was before) but now fails to execute:

$blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))
iex : The term 'Get-NetIPAddress' 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.
At C:\Users\appveyor\AppData\Local\Temp\1\1fn9k92dyi.ps1:6 char:20
+ ... dp = $true; iex ((new-object net.webclient).DownloadString('https://r ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : ObjectNotFound: (Get-NetIPAddress:String) [Invoke-Expression], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException,Microsoft.PowerShell.Commands.InvokeExpressionCommand

Command exited with code 1

So either the documentation needs an update or the script... or both.

FeodorFitsner commented 3 years ago

I wasn't able to reproduce the issue on Visual Studio 2019 and Visual Studio 2017 images. Here is some of the tests: https://ci.appveyor.com/project/FeodorFitsner/simple-console/builds/39903719

There could be some changes into PowerShell environment during the build. Could you, perhaps, do a simple repro in a public repository?

GitMensch commented 3 years ago

Just rechecked, that was running on PS Core, possibly this is the reason?

FeodorFitsner commented 3 years ago

I've checked with PS Core and it worked as well. Did it work for you with Windows PowerShell?

GitMensch commented 3 years ago

To tests that I've used a working environment and added the following in appveyor.yml:

on_success:
- pwsh: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))

Result in all environments of that build with

image:
- Visual Studio 2015
- Visual Studio 2017

Is the message above, it does work in the VS2019 image (while it previously also worked in the older ones).

What do we do with this information now?

FeodorFitsner commented 3 years ago

Try using ps instead of pwsh for RDP script.

GitMensch commented 3 years ago

OK, ps is "Powershell" and pwsh is "Powershell Core". The script works with both in the VS2019 image but for the others only in "Powershell".

So I assume that the cmdlet Get-NetIPAddress was added later and the two "older" images have an older version of ps-core that does not support this.

Options:

What do you think?

FeodorFitsner commented 3 years ago

Actually, all examples in RDP KB use ps prefix. Indeed, VS 2015 and VS 2017 images have outdated PS Core, so use ps which guaranteed has that cmdlet.

GitMensch commented 3 years ago

Hm, would the default workers used for public repos work with $nonat set? In this case #3692 would solve it.

FeodorFitsner commented 3 years ago

$nonat is never set by build workers (I'm not even sure why that variable was introduced at all, maybe for BYOC scenarios), so that fix won't help to the fact that pre 7.x PS Core does not have Get-NetIPAddress cmdlet.

GitMensch commented 3 years ago

The idea was to set $nonat, if this would work. Guess it wouldn't...