Azure VM Powershell Can't run script using UNC path from other server, get not digitally signed error

I am trying run PowerShell script on my server (Azure VM) which is available on Remote Machine (On-Premise / Azure VM) but get below error.
I don’t want to change execution policy to Bypass or unrestricted, as it’s already working between on-premise to on-premise. script execute successfully using UNC Path.

Note: This blog not showing UNC path correctly (I am using \ \ in my UNC path)

PS C:\Users\19004-SA\Desktop> Get-ExecutionPolicy
RemoteSigned

PS C:> & ‘\RemoteServer\c$\test.ps1’
& : File \RemoteServer\c$\test.ps1 cannot be loaded. The file \RemoteServer\c$\test.ps1 is not digitally signed. You
cannot run this script on the current system. For more information about running scripts and setting execution policy,
see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:3

  • & ‘\RemoteServer\c$\test.ps1’
  • + CategoryInfo          : SecurityError: (:) [], PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess

Hi Patilkishora, welcome back to the forum

This is because you did not use the preformatted text option, it’s the little </> button (note it may be hidden under the settings wheel) Please always format any code/errors with this option. If you don’t want to change your policy, you can try copying the script to the local system and run it locally. Outside of that you can either sign the script, or perhaps use a onetime bypass while calling it.

powershell.exe -ex bypass -file \\RemoteServer\c$\test.ps1

I tried bypass & unrestricted option and script works through UNC path.
I would like to understand the behavior of the Azure VM, because on on-premise server there is now issue.

Even if I try to execute script on Azure VM using UNC and script is on other Azure VM I get the same error. which is not the case in on-premise (VMWARE) servers.

I can’t see your environment so I won’t be much help. Are the machines domain joined? Have you checked the network category and make sure it’s not “public”?

Get-NetConnectionProfile

On-premise / Azure VM all these machines are in same domain.
Only difference OS & Powershell Version

On-premise ( OS: 2012 R2, PS Version: 4.0
Azure VM (OS:2019 , PS Version:5.1)

I checked network category and it’s not “Public” and same on both servers.