Register-psrepository failed with "The property 'Name' cannot be found on this object" error
Prerequisites
- [X] Write a descriptive title.
- [X] Make sure you are able to repro it on the latest version
- [X] Search the existing issues.
Steps to reproduce
Recently, I got one issue from customer. We find the issue is caused by Ping-Endpoint (functions in PowershellGet module, PSModule.psm1 ) returns 403 or 405 randomly when execute Register-PSRepository.
1- In the environment, we will see in verbose message, there are several ping-endpoint results and for the last one, it returns 403.

2- At this point, if we check psrepositories.xml file (C:\Users<username>\AppData\Local\Microsoft\Windows\PowerShell\PowerShellGet), we will see the "sourcelocation" is null.

3- For the following attempts to register a repository it will fail with the same error.
4- In my local lab, I forcely change the last ping-endpoint result to 403/405 in psmodule.psm1 and the same result would be reproduced that "sourcelocation" in psrepositories.xml is null but the error message is a little bit different.

5- To resolve this issue, currently, the only way seems to delete the psrepositories.xml
6- In the PowershellGet version 2.1.0, it is has already handled 200, 401 and 407. Will it be possible to add 403 and 405 also? Appreciate your inputs.
PowerShell Gallery | PSModule.psm1 2.1.0
Write-Debug -Message "Ping-Endpoint: location=$Location, statuscode=$statusCode, resolvedLocation=$resolvedLocation"
if((($statusCode -eq 200) -or ($statusCode -eq 401) -or ($statusCode -eq 407)) -and $resolvedLocation) { return $resolvedLocation }
Expected behavior
Register PS repository successfully
Actual behavior
Register PS repository with error and will fail with all following attempts to register PS repository
Error details
Cannot bind argument to parameter 'location' because it is an empty string.
The property 'Name' cannot be found on this object
Environment data
PS C:\windows\system32> $psversiontable
Name Value
---- -----
PSVersion 5.1.14393.5127
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.14393.5127
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
Version
Powershell version 5.1, PowershellGet version 1.0.0.1
Visuals
No response