PowerShell does not allow you to use a remote session if you have a network configured as public instead of private.
If you have a public network setup and use the Get-Credential command, even when executing PowerShell on localhost, you get the following error:
[YourServerName] Connecting to remote server YourServerName failed with the following error message : Access
is denied. For more information, see the about_Remote_Troubleshooting Help topic.
+ CategoryInfo : OpenError: (YourServerName:String) [], PSRemotingTransportException
+ FullyQualifiedErrorId : AccessDenied,PSSessionStateBroken
If are on localhost and you remove the -credential from your command, it will execute successfully. (Assuming you are logged in as a user with rights to execute the PowerShell commands).
Here is an example to try:
Produces Error
$credential = Get-Credential
$compname = “YourServerName”
Invoke-Command -ComputerName $compname -Credential $credential {tzutil /s “Central Standard Time”}
Runs Successfully
$credential = Get-Credential
$compname = “YourServerName”
Invoke-Command -ComputerName $compname {tzutil /s “Central Standard Time”}
The key is to make your public network a private one.
If your server came with two NICs and you only configured one of them, then your 2nd NIC may be enabled, but not have a default gateway. If you configure the NIC with a proper IP address and default gateway, it will change to Private and your PowerShell scripts will work. Alternatively, if you are not using that NIC, you can disable it.