What I’m trying to do is, within the function, set-content of a bat file to a bat file cmd based on the version of the application then run the cmd, then get-content of a log that is written by the command ad return the results. I can get this to work on a locally but if I try to do it remotely I’m hitting issues…
Magazines have issues. Sounds like you’re having problems. It’d help to know what this problems are, as I can’t run your code in your environment :).
You don’t describe how you’re running this function. If you’re doing so by using Remoting (Invoke-Command), then you’re very likely running into the “second hop” problem that many people run into. It’s well-covered in “Secrets of PowerShell Remoting” (free, from the Resources/eBooks menu here). Your credentials get delegated by Invoke-Command to the remote machine, but by default it can’t delegate them any further, so accessing a UNC would fail.
You would either need to accommodate additional delegation hops, likely via CredSSP, or re-think the way you’re moving information around to avoid the double-hop.
Now, I don’t know that this is your problem, because I don’t know how you’re running this function remotely, nor do I know what problems you’re running into when you do so. Right now, I’m just guessing, and hoping you’ll share some more details.
That path should probably be in double quotes. Also, notice D$. The dollar sign is going to confuse PowerShell, because it’s going to seem like a variable. Put a backtick in front of that dollar sign so that it’s treated as a literal character.
In your Invoke-Command example, the problem is that you’re asking the remote computer to evaluate $QueryText. The remote computer doesn’t HAVE a $QueryText variable, though. You can use $using:QueryText (PowerShell v4 and later, I believe) instead, which will grab the value from $QueryText on your local computer, and send that.
You do have to keep track of what code is running locally, and what code is running remotely, and pay attention to how PowerShell is parsing your commands and values. It’s definitely complicated.