Powershell, Using the results of a Invoke-SQLcmd as a variable in a file path

76 views Asked by At

I am trying to use Powershell to run a stored procedure in a database and set those results to a variable. That part of my script works just fine, however when i try to use said variable in a file path I receive the below error:

"Cannot find path 'C:\Program Files\Microsoft.PowerShell.Commands.Internal.Format.FormatStartData Microsoft.PowerShell.Commands.Internal.Format.GroupStartData Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData Microsoft.PowerShell.Commands.Internal.Format.GroupEndData Microsoft.PowerShell.Commands.Internal.Format.FormatEndData' because it does not exist."

The Script I am using creates a Function for the SQL cmd

   function version
{
Invoke-Sqlcmd -Username  -Password "" -Serverinstance $ip -Database DBname -Query "EXEC [PROFITMASTER].[DBO].[SPSM_SYS_GETDATABASEVERSION]" |Format-Table -HideTableHeaders

}

The second part of the script sets a variable to the results of the function, then attempts to run a .exe from a filepath that includes the variable.

if ($result -eq [System.Windows.Forms.DialogResult]::OK -and $objListBox.SelectedIndex -ge 0)
{        
      cd "C:\Program Files\$Release"
    start-process '.\Filename.exe'
}

Any help would be greatly appreciated. I have been fighting this script and researching online for the last 2 days.

0

There are 0 answers