How do you do the equivalent of using a remote server's $env namespace without hardcoding network paths for cmdlets like Set-Location? I have a script that loops through remote servers and I'm trying to access their equivalent of $env:programfiles from a single script, but these servers have the variable set in different locations.
Basically getting a loop that navigates
c:\program files \\server1\c$\program files \\server2\c$\programs \\server3\d$\apps
Using something familiar and simple like
And have the remote server's $env return a network path instead of a drive letter. The current way I'm doing it is grabbing the paths using Invoke-Command and building the path manually (replace : with $, append \\server in front of the path, turning "c:\program files" to "\\server\c$\program files")