I’m trying to write a script to install and sync certain applications on two IIS. Right now I’m using a .bat file in combination with PowerShell scripts to active this:
@echo OFF
rem set paramiters
set "webSiteName=SiteName"
set "siteRootDirectoryPath=C:wwwroot"
set "ApiName=Api"
set "AppName=App"
set "psIntallScriptPath=C:versionDeployApiAndAppToIIS.ps1"
set "psAppPoolScriptPath=C:versionEnsureAppPool.ps1"
set "currentDirectory=%~dp0"
rem Call the PowerShell script with the parameters
powershell -NoProfile -ExecutionPolicy Bypass -File "%psScriptPath%" -siteRootDirectory %siteRootDirectoryPath% -sourceDirectory %currentDirectory% -siteName %webSiteName% -appNames %ApiName%,%AppName%
rem Check the exit code of the PowerShell script
if %ERRORLEVEL% NEQ 0 (
if %ERRORLEVEL% NEQ 101 (
echo "Error %ERRORLEVEL%. update API and App"
pause
exit /b %ERRORLEVEL%
)
if %ERRORLEVEL% EQU 101 (
echo "Could not find API/App zip files, they will not be installed"
)
)
if %ERRORLEVEL% EQU 0 (
echo "Api and app for %webSiteName% updated"
)
rem Sync IIS site
echo "Sync website %webSiteName% to Web2"
"C:Program FilesIISMicrosoft Web Deploy V3msdeploy.exe" -verb:sync -source:iisApp="%webSiteName%" -skip:Directory="\Log$" -skip:Directory="\%ApiName%" -dest:iisApp="%webSiteName%",computername=Web2
IF %ERRORLEVEL% NEQ 0 (
echo "Error %ERRORLEVEL%. Sync website %webSiteName% to Web2"
pause
exit %ERRORLEVEL%
)
rem Create a separate AppPool for the API
echo "Creating App Pool for API %ApiName%"
"C:Program FilesIISMicrosoft Web Deploy V3msdeploy.exe" -verb:sync -source:appPoolConfig="%webSiteName%%ApiName%" -dest:appPoolConfig="%webSiteName%%ApiName%",computername=Web2
IF %ERRORLEVEL% NEQ 0 (
echo "Error creating App Pool. Error %ERRORLEVEL%"
pause
exit %ERRORLEVEL%
)
rem Sync the API sub-application and assign the new App Pool
echo "Sync sub-application HiCoreApi and assign its app pool"
"C:Program FilesIISMicrosoft Web Deploy V3msdeploy.exe" -verb:sync -source:iisApp="%webSiteName%%ApiName%" -skip:Directory="\Log$" -dest:iisApp="%webSiteName%%ApiName%",computername=Web2
IF %ERRORLEVEL% NEQ 0 (
echo "Error %ERRORLEVEL%. Sync website %webSiteName% to Web2"
pause
exit %ERRORLEVEL%
)
pause
goto :eof
the PowerShell first copies all folders on IIS-1, ensures settings, and creates app-pools for the two applications and the site itself, so three app-pools in total, and that all works great. Then the script syncs the site folder, syncs the app-pool and the app folder to IIS-2, but here is the issue. when syncing the apps use the same app-pool as the site, not the pool that is set in IIS-1 and copied to IIS-2.
I’ve tried gooleling and GPT, but i have no good answers. I know i can use PowerShell remotely, but I’m getting some authentication issues what I’m not having with msdeploy.exe so that is what I’d like to use.
5