I have written a PowerShell script block for creating IIS app pool and website on Azure Virtual Machine Scale Set multiple instances, while the script block runs parallel, I get the error The object identifier does not represent a valid object. (Exception from HRESULT: 0x800710D8), can someone help?
Resetting IIS didn't help, I also made sure the app pool is created and waited for 5 seconds to complete the process, still the same issue.
this is what I have written within a script block
Import-Module -Name WebAdministration
# get SSL certificate thumbprint to attach
$thumbprint = Get-ChildItem -Path Cert:\LocalMachine\My | where-Object { $_.subject -like $certName } | Select-Object -ExpandProperty Thumbprint
# check the existing app pool
$apppoolExists = Get-IISAppPool -Name $appPoolName
if (!($apppoolExists.Name -ieq $appPoolName)) {
# create a new web application pool
New-WebAppPool -Name $appPoolName -Force
Start-WebAppPool -Name $appPoolName
Start-Sleep -Seconds 5
Write-Host "Application pool : $appPoolName created successfully"
} else {
Write-Host "App pool $appPoolName already exists"
}
# set user identity with custom account for app pool
Set-ItemProperty IIS:\AppPools\$appPoolName -name processModel -value @{userName = $username; password = $password; identitytype = 3 }
# set website path code
------- assume setting path -------
# check existing website
$siteExists = Get-Website -Name $siteName
if (!($siteExists.name -ieq $siteName)) {
# create a new website
New-WebSite -Name $siteName -PhysicalPath $physicalPathWebsite -ApplicationPool $appPoolName -Force
Write-Host "Web site : $siteName created successfully"
} else {
Write-Host "Website $siteName already exists"
}
# remove http binding
Get-WebBinding -Name $siteName -Protocol http -Port 80 | Remove-WebBinding
Get-WebBinding -Name $siteName -Protocol https -Port 443 | Remove-WebBinding
# add binding to website
New-WebBinding -Name $siteName -Port $port -Protocol $protocol -HostHeader $CName -SslFlags 1 -Force
# add an SSL certificate to binding
$binding = Get-WebBinding -Name $SiteName -Port $Port -Protocol 'https'
$binding.AddSslCertificate($thumbprint, 'my')
# start website
Start-Website -Name $siteName
Write-Host "website : $siteName started"
Write-Host "IIS website and application pool creation successful"
User contributions licensed under CC BY-SA 3.0