Quantcast
Channel: SQLServerCentral » Programming » Powershell » Latest topics
Viewing all articles
Browse latest Browse all 467

Parameter on Powershell Script

$
0
0
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.[code="other"]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"[/code]And it's called through this:[code="other"]powershell.exe -file "deploy-ssis-package.ps1" -dtsx "C:\Git\SQL-Deployment\SQL-Deployer-eFR.dtsx"[/code]The problem is that I end up with the following result:[code="plain"]"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 UtilityVersion 12.0.4100.1 for 64-bitCopyright (C) Microsoft Corporation. All rights reserved.Option "-deployment" is not valid.[/code]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??

Viewing all articles
Browse latest Browse all 467

Trending Articles