I am trying to execute a set of code using "Invoke-Command with computer name and path". It is executing the file but not getting the correct result. When I am executing the same code locally on the server just by using "Run with Powershell" it is giving the correct output. Can anyone please help me with this.
Example 1) Invoke-Command -ComputerName $ServerName -FilePath "\\$ServerName\C$\textfile.ps1"
What is the expected and wrong output here. Is it possible to share both the outputs.
I suggest not do use script execution from remote path. Try to have it locally or get the script content and convert to scriptblock using [ScriptBlock]::create($content) method.