October 19, 2016 at 8:52 am
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??
October 19, 2016 at 11:17 am
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.
October 19, 2016 at 12:41 pm
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.
October 19, 2016 at 1:58 pm
I'll take a wild punt on $Params = "/FILE " => $Params = " /FILE " perhaps?
October 19, 2016 at 5:09 pm
Change this line:
$FullCommand = '& "' + $DtExecPath + '" --% ' + $Params;
Then use
Invoke-Expression $FullCommand
MM
select geometry::STGeomFromWKB(0x0106000000020000000103000000010000000B0000001000000000000840000000000000003DD8CCCCCCCCCC0840000000000000003DD8CCCCCCCCCC08408014AE47E17AFC3F040000000000104000CDCCCCCCCCEC3F9C999999999913408014AE47E17AFC3F9C99999999991340000000000000003D0000000000001440000000000000003D000000000000144000000000000000400400000000001040000000000000F03F100000000000084000000000000000401000000000000840000000000000003D0103000000010000000B000000000000000000143D000000000000003D009E99999999B93F000000000000003D009E99999999B93F8014AE47E17AFC3F400000000000F03F00CDCCCCCCCCEC3FA06666666666FE3F8014AE47E17AFC3FA06666666666FE3F000000000000003D1800000000000040000000000000003D18000000000000400000000000000040400000000000F03F000000000000F03F000000000000143D0000000000000040000000000000143D000000000000003D, 0);
October 20, 2016 at 5:37 am
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.
October 20, 2016 at 7:38 am
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.
October 20, 2016 at 8:01 am
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
Change is inevitable... Change for the better is not.
October 20, 2016 at 8:02 am
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);
October 20, 2016 at 8:18 am
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.
October 20, 2016 at 8:57 am
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.
October 20, 2016 at 9:46 am
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).
October 25, 2016 at 9:38 am
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
October 25, 2016 at 10:34 am
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?
October 25, 2016 at 10:41 am
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
Viewing 15 posts - 1 through 15 (of 15 total)
You must be logged in to reply to this topic. Login to reply