Last active
September 14, 2016 16:18
-
-
Save sayedihashimi/1390cd6c97f25eefabdc to your computer and use it in GitHub Desktop.
Shows how to call msdeploy.exe from powershell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Execute-CommandString{ | |
[cmdletbinding()] | |
param( | |
[Parameter(Mandatory=$true,Position=0,ValueFromPipeline=$true)] | |
[string[]]$command, | |
[switch] | |
$ignoreExitCode | |
) | |
process{ | |
foreach($cmdToExec in $command){ | |
'Executing command [{0}]' -f $cmdToExec | Write-Verbose | |
cmd.exe /D /C $cmdToExec | |
if(-not $ignoreExitCode -and ($LASTEXITCODE -ne 0)){ | |
$msg = ('The command [{0}] exited with code [{1}]' -f $cmdToExec, $LASTEXITCODE) | |
throw $msg | |
} | |
} | |
} | |
} | |
# in this case there is no space in any argument and the call to msdeploy.exe succeeds | |
$msdeployExe = 'C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe' | |
$packOutput = 'C:\temp\publish\01' | |
$pubOut = 'c:\temp\publish-no-space\' | |
$publishArgs = @() | |
$publishArgs += ('-source:contentPath=''{0}''' -f "$packOutput") | |
$publishArgs += ('-dest:contentPath=''{0}''' -f "$pubOut") | |
$publishArgs += '-verb:sync' | |
$publishArgs += '-disablerule:BackupRule' | |
'Calling msdeploy to publish to file system with the command: [{0} {1}]' -f $msdeployExe,($publishArgs -join ' ') | Write-Output | |
$command = '"{0}" {1}' -f $msdeployExe,($publishArgs -join ' ') | |
Execute-CommandString -command $command | |
# in this case the call to msdeploy.exe fails with an argument error | |
$pubOut2 = 'c:\temp\publish with space\' | |
$publishArgs2 = @() | |
$publishArgs2 += ('-source:contentPath=''{0}''' -f "$packOutput") | |
$publishArgs2 += ('-dest:contentPath=''{0}''' -f "$pubOut2") | |
$publishArgs2 += '-verb:sync' | |
$publishArgs2 += '-disablerule:BackupRule' | |
'Calling msdeploy to publish to file system with the command: [{0} {1}]' -f $msdeployExe,($publishArgs -join ' ') | Write-Output | |
$command = '"{0}" {1}' -f $msdeployExe,($publishArgs2 -join ' ') | |
Execute-CommandString -command $command |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment