1

I'm trying to execute a command using the following code snippet:

foreach($package in (Get-Childitem *.dtsx | select-object -expand Name))
{
    DTUTIL /COPY SQL;"\$package" /DESTSERVER "$global:SSISServer" /FILE "$package" /Q
}

However doing so results in the following error message:

You must provide a value expression on the right-hand side of the '/' operator.
At C:\Projects\RiskOptix\Code\Deployment\BuildAll.ps1:267 char:39
+         DTUTIL /COPY SQL;"\$package" / <<<< DESTSERVER "$global:SSISServer" /FILE "$package" /Q
+ CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : ExpectedValueExpression

I also tried

& DTUTIL "/COPY SQL;'\" + [System.IO.Path]::GetFileNameWithoutExtension($package) + "' /DESTSERVER '$global:SSISServer' /FILE $package"

But now this gives me

Microsoft (R) SQL Server SSIS Package Utilities
Version 10.50.1600.1 for 32-bit
Copyright (C) Microsoft Corporation 2010. All rights reserved.

At least one of the DTS, SQL, or File options must be specified.

But at least the command ran but it seems like it didn't receive any of the parameters I sent it ...I'm guessing there's a fundamental concept of PowerShell I'm overlooking or failed to grasp here. Where have I gone wrong?

2 Answers 2

1

When passing variables as arguments to a command, you don't need to quote them. That being said, it looks like you have a rogue semi-colon in your command. Semi-colons are optional in PowerShell, but when present, is used as the command separator. In this case, you'll need to quote the argument that has a semi-colon, or create a variable for that argument:

Get-Childitem *.dtsx | 
    Select-Object -expand Name |
    ForEach-Object { DTUTIL /COPY "SQL;\$package" /DESTSERVER $global:SSISServer /FILE $package /Q

I've never used diutil, so don't know the commands arguments or syntax.

Sign up to request clarification or add additional context in comments.

1 Comment

This worked - I guess my problem was not understanding how parameters are passed to a command from PowerShell Thanks, this was driving me crazy
1

try Invoke-Expression like:

Invoke-Expression "DTUTIL /COPY SQL;`"\$package`" /DESTSERVER `"$global:SSISServer`" /FILE `"$package`" /Q"

the whole string is evaluated first and result is then passed to powershell like normal command

3 Comments

It's still giving me the error Invoke-Expression : You must provide a value expression on the right-hand side of the '/' operator.
try: echo "DTUTIL /COPY SQL;"\$package" /DESTSERVER "$global:SSISServer" /FILE "$package" /Q" and design the output to the way you would run in win batch
Actually that gave me the idea - I used echo "/COPY SQL;""\$package"" /DESTSERVER ""$global:SSISServer"" /FILE $package /Q" | DTUTIL ..and surprisingly it worked. What is the difference between using it like this way, vs &, vs Invoke-Method, vs multiple strings for each parameter eg DTUTIL "/COPY SQL; '\$Package'" "/DESTSERVRER '$Server'" "/FILE $package" "/Q"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.