I am trying to write a short powershell script to accomplish some networking integration for software I am working on.
I have Powershell 4.0 working between 4 machines running both Win7 and Win8, and the connections function, and allow manual manipulation and execution.
However, when I try and write a script to automate the process, things start to misbehave.
Whet I am trying to do is execute a command on a remote machine like
F:\Folder\App.exe /xLICENSE.txt
App.exe takes the command-line input from /xLICENSE.txt and creates a file named LICENSE.txt in it's home directory with a unique user handle for use with certain application processes.
If I manually enter a new PSSession with a computer hosting App.exe, I can enter that command exactly as shown, and it executes the application, and produces the correct results.
However, when I attempt to integrate this command into a script, it keeps telling me that the command is not recognized as any command or cmdlet.
I have tried
$connection = New-Pssession -Computername NAME -Credential LOGIN
Invoke-Command -Session $connection -ScriptBlock {& "F:\Folder\App.exe /xLICENSE.txt"}
Remove-PSSession $connection
But it just gives me the error I described earlier. I've also taken the command out of the quotations, and omitted the &, as well as replacing the command with a string containing the command (within quotations preceding an &)
And I also tried the line
Invoke-Command -Computername NAME -ScriptBlock {& "F:\Folder\App.exe /xLICENSE.txt"} -Credential LOGIN
and that doesn't work either. I've also tried the different ways to reference the command, using strings, and I've also tried passing the string in as a parameter to the invoke-command cmdlet, but nothing seems to work.
The only difference here is the Invoke-Command doesn't work if I do it manually...
If I remove the /x argument, then the script executes, but there's no way to prove that it did. If I do any of the above with a cmdlet like, say, Get-ChildItem, then it will correctly show the contents of the home directory of the server I am connecting to.
I'm just sort of lost as to what I can do about this. I had high hopes for Powershell, but if I can't get it to do this, it's going to be tough...
Thanks!