I have a powershell script that executes a custom executable file on a remote server. I have no problem getting the script to execute and to function correctly IF I first execute the program manually first on the server.
The reason for this is that the program dynamically creates assemblies and save these to file for later use. If these files exists the program tries to remove them and recreate or if this fails uses existing files.
The conclusion that I have is that when running the script the program doesn't have the rigth to handle the file system for some reason. Since if I run the program manually on the server the dynamic assembly files are created and subsequent executions of the script works as if the file was created, i.e. it reads the files created before. The files are created in the same directory as the program executes in.
How can I setup the powershell script so that files are allowed to be created on the remote server?
Below is "almost" my script
$path = Split-Path -parent $MyInvocation.MyCommand.Definition
$password = ConvertTo-SecureString -String "myPass" -AsPlainText -Force
$credentials = New-Object pscredential("remoteUser", $password)
$servernamn = "myMachine"
Invoke-Command -ComputerName $servernamn -Credential $credentials -ArgumentList $path ScriptBlock { & 'D:\temp\custom.exe' }
I got this to work after a while, couldn't understand why the suggested try didn't.
At the end I got the following script
Invoke-Command -ComputerName $servernamn -Credential $credetials -Scriptblock {
cd "D:\temp\"
./custom.exe
}
I don't know why there is a difference in running the program AFTER i change directory but apparently there is. Anyway this works and if somebody have the same problem try this.