|
在 IIS 7.5(Windows 7、Win2008 R2)中无法使用管理单元进行 WebAdministration,只能使用 import-module
- # Web管理在Windows 2008 R2上作为一个模块加载,但作为Windows 2008的一组管理单元加载(不是R2)
- function Util-Load-Web-Administration
- {
- $ModuleName = "WebAdministration"
- $ModuleLoaded = $false
- $LoadAsSnapin = $false
- if ($PSVersionTable.PSVersion.Major -ge 2)
- {
- if ((Get-Module -ListAvailable | ForEach-Object {$_.Name}) -contains $ModuleName)
- {
- Import-Module $ModuleName
- if ((Get-Module | ForEach-Object {$_.Name}) -contains $ModuleName)
- { $ModuleLoaded = $true } else { $LoadAsSnapin = $true }
- }
- elseif ((Get-Module | ForEach-Object {$_.Name}) -contains $ModuleName)
- { $ModuleLoaded = $true } else { $LoadAsSnapin = $true }
- }
- else
- { $LoadAsSnapin = $true }
- if ($LoadAsSnapin)
- {
- try
- {
- if ((Get-PSSnapin -Registered | ForEach-Object {$_.Name}) -contains $ModuleName)
- {
- if ((Get-PSSnapin -Name $ModuleName -ErrorAction SilentlyContinue) -eq $null)
- { Add-PSSnapin $ModuleName }
- if ((Get-PSSnapin | ForEach-Object {$_.Name}) -contains $ModuleName)
- { $ModuleLoaded = $true }
- }
- elseif ((Get-PSSnapin | ForEach-Object {$_.Name}) -contains $ModuleName)
- { $ModuleLoaded = $true }
- }
- catch
- {
- Write-Error "`t`t$($MyInvocation.InvocationName): $_"
- Exit
- }
- }
- }
复制代码 |
|