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

前端 未结 6 1692
猫巷女王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:10

    Another way using Windows version:

    if ([System.Version](Get-ItemProperty -path "HKLM:\Software\Microsoft\Windows NT\CurrentVersion").CurrentVersion -ge [System.Version] "6.1")
    { Import-Module WebAdministration }
    else
    { Add-PSSnapin WebAdministration }
    

提交回复
热议问题