I am using the IIS Powershell snapin to configure a new web application from scratch. I am new to PS. The following script will not workl as PS is not recognising the ManagedPipelineMode enum. If I change the value to 0 it will work. How can I get PS to understand th enum. I tried the Add-Type cmdlet and also load the Microsoft.Web.Administration assembly without any scuccess, these lines are now commented.
How can I get this PS script working with the enum ?
#Add-Type -AssemblyName Microsoft.Web.Administration
#[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Web.Administration")
Import-Module WebAdministration
$AppPoolName = 'Test AppPool'
if ((Test-Path IIS:\apppools\$AppPoolName) -eq $false) {
Write-Output 'Creating new app pool ...'
New-WebAppPool -Name $AppPoolName
$AppPool = Get-ChildItem iis:\apppools | where { $_.Name -eq $AppPoolName}
$AppPool.Stop()
$AppPool | Set-ItemProperty -Name "managedRuntimeVersion" -Value "v4.0"
$AppPool | Set-ItemProperty -Name "managedPipelineMode" -Value [Microsoft.Web.Administration.ManagedPipelineMode]::Integrated
$AppPool.Start()
}
The error message is:
Set-ItemProperty : [Microsoft.Web.Administration.ManagedPipelineMode]::Integrated is not a valid value for Int32.
It is expecting an integer, even though the underlying property is of type ManagaedPipelineMode
. You can do below however:
$AppPool | Set-ItemProperty -Name "managedPipelineMode" -Value ([int] [Microsoft.Web.Administration.ManagedPipelineMode]::Classic)
PS:
Instead of
$AppPool = Get-ChildItem iis:\apppools | where { $_.Name -eq $AppPoolName}
you can do:
$AppPool = Get-Item iis:\apppools\$AppPoolName
Regarding: Add-Type -AssemblyName
- this will only work for a canned set of assemblies that PowwerShell knows about. You have to find the assembly in your file system and use the -Path
parameter. This worked on my system in a 64-bit PowerShell console:
Add-Type -Path C:\Windows\System32\inetsrv\Microsoft.Web.Administration.dll
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With