The top portion of my code is working beautifully. For some reason I am have trouble with the code i have bolded below.
What I am trying to do is select the field called path from the sql server, then change the directory to that path. Then I am selecting the executable file from the sql table in the field called "EXE" and running it.
Foreach-object {CD $_.Path ; start-process -filepath $_.EXE; $_} <-This code works when I have it set to run locally. My query is working perfectly as well. Do i need to be naming the .Path and .EXE something like: {CD dbo.Auto_Master.Path ; start-process -filepath dbo.Auto_MasterEXE; $_} as opposed to using the "$_" ?
Any help would be greatly appreciated, thanks!
Here is the entirety of my code:
import-module C:\WORK\xMATCH\Invoke-Sqlcmd2.ps1
$query = "SELECT dbo.Auto_Master.PATH, dbo.Auto_Master.EXE FROM dbo.Auto_Master WHERE (((dbo.Auto_Master.Active)='Y'));"
invoke-sqlcmd2 -serverinstance "$env:computername\" -Database SQL_TRIG -Query $query | Foreach-object {CD $_.Path ; start-process -filepath $_.EXE; $_}