0

I have a requirement where i need to install a application using a batch file. when i run this batch file it asks for inputs and that batch file internally calls a powershell script which ask the inputs, if i hit a enter key for some inputs it takes the default values.

Can any one let me know how to store all inputs in a file and pass it to a batch file and it should also support the same for powershell script as well as the default values.

BATCHFILE.cmd

@echo off
setlocal EnableDelayedExpansion
set scriptsPath=%~dp0
set scriptsPathShort=%~dps0
set psPath=%windir%\System32\WindowsPowerShell\v1.0\powershell.exe

:params
set Path=%~1
set psVersion=0

if "!psVersion!" == "2.0" "!psPath!" -version !psVersion! -command "!scriptsPathShort!install\install-driver.ps1" '!Path!' '****'
if not !errorlevel! == 0 goto error 
goto end    

 install-driver.ps1
param 
(
    [string] $scriptsBasePath = $(throw "Missing parameter: scriptsBasePath"),
    [string] $Path = $(throw "Missing parameter: packagePath"),
    [string] $packageRootFolder = $(throw "Missing parameter: packageRootFolder")
)
$configFileName = "install.config"

**install.config**

<Param name="ClientDir" required="1"
                label="Client Directory" 
                desc="Choose a unique name which will be used by the application to create folder in which client files will be stored" />

        <Param mode="adv" name="lPswdEncryptionMode" required="1" defaultValue="2" 
                label="Password Encryption Mode" /> 
<Param componentType="webserver" name="WebsiteName" required="1" defaultValue="Default Web Site" 
                label="Website Name" 
                desc="Enter site name under which the website component will be installed" cloud="1" />

This is only piece of code just to have a idea . it calls a config file where i have few parameters. Can any one please let me know how to pass the variables ?

user1190615
  • 111
  • 1
  • 4
  • 17

1 Answers1

1

Here is how I gather variables from my config/ini files into powershell.

$SETTINGS = Get-Content .\install.config

$scriptsBasePath = $SETTINGS[0]
$Path = $SETTINGS[1]
$packageRootFolder = $SETTINGS[2]

If install.config is not in the same directory, substitute the full path.

Knuckle-Dragger
  • 6,644
  • 4
  • 26
  • 41
  • in config.xml file there is a tag with and – user1190615 Aug 04 '14 at 17:13
  • my example assumed it was a blank text file with each variable on it's own line. If that config file is full of XML, don't use it with my example, create a new file just for your hand made variables. – Knuckle-Dragger Aug 04 '14 at 18:42
  • maybe later I will write an answer using the `Select-Xml` cmdlet - until then, here is a link to get you started in that direction. http://stackoverflow.com/questions/18509358/how-to-read-xml-in-powershell – Knuckle-Dragger Aug 05 '14 at 00:57
  • just to add .. `"$value = Read-Host -prompt $($param.label + $defaultLabel)"` this piece of code is in while loop and taking all the values from config file and asking the user to provide the value. but i want to set those parameters hardcoded and run the script. any Ideas ? – user1190615 Aug 07 '14 at 20:55