Score:0

Windows-to-Windows SSH: Get remote environment variable

ad flag
kol

From a Windows 10 host I connect to a Windows 10 target machine via SSH to read one of its environment variables, say, %COMPUTERNAME%. OpenSSH is installed on both machines. The remote shell is cmd, and I'd like to use cmd commands. I tried this:

ssh someuser@somecomputer echo %COMPUTERNAME%

Unfortunately I get the host computer's name. Apparently the local cmd substitutes the local %COMPUTERNAME% variable before sending the command to the target. How can I get the remote computer's name? I tried escaping the %, using quotes etc., but nothing helped.

IMPORTANT: I can already solve the problem by calling PowerShell on the target. What I'd like to learn is how this can be done using cmd... I have a feeling this should be possible :)

in flag
Sounds like you are searching for delayed variable expansion https://ss64.com/nt/delayedexpansion.html
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.