I was trying to migrate my batch script to powershell.
I have tried writing the script and run it from powershell ise.
$sites = @("abc","xyz","pqr")
foreach ($site in $sites)
{
msdeploy -verb:sync -verbose -source:runcommand -dest:runcommand="$env:windir\system32\inetsrv\appcmd stop site /site.name":$site
}
When I run the command(msdeploy) it runs perfect from command prompt.
I get the following error (attached):
I would appreciate if someone can help me on this. Thanks in advance.
After so much of struggle I figured it out, and resolved the issue.
foreach($site in $sites){
msdeploy -verb:sync -verbose -source:runcommand -dest:runcommand=`"$env:windir\system32\inetsrv\appcmd stop site /site.name`":"$site",computername="$serverName",username="$user",password="$passCode"
}
It was just a escape character that helped me to run the script("`").
I hope it helps someone without pulling their hair.