Submitted by Robse-ponte on Fri, 02/19/2016 - 08:36
Forums:
I try to run a powershell script with a function and it does not work. NX says, cannot find script. What am I doing wrong? Thank you and best regards. Hereby my function:
Imports System.Diagnostics
RunPowerShell("C:\Temp\test.ps1")
Public Function RunPowerShell(ByVal script As String) As Integer
Dim execProcess As New System.Diagnostics.Process
execProcess.StartInfo.CreateNoWindow = true
execProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
execProcess.StartInfo.FileName = "powershell.exe"
execProcess.StartInfo.Arguments = script
execProcess.StartInfo.UseShellExecute = False
Return execProcess.Start
re: run powershell script
I created a very simple powershell script and modified your code to point to it. The code worked for me.
Double check the path and name of your script to make sure it exactly matches the path you are calling in the journal file.
Teamcenter
Hmm really strange behavior, it seems that this code is working with NX native, but in combination with teamcenter it is not.
error:
System.componentModel.Win32Exception: Das System kann die angegebene Datei nicht finden bei System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)....
It seems, this is a Windows 64bit issue. Do you know any advice?
re: run script
Unfortunately, I cannot think of a good reason why running a script in this manner would work with native NX, but not TC...
Solved
replaced "powershell.exe" with "C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe" and everything is working fine now... rookie mistake
re: solved
Great news; thanks for the update.