I'm trying to build up a command line and fire it into MSDeploy.exe as part of a PowerShell module. It seems PowerShell continues to struggle when it comes to native processes and dynamic command lines (as of Windows PowerShell 4). In this case it wraps the source and dest attributes in double quotes which MSDeploy can't handle. Here is my function:
function Set-WebSiteOffline { param( [Parameter(Mandatory=$true)][string]$ServerName, [Parameter(Mandatory=$true)][string]$SiteName, [string]$UserName, [string]$Password ) $EncodedSiteName = [System.Web.HttpUtility]::UrlEncode($SiteName); $SiteManagementEndpoint = "https://$ServerName.contoso.com:8172/MSDeploy.axd?Site=$EncodedSiteName"; $Verb = "-verb:sync"; $Source = "-source:contentPath='`"$SiteName/App_Offline.htm.deploy`"',computername='$SiteManagementEndPoint'" $Destination = "-dest:contentPath='`"$SiteName/App_Offline.htm`"',computername='$SiteManagementEndPoint'" $Verbose = "-verbose"; $DoNotDeleteRule = "-enableRule:DoNotDeleteRule"; if($UserName -ne "") { $Source = $Source + ",username='$ENV:UserDomain\$UserName',password='$Password'"; $Destination = $Destination + ",username='$ENV:UserDomain\$UserName',password='$Password'"; } $MSDeployArguments = $Verb, $Source, $Destination, $Verbose, $DoNotDeleteRule;& $MSDeploy $MSDeployArguments }
I've looked at the new cmdlets but I don't see a great plan B. The best option it appears is to dump the actions I want to do to a manifest file then invoke Sync-WDManifest. Feels like a bit of a pain if you ask me when there could have just been a cmdlet that accepts verb, source, dest and the other command line parameters.
Are there any other options that the team is aware of for calling MSDeploy via PSH? If I have to go the manifest route then how would I pass in the DoNotDeleteRule?