ASPNET: 使用PowerShell部署ASP.NetCore程序到IIS

直接看如下代码就好。

 

Import-Module WebAdministration

Write-Host "Checking IIS status..."
$iis = Get-Service W3SVC -ErrorAction Ignore
if($iis){
    if($iis.Status -eq "Running") {
        Write-Host "IIS Service is running"
    }
    else {
        Write-Host "IIS Service is not running"
    }
}
else {
    Write-Host "Checking IIS failed, please make sure IIS is ready."   
}

$aspNetCoreModule = Get-WebGlobalModule -Name AspNetCoreModule -ErrorAction Ignore

if($aspNetCoreModule)
{
     Write-Host "IIS ASPNetCoreModule is ready:"
     Write-Host $aspNetCoreModule.Name $aspNetCoreModule.Image
}
else
{
    #download aspnetcoremodule
    Invoke-WebRequest -Uri "https://download.visualstudio.microsoft.com/download/pr/34f4b2a6-c3b8-495c-a11f-6db955f27757/8c340c1a8c25966e39e0c0a4b308dff4/dotnet-hosting-2.2.5-win.exe" -OutFile "dotnet-hosting-2.2.5-win.exe"
    Start-Process "dotnet-hosting-2.2.5-win.exe" -Wait  -ArgumentList '/S', '/v', '/qn' -passthru
    Write-Host "IIS ASPNetCoreModule is installed successfully"

}

$site =get-website|Where-Object {$_.Name -like '*mmcapi*'}

$siteName = $site.Name  # xxx.com
$poolName =$site.Name
$physicalPath = $site.PhysicalPath   #D:\Apps\xxx.com

Write-Host 'site name:' $sitename ', pool name:' $poolName ', physical path:' $physicalPath

# 把应用程序池的.Net版本设置为无托管代码
Set-ItemProperty -Path IIS:\AppPools\$poolName -Name managedRuntimeVersion -Value ''

# Set identity user
Set-ItemProperty IIS:\AppPools\$poolName -name processModel.identityType -Value SpecificUser
Set-ItemProperty IIS:\AppPools\$poolName -name processModel.userName -Value $username
Set-ItemProperty IIS:\AppPools\$poolName -name processModel.password -Value $password
get-ItemProperty -Path IIS:\AppPools\$poolName -Name processmodel

# restart IIS
Invoke-Expression "net stop was /y"
Invoke-Expression "net start w3svc"

Start-WebAppPool -Name $poolName

 

也可参考我的另一篇文章: 

https://blog.csdn.net/wucong60/article/details/85803663

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值