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

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

    This is great. All I had to do was add an else so it would add the snap-in when run on Windows 2008. This works in scripts for my situation.

    Function Load-WebAdmin {
      $webAdminModule = get-module -ListAvailable | ? { $_.Name -eq "webadministration" }
      If ($webAdminModule -ne $null) {
        import-module WebAdministration
      }else{
        Add-pssnapin WebAdministration
       }
    }
    

提交回复
热议问题