E.Meir
E.Meir

Reputation: 2226

using MsDeploy-Sync to copy only one file locally

Currently i am copying all the $DeploymentPath (folder) locally, and then deleting all the files in it, except 1 file that i want.

MsDeploy-Sync `
       -SourceContentPath:"$DeploymentPath" `
       -DestinationContentPath:"$SupportFolder/WebPages" `

Get-ChildItem "$SupportFolder\WebPages" -Exclude "web.config.js" |
  Remove-Item

What i want to do:

copy only 1 file web.config.js locally, if it doesn't exist there, return false.

Is it possible?

Upvotes: 1

Views: 77

Answers (1)

Martin Brandl
Martin Brandl

Reputation: 58991

First of all, you should use the Join-Path cmdlet to combine a path in PowerShell.

To check whether the file exist, just use the Test-Path cmdlet:

$webConfigPath = Join-Path $SupportFolder '\WebPages\web.config.js'
if (Test-Path $webConfigPath)
{
     MsDeploy-Sync `
        -SourceContentPath (Join-Path $DeploymentPath 'web.config.js') `
        -DestinationContentPath (Join-Path $SupportFolder 'fromServer_web.config.js')
}
else
{
    $false # return $false
}

Upvotes: 1

Related Questions