Hello,
I tried your script and received the errors below. I configured an IP on the VM and put hosts file entries on the host running the script. I did some research on the error and found references to proxy configurations which I am not using.
VERBOSE: 4/6/2020 2:06:40 PM Get-View Finished execution
VERBOSE: 4/6/2020 2:06:40 PM Get-View Finished execution
VERBOSE: 4/6/2020 2:06:40 PM Get-View Finished execution
VERBOSE: 4/6/2020 2:06:40 PM Get-View Finished execution
VERBOSE: Created temp folder in guest OS C:\Users\ADMINI~1\AppData\Local\Temp\salman_2020vmware26
VERBOSE: Created temp script file in guest OS
C:\Users\ADMINI~1\AppData\Local\Temp\salman_2020vmware26\salman_2020vmware219.ps1
VERBOSE: Created temp output file in guest OS
C:\Users\ADMINI~1\AppData\Local\Temp\salman_2020vmware26\salman_2020_outputvmware233
VERBOSE: Copying Data to C:\Users\ADMINI~1\AppData\Local\Temp\salman_2020vmware26\salman_2020vmware219.ps1
Invoke-WebRequest : Unable to connect to the remote server
At C:\Users\salman\Documents\test.ps1:261 char:15
+ ... copyResult = Invoke-WebRequest -Uri $fileInfo -Method Put -Body $Data
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Invoke-WebRequest], WebException
+ FullyQualifiedErrorId : System.Net.WebException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
ScripText copy failed!Status
At C:\Users\salman\Documents\test.ps1:264 char:1
+ Throw "ScripText copy failed!`rStatus $($copyResult.StatusCode)`r$(($ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (ScripText copy failed!Status :String) [], RuntimeException
+ FullyQualifiedErrorId : ScripText copy failed!Status