Reputation: 111
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 ?
Upvotes: 0
Views: 967
Reputation: 7046
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.
Upvotes: 1