這篇算是個小筆記。在之前的公司上班,每次上新版網站都很煩,因為 IIS 底下掛了好幾個網站,然後都要一個一個把網站跟 application pool 停掉,再把新網站更新上去,最後再把每個網站跟 application pool 都開啟。事情很簡單,但很花時間,於是我就試著利用之前學到的指令寫了一支簡單的 script,有興趣的人可以參考看看(範例中網站名稱跟 application pool 同名):

Stop-WebSite -Name "TestWebSite";
Stop-WebAppPool -Name "TestWebSite"
rm C:\inetpub\wwwroot\TestWebSite\*
Expand-Archive -LiteralPath 'C:\WebFileFolder\Publish.zip' -DestinationPath C:\inetpub\wwwroot\TestWebSite
Start-WebAppPool -Name "TestWebSite"
Start-WebSite -Name "TestWebSite";

中間有一個解壓縮的指令,是因為網站的檔案較多,壓成一個檔案,丟到遠端的主機會比較有效率。