PowerShell: Load WebAdministration in ps1 script on both IIS 7 and IIS 7.5

前端 未结 6 1690
猫巷女王i
猫巷女王i 2021-01-31 04:57

I have a PowerShell script that configures web site and web application settings in IIS. So I use the cmdlets in the WebAdministration snap in. But this script needs to run on

6条回答
  •  醉话见心
    2021-01-31 05:21

    This is probably a bit late to help you, but here is how we do this:

    $iisVersion = Get-ItemProperty "HKLM:\software\microsoft\InetStp";
    if ($iisVersion.MajorVersion -eq 7)
    {
        if ($iisVersion.MinorVersion -ge 5)
        {
            Import-Module WebAdministration;
        }           
        else
        {
            if (-not (Get-PSSnapIn | Where {$_.Name -eq "WebAdministration";})) {
                Add-PSSnapIn WebAdministration;
            }
        }
    }
    

提交回复
热议问题