Parameter on Powershell Script

  • I'm having some problems sending parameters to a Powershell script when it includes a dash (-) in it. Here's an example on what I'm trying to do. The script is made to run an SSIS package from Powershell.

    param($dtsx = '')

    function GetDtExecPath {

    $DtsPath = (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\120\DTS\Setup').SQLPath;

    $DtExecPath = (Resolve-Path "$DtsPath\Binn\DTExec.exe");

    $DtExecPath;

    }

    function GetDtExecPropertyPathValue() {

    param(

    $PropertyPath = '',

    $Value = ''

    );

    $outPropPath = "\Package.Variables[User::" + $PropertyPath + "].Properties[Value]"

    #"$outPropPath;\`"`"$Value\`"`"";

    #"$outPropPath;$Value";

    "$outPropPath;" + '"' + $Value + '"';

    }

    function RunPackage {

    param(

    $DtExecPath = (GetDtExecPath),

    $File = 'test.dtsx'

    );

    $Params = "/FILE " + [CHAR]34 + $File + [CHAR]34;

    for($i = 0; $i -lt $Args.Length; $i += 2) {

    $PropertyPath = $Args[$i].SubString(1);

    $Value = $Args[$i+1];

    $PropertyPathValue = GetDtExecPropertyPathValue -PropertyPath $PropertyPath -Value $Value;

    $Params += " /SET $PropertyPathValue";

    }

    $FullCommand = '"' + $DtExecPath + '"' + $Params;

    $FullCommand

    &"$DtExecPath" $Params;

    #&"$DtExecPath" "$Params"

    }

    RunPackage -File $dtsx -prmMainScriptFolder "C:\Git\DB_Deployment_to_QA" -prmRallyID "US99999"

    And it's called through this:

    powershell.exe -file "deploy-ssis-package.ps1" -dtsx "C:\Git\SQL-Deployment\SQL-Deployer-eFR.dtsx"

    The problem is that I end up with the following result:

    "C:\Program Files\Microsoft SQL Server\120\DTS\Binn\DTExec.exe"/FILE "C:\Git\SQL-Deployment\SQL-Deployer-eFR.dtsx" /SET \Package.Variables[User::prmMainScriptFolder].Properties[Value];"C:\Git\DB_Deployment_to_QA" /SET \Package.Variables[User::prmRallyID].Properties[Value];"US99999"

    Microsoft (R) SQL Server Execute Package Utility

    Version 12.0.4100.1 for 64-bit

    Copyright (C) Microsoft Corporation. All rights reserved.

    Option "-deployment" is not valid.

    If I run the command generated by Powershell, it runs without a problem. Any ideas on why it's ignoring the quotes when called from PoSh??

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • Have you tried renaming the folders to use underlines instead of hyphens?

    I think the hyphens are the problem. That powershell might see them literally as a switch "notifier" kind of thing. Alternatively, see if you can escape the hyphen.

    EDIT: Or better yet, create a share with no hyphens in it. See if that works.

    Brandie Tarvin, MCITP Database AdministratorLiveJournal Blog: http://brandietarvin.livejournal.com/[/url]On LinkedIn!, Google+, and Twitter.Freelance Writer: ShadowrunLatchkeys: Nevermore, Latchkeys: The Bootleg War, and Latchkeys: Roscoes in the Night are now available on Nook and Kindle.

  • Brandie Tarvin (10/19/2016)


    Have you tried renaming the folders to use underlines instead of hyphens?

    I think the hyphens are the problem. That powershell might see them literally as a switch "notifier" kind of thing. Alternatively, see if you can escape the hyphen.

    EDIT: Or better yet, create a share with no hyphens in it. See if that works.

    I tried to escape the hyphens using the grave accent(`) without luck. I tried using single quotes, double quotes and combinations of both without luck.

    I don't want to create a new path because I might need to ask that the git repositories are created again or renamed. I believe that this might be too complex.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • I'll take a wild punt on $Params = "/FILE " => $Params = " /FILE " perhaps?

  • Change this line:

    $FullCommand = '& "' + $DtExecPath + '" --% ' + $Params;

    Then use

    Invoke-Expression $FullCommand

    MM



    select geometry::STGeomFromWKB(0x0106000000020000000103000000010000000B0000001000000000000840000000000000003DD8CCCCCCCCCC0840000000000000003DD8CCCCCCCCCC08408014AE47E17AFC3F040000000000104000CDCCCCCCCCEC3F9C999999999913408014AE47E17AFC3F9C99999999991340000000000000003D0000000000001440000000000000003D000000000000144000000000000000400400000000001040000000000000F03F100000000000084000000000000000401000000000000840000000000000003D0103000000010000000B000000000000000000143D000000000000003D009E99999999B93F000000000000003D009E99999999B93F8014AE47E17AFC3F400000000000F03F00CDCCCCCCCCEC3FA06666666666FE3F8014AE47E17AFC3FA06666666666FE3F000000000000003D1800000000000040000000000000003D18000000000000400000000000000040400000000000F03F000000000000F03F000000000000143D0000000000000040000000000000143D000000000000003D, 0);

  • Forum Etiquette: How to post Reporting Services problems
  • [/url]
  • Forum Etiquette: How to post data/code on a forum to get the best help - by Jeff Moden
  • [/url]
  • How to Post Performance Problems - by Gail Shaw
  • [/url]

  • Luis Cazares (10/19/2016)


    Brandie Tarvin (10/19/2016)


    Have you tried renaming the folders to use underlines instead of hyphens?

    I think the hyphens are the problem. That powershell might see them literally as a switch "notifier" kind of thing. Alternatively, see if you can escape the hyphen.

    EDIT: Or better yet, create a share with no hyphens in it. See if that works.

    I tried to escape the hyphens using the grave accent(`) without luck. I tried using single quotes, double quotes and combinations of both without luck.

    I don't want to create a new path because I might need to ask that the git repositories are created again or renamed. I believe that this might be too complex.

    And a share won't work for that?

    Let us know if Magoo's suggestion works. The only thing I found with hyphenated folders on Google had to do with issues at the server, not with the names.

    Brandie Tarvin, MCITP Database AdministratorLiveJournal Blog: http://brandietarvin.livejournal.com/[/url]On LinkedIn!, Google+, and Twitter.Freelance Writer: ShadowrunLatchkeys: Nevermore, Latchkeys: The Bootleg War, and Latchkeys: Roscoes in the Night are now available on Nook and Kindle.

  • Oh Magoo, you've done it again! 😀

    That worked perfectly. Now I wonder what would they prefer, if the Powershell option or the bat file option.

    Here's the ps1 final script .

    param($dtsx = '', $RallyID = '', $MainScriptFolder = '')

    function GetDtExecPath {

    $DtsPath = (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\120\DTS\Setup').SQLPath;

    $DtExecPath = (Resolve-Path "$DtsPath\Binn\DTExec.exe");

    $DtExecPath;

    }

    function GetDtExecPropertyPathValue() {

    param(

    $PropertyPath = '',

    $Value = ''

    );

    $outPropPath = "\Package.Variables[User::" + $PropertyPath + "].Properties[Value]"

    "$outPropPath;" + '"' + $Value + '"';

    }

    function RunPackage {

    param(

    $DtExecPath = (GetDtExecPath),

    $File = 'test.dtsx'

    );

    $Params = "/FILE " + [CHAR]34 + $File + [CHAR]34;

    for($i = 0; $i -lt $Args.Length; $i += 2) {

    $PropertyPath = $Args[$i].SubString(1);

    $Value = $Args[$i+1];

    $PropertyPathValue = GetDtExecPropertyPathValue -PropertyPath $PropertyPath -Value $Value;

    $Params += " /SET $PropertyPathValue";

    }

    $FullCommand = '& "' + $DtExecPath + '" --% ' + $Params;

    Invoke-Expression $FullCommand

    }

    RunPackage -File $dtsx -prmMainScriptFolder $MainScriptFolder -prmRallyID $RallyID

    Thank you for all your help.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • Luis Cazares (10/20/2016)


    Oh Magoo, you've done it again! 😀

    Heh... glad I'm not the only one that says that. 😀

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • I was wondering whether all this complexity is worth it...just to run a dtsx? But I'm not a DBA, so I assume this is a small part of a bigger development...

    MM



    select geometry::STGeomFromWKB(0x0106000000020000000103000000010000000B0000001000000000000840000000000000003DD8CCCCCCCCCC0840000000000000003DD8CCCCCCCCCC08408014AE47E17AFC3F040000000000104000CDCCCCCCCCEC3F9C999999999913408014AE47E17AFC3F9C99999999991340000000000000003D0000000000001440000000000000003D000000000000144000000000000000400400000000001040000000000000F03F100000000000084000000000000000401000000000000840000000000000003D0103000000010000000B000000000000000000143D000000000000003D009E99999999B93F000000000000003D009E99999999B93F8014AE47E17AFC3F400000000000F03F00CDCCCCCCCCEC3FA06666666666FE3F8014AE47E17AFC3FA06666666666FE3F000000000000003D1800000000000040000000000000003D18000000000000400000000000000040400000000000F03F000000000000F03F000000000000143D0000000000000040000000000000143D000000000000003D, 0);

  • Forum Etiquette: How to post Reporting Services problems
  • [/url]
  • Forum Etiquette: How to post data/code on a forum to get the best help - by Jeff Moden
  • [/url]
  • How to Post Performance Problems - by Gail Shaw
  • [/url]

  • mister.magoo (10/20/2016)


    I was wondering whether all this complexity is worth it...just to run a dtsx? But I'm not a DBA, so I assume this is a small part of a bigger development...

    I'm not sure it's worth it either, but it wasn't my decision. We just need a command line option to run the package from a third party tool and they thought that using PowerShell was the way to go. The whole time, I believed that using the basic command shell was enough and it was.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • Luis Cazares (10/20/2016)


    mister.magoo (10/20/2016)


    I was wondering whether all this complexity is worth it...just to run a dtsx? But I'm not a DBA, so I assume this is a small part of a bigger development...

    I'm not sure it's worth it either, but it wasn't my decision.

    GAH. I hate it when that happens.

    Brandie Tarvin, MCITP Database AdministratorLiveJournal Blog: http://brandietarvin.livejournal.com/[/url]On LinkedIn!, Google+, and Twitter.Freelance Writer: ShadowrunLatchkeys: Nevermore, Latchkeys: The Bootleg War, and Latchkeys: Roscoes in the Night are now available on Nook and Kindle.

  • Brandie Tarvin (10/20/2016)


    Luis Cazares (10/20/2016)


    mister.magoo (10/20/2016)


    I was wondering whether all this complexity is worth it...just to run a dtsx? But I'm not a DBA, so I assume this is a small part of a bigger development...

    I'm not sure it's worth it either, but it wasn't my decision.

    GAH. I hate it when that happens.

    That's half the fun (or the learning).

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • what do you mean????? "The code below clears the Local Servers Group completely (be aware of this),"???

    can I run it without this clearing of the LSG????

    'dir -Recurse | Remove-Item -force; #clean up everything' + CHAR(13) + CHAR(10)

    Local Servers Group??? that's on AD as a GPO, or Group or Container right???

    Thanks

  • trangen1 (10/25/2016)


    what do you mean????? "The code below clears the Local Servers Group completely (be aware of this),"???

    can I run it without this clearing of the LSG????

    'dir -Recurse | Remove-Item -force; #clean up everything' + CHAR(13) + CHAR(10)

    Local Servers Group??? that's on AD as a GPO, or Group or Container right???

    Thanks

    Did you post this in the wrong thread?

    Brandie Tarvin, MCITP Database AdministratorLiveJournal Blog: http://brandietarvin.livejournal.com/[/url]On LinkedIn!, Google+, and Twitter.Freelance Writer: ShadowrunLatchkeys: Nevermore, Latchkeys: The Bootleg War, and Latchkeys: Roscoes in the Night are now available on Nook and Kindle.

  • Brandie Tarvin (10/25/2016)


    trangen1 (10/25/2016)


    what do you mean????? "The code below clears the Local Servers Group completely (be aware of this),"???

    can I run it without this clearing of the LSG????

    'dir -Recurse | Remove-Item -force; #clean up everything' + CHAR(13) + CHAR(10)

    Local Servers Group??? that's on AD as a GPO, or Group or Container right???

    Thanks

    Did you post this in the wrong thread?

    That might be the case, the quote belongs to the article posted today and the thread for the article can be found here: http://www.sqlservercentral.com/Forums/Topic1828919-3838-1.aspx

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • Viewing 15 posts - 1 through 15 (of 15 total)

    You must be logged in to reply to this topic. Login to reply