dimanche 29 mars 2015

batch file variable issue

Batch newbie here. I have a slight issue with a variable not being captured correctly. I have a SCCM Object variable for ABC_RegionCode, ABC_DBNAME, ABC_Schema and srvpocWeb_%%% (where % equals a sitecode). my problem is srvPocWeb_%1="%4" does NOT give me what i'm expecting, which is srvPocWeb_(regionCodeVariable). The rest of this script works fine. it will go and get the value of the variables i've specified. the issue i'm having is getting the value (which is a password) in the %4 variable since it changes sitecode variables for every machine it runs on. Is it possible to have "set srvPocWeb_%1="%4" pull in the variable value from an SCCM object with the name srvPocWeb_999 and then one right after with the name srvPocWeb_912 (for example).


the way im executing this batch is as follows:


example.bat %ABC_RegionCode% %ABC_DBNAME% %ABC_SCHEMA% !srvPocWeb_%1! >> C:\test.txt


the output im getting in the txt file is looking all correct except for the password feild is not the value from the password variable but rather its name field.



@echo off
Setlocal EnableDelayedExpansion

Rem Pull in variables from SCCM OBject -

@echo set ABC_RegionCode="%1"
@echo set ABC_DBNAME="%2"
@echo set ABC_SCHEMA="%3"
@echo set srvPocWeb_%1="%4"



@echo "C:\Program Files\Application_%1\Database\Tools\Client\Client.exe" sourcepath="C:\Source" databasetype="oracle" databaseconnection="data Source=%2;User Id=%3;Password=!srvPocWeb_%1!" reportsfolderpath="C:\reports"

@echo "C:\Program Files\Application_%1\Database\Tools\Client\Client.exe" sourcepath="C:\Source" reImportBuild=true outputonly=false databasetype="oracle" databaseconnection="data Source=%2;User Id=%3;Password=!srvPocWeb_%1!" reportsfolderpath="C:\reports"
@echo All Done

Aucun commentaire:

Enregistrer un commentaire