Leblanc Meneses
Leblanc Meneses

Reputation: 3091

extending an existing powershell script

We currently have a PreDeploy.ps1, Deploy.ps1, PostDeploy.ps1 scripts specific to web applications or window services. Every once in a while we need to have an extension file to customize the deployment process.

We plan to implement extension files using an underscore - something like:

Deploy.ps1

    if( Test-Path "_Deploy.ps1" )
{
    $extensionFile = Resolve-Path "_Deploy.ps1"
    PowerShell -File $extensionFile 
}

How can i pass currently scoped variables (variable name and value) to the extensionFile?

Upvotes: 1

Views: 113

Answers (1)

Keith Hill
Keith Hill

Reputation: 202032

Well don't start a new PowerShell instance. :-) Run the script in the current PowerShell instance e.g.:

& $extensionFile

If that $extensionFile needs to modify (or create) variables in the current scope then execute it like so:

. $extensionFile

Upvotes: 2

Related Questions