How to pass parameters to PowerShell script from T

2019-04-07 07:55发布

问题:

I created a little PowerShell script to change connection string in my web.config.

param([string]$webConfigPath, [string]$connectionStringName, [string]$connectionStringValue)

# get the full path of the web config file
$webConfigFile = [IO.Path]::Combine($webConfigPath, 'Web.config')
# load the XML
$webConfig = [xml](cat $webConfigFile)

#change the appropriate config
$webConfig.configuration.connectionStrings.add | foreach {
    if($_.name -eq  $connectionStringName){
        $_.connectionString = $connectionStringValue
    }
}

#save the file
$webConfig.Save($webConfigFile)

I added it to my build process. How to pass the build's variables to the script?

(I use the new script based build process, so I only have a builtin "Arguments" field for the parameter)

回答1:

You can put all parameters in a single line into Arguments files like this:

-webConfigPath "c:\web.config" -connectionStringName "My connection string"