Search code examples
powershelloctopus-deploy

Powershell invoking DTUTIL error


I'm currently in the process of building a deployment process in octopus deploy and as part of that I want to use DTUTIL to create folders and load SSIS packages to our server. This text "C:\Program Files (x86)\Microsoft SQL Server\130\DTS\Binn\dtutil.exe" /SourceServer [servername] /FC SQL;\;[foldername], with appropriate server and folder names, which works in DOS.

Here is the rub, if I use the same code in Powershell I get an error:

$Command ="`"C:\Program Files (x86)\Microsoft SQL Server\130\DTS\Binn\dtutil.exe`"  /SourceServer MYSERVER /FC SQL;\;Folder1";
invoke-Expression $Command;
invoke-expression : At line:1 char:73
+ ...  Files (x86)\Microsoft SQL Server\130\DTS\Binn\dtutil.exe"  /SourceSe ...
+                                                                  ~
You must provide a value expression following the '/' operator.
At line:1 char:73
+ ... \Microsoft SQL Server\130\DTS\Binn\dtutil.exe"  /SourceServer MYSERVER ...
+                                                      ~~~~~~~~~~~~
Unexpected token 'SourceServer' in expression or statement.
At line:1 char:1
+ invoke-expression $Command
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : ParserError: (:) [Invoke-Expression], ParseException
+ FullyQualifiedErrorId : ExpectedValueExpression,Microsoft.PowerShell.Commands.InvokeExpressionCommand

Has anyone got any idea how to remedy this?

Anthony


Solution

  • You can execute the EXE using the & operator:

    & "C:\Program Files (x86)\Microsoft SQL Server\130\DTS\Binn\dtutil.exe"  /SourceServer MYSERVER /FC SQL;\;Folder1
    

    Also, the above Invoke-Expression command failed in the same way when I ran it in PowerShell directly, this doesn't appear to be an issue with running the PowerShell within Octopus.