Powershell dtutil

Powershell Dtutil (Dtutil.exe) – When I first tried PowerShell with Dtutil command line tool I had an issue to run the command. The problem was semicolon ; which is a special character in Powershell. For those having similar issue see below how you can run dtutil command from PowerShell:

Here is a simple copy file example:

dtutil /FILE ".\SourceFileFromTheSameFolder.dtsx" /COPY FILE';C:\Program Files\Microsoft SQL Server\100\DTS\Packages\PackageFinalDestination.dtsx' /Quiet

In the above command I just move file from folder where I have my PowerShell script into FileSystem SSIS default folder.
Notice that I put apostrophe ‘ before semicolon ; if I didn’t do that it would give the following error:
Unexpected token 'Quiet' in expression or statement.
And if I removed /Quiet it would give next error:
Argument "FILE" for option "copy" is not valid.

Below is code that I am still working on and additionally get dynamically DTSPath from registry which I hope will be reliable way to do it. Captures result in variable to avoid ugly message and then output the result and pauses.

$DTSPath = (get-itemproperty -path "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\100\SSIS\Setup\DTSPath").'(default)'

$result = dtutil /FILE ".\SourcePackage.dtsx" /COPY FILE';'$DTSPath'Packages\Destination.dtsx' /Quiet

if ($LASTEXITCODE -eq 0) {Write-Host "Package Deployment result (ERS CSV Load)…ok"}
elseif ($LASTEXITCODE -eq 1) {Write-Host "Package Deployment result (ERS CSV Load)…*** ERROR *** The utility failed. Error code 1"}
elseif ($LASTEXITCODE -eq 4) {Write-Host "Package Deployment result (ERS CSV Load)…*** ERROR *** The utility cannot locate the requested package. Error code 4"}
elseif ($LASTEXITCODE -gt 5) {Write-Host "Package Deployment result (ERS CSV Load)…*** ERROR *** The utility cannot load the requested package. Error code 5"}
elseif ($LASTEXITCODE -gt 6) {Write-Host "Package Deployment result (ERS CSV Load)…*** ERROR *** The utility cannot resolve the command line because it contains either syntactic or semantic errors. Error code 6"}
else {"Package Deployment result (ERS CSV Load)…*** ERROR *** Unidentified Error."}

Write-Host "Press any key to continue …"
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")

Powershell dtutil

See also: DTUTIL - Microsoft documentation

Hope that helps
Emil
Did you find this page useful?
+1  |  -0
(1 Votes)