I am able to connect to the remote host via pssession and run .PS1 files (located on my local computer) on that host. I am trying to run the script below on the remote host which runs, however it cannot locate the files “userlist.csv” and “addusers.ps1” (both files are located on my local computer). I suppose I am not referencing or pointing to the files correctly (“userlist.csv” and “addusers.ps1”) within the script. Any help is appreciated! Thanks!
When a script is running on a remote computer, it is referring to its local resources. There’s no implicit connection back to your computer. So you either need to stage those files on the remote machine, or make them available via a file share (e.g., a UNC path).
Thanks Don! We originally considered copying the files to the target (easy to do). We thought it would be the most convenient if the targets could “see” our clients (which reside on our internal network). So to facilitate UNC back to the client, the client would have to be “NATTED”…meaning the internal client IP would have to be assigned a public address.
Question: if we reference a UNC path inside the remote session (SSL), does the UNC reference open a new SMB connection outside of the remote session? OR does it use SMB wrapped inside the SSL transmission? I know we could WireShark this, but just curious if you know of the particulars.
So, are you using “SSL” or PowerShell Remoting? Just curious, it doesn’t impact the answer. There’s no such thing as “SMB wrapped inside” anything; the remote machine would open a new, normal SMB connection to whatever UNC path you told it to use. That would need to work from both a connectivity and an authentication perspective - and the connection may been seen by the “file server” as Anonymous.
But that actually does beg the question of whether you’re using SSL (did you mean SSH?) or Remoting. Because there are better ways to do this.
The remote computer produces objects, which have properties, and those properties possess values. Those come back to your machine via the Remoting connection, and YOUR machine appends that data to a CSV, or puts it in a new CSV, or whatever. Notice, too, that the INPUT CSV was read in LOCALLY, and passed into the remote script block. The remote machine will see that entire data set in $data, although I didn’t use it in my example.
So you pass objects back and forth. Any writing to contents on your computer happens on YOUR computer. You don’t want one computer reaching out to another to write to a CSV file, and you don’t want to be copying files back and forth and all that crap.
I understand - was able to get everything to work just fine by not calling too many PS1’s from the primary script. This allowed the primary to see the multiple sessions/variables are the script was running. In the end, everything ran as expected.