Score:0

How to run PowerShell scripts remotely on old servers (2012 and 2012 R2)?

ir flag

I've been running remote scripts on newer VMs (2019 and 2022) but now I have to run my scripts remotely on older VMs as well. It looks like PowerShell Direct is not available on older Windows Server like 2012 and 2012 R2.

Is there a equally simple way to run remote scripts on these old servers?

noobie avatar
ir flag
PSRemoting is already enabled on the servers. I double checked. Notice that I'm using -Invoke-Command with -VMName parameter and not -ComputerName parameter.
noobie avatar
ir flag
Yea. For some reason using `Invoke-Command` with `-VMName` did not work but with `-ComputerName` it did!
X.LINK avatar
tw flag
Windows 8 and 8.1 based Server editions (respectively 2012 and 2012 R2) are the first ones to get integrated PowerShell. But since Microsoft is Microsoft, it's just they'll sometimes change the commands way of doing things without properly considering retrocompatibility ever since too, same goes for Beta-class software as RTM.
Score:0
ir flag

Use -ComputerName instead of -VMName.

Invoke-Command -ComputerName <your VM name> -Credential $cred -ScriptBlock { whoami }

Make sure to run this on the host beforehand to add the remote server to trusted hosts.

Set-Item -Force WSMan:\localhost\Client\TrustedHosts "*"

Restart-Service WinRm -Force

And as @Pimp Juice IT mentioned in their comment, enable PSRemoting on the remote server and make sure the host is added to its TrustedHosts list as well.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.