Yes, with a -source:runCommand, but first you should put the script there (a batch for example)
from: http://sourcecodebean.com/archives/synchronizing-files-and-executing-commands-on-a-remote-server-using-msdeploy/775
Bellow is a simple PowerShell script that has two functions.
Send-Files – Synchronizes a local folder to a remote server.
Execute-RemoteCommand – Executes a batch file on a remote server. The file must already be in place on the server.
$MSDeployExe = "C:\Program Files\IIS\Microsoft Web Deploy\msdeploy.exe"
$RemoteHost = "http://localhost:80/MsDeployAgentService"
$Credentials = ""
$LocalDir = "C:\temp\LocalDir"
$RemoteDir = "C:\temp\RemoteDir"
function Send-Files {
param (
[string]$WebDeployService,
[string]$LocalDir,
[string]$RemoteDir,
[string]$Credentials
)
Write-Host "Sending files to $WebDeployService`: $RemoteDir" -ForegroundColor Yellow
if ($Credentials -ne "") {
$Credentials = ",getCredentials=" + $Credentials
}
& $MSDeployExe "-verb:sync" "-source:dirPath=$LocalDir" "-dest:dirPath=$RemoteDir,computername=$WebDeployService$Credentials" "-verbose"
$successful = $?
if (-not $successful) {
throw "Failed sending files"
}
}
function Execute-RemoteCommand {
param (
[string]$WebDeployService,
[string]$RemoteDir,
[string]$BatchFile,
[string]$Credentials,
[int]$waitInterval = 15000
)
$command = Join-Path $RemoteDir $BatchFile
Write-Host "Executing $command on $WebDeployService" -ForegroundColor Yellow
& $MSDeployExe "-verb:sync" "-source:runCommand=’$command’,waitInterval=$waitInterval,waitAttempts=1" "-dest:auto,computername=$RemoteHost$Credentials" "-verbose"
$successful = $?
if (-not $successful) {
throw "Failed executing command"
}
}
# Test
Send-Files $RemoteHost $LocalDir $RemoteDir $Credentials
Execute-RemoteCommand $RemoteHost $RemoteDir "HelloWorld.bat" $Credentials