powershellinvoke-sqlcmd

"Given path's format is not supported" when using relative paths in Powershell


I have a Powershell script which I have used successfully for some time but only recently it has stopped liking the relative paths that are setup. Any idea why or how this might happen?

The location of the script I am trying to call is C:\Scripts\01_Upload.sql.

$scripts = "C:\Scripts"
cd $scripts
Invoke-Sqlcmd -ServerInstance 'xxx-xx-xxxx' -Database 'TestDB' -InputFIle .\01_Upload.sql

I have censored the server name for security. This line has previously worked, I've tried different also just using 01_Upload.sql and also by surround it in quotes but it now returns this error:

Invoke-Sqlcmd : The given path's format is not supported.

If I include the full path, the code works fine. Why are my relative paths not working? I have recently updated from Windows 7 to Windows 10 if this has impacted things.


Solution

  • According to documentation full path to file is required.

    -InputFile Specifies a file to be used as the query input to this cmdlet. The file can contain Transact-SQL statements, XQuery statements, and sqlcmd commands and scripting variables. Specify the full path to the file. Spaces are not allowed in the file path or file name.

    https://learn.microsoft.com/en-us/powershell/module/sqlserver/invoke-sqlcmd?view=sqlserver-ps