I created a PowerShell script that connects to a server using WinRM and deploys a newly built .dll file. It works perfectly when I run it on its own, but when I try to execute it in the post-build section using the command `powershell.exe -ExecutionPolicy Bypass -file "$(ProjectDir)myscript.ps1"`, I get an error code -196608. The script is located in the ProjectDir folder. Does anyone have any advice on how to resolve this?
2 Answers
Have you tried using a static path? You might need to prepend `$Using:` before your variable for it to work properly. Also, it’s a good idea to verify the file path with `Join-Path` and `Test-Path` on the remote server to ensure everything is set correctly. I also noticed a typo in your command - there's an extra 'E' before the `-file` part, so make sure to fix that!
What’s your build environment like? I recommend avoiding passing PowerShell expressions directly to a PowerShell process because it could lead to evaluation issues in the parent context. Try resolving the ProjectDir variable outside the script, and also be careful with command line arguments and delimiters. If you're calling `myscript.ps1`, just use an ampersand before the script path instead of starting a new PowerShell process.

Got it! I'll give that a shot by using & "$ProjectDirMyScript.ps1".