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.
You need to use Invoke-Expression
which will allow you to execute a string as a command. Store your command as a string and pass it to Invoke-Expression
as a parameter.
$sites = @("abc","xyz","pqr")
$commandPrefix = 'msdeploy -verb:sync -verbose -source:runcommand -dest:runcommand="$env:windir\system32\inetsrv\appcmd stop site /site.name"'
foreach ($site in $sites)
{
$command = $commandPrefix ":" $site
Invoke-Expression $command
}
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.
You can also try using the recycleApp provider:
msdeploy -verb:sync -source:recycleApp -dest:recycleApp="MySite",recycleMode="StopAppPool"
//deploy and sync content
msdeploy -verb:sync -source:recycleApp -dest:recycleApp="MySite",recycleMode="StartAppPool"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.