在Windows7 PsSnapin Web管理

我想使用PowerShell在Windows7 64位上管理我的IIS7。

我尝试安装IIS7 Powershell管理单元http://www.iis.net/download/PowerShell

我“以管理员身份运行”,然后输入下面列出的命令:msiexec / I iis7psprov_x64.msi但我得到以下错误消息:“PowerShell管理单元是Windows操作系统的一部分,请通过程序和功能或服务器管理器安装”

我认为这个特殊的功能不需要加载Web管理模块,但我激活了“程序和功能|”中的所有选项

打开或关闭Windows功能| IIS | 网页管理工具| IIS管理脚本和工具

我做这些检查:

1.)Power-Shell已安装

PS C:Program FilesIIS> $Host.Version


    Major  Minor  Build  Revision
     -----  -----  -----  --------
     2      0      -1     -1



PS C:Program FilesIIS> $PSVersionTable
    Name                           Value
     ----                           -----
     CLRVersion                     2.0.50727.5448
     BuildVersion                   6.1.7601.17514
     PSVersion                      2.0
     WSManStackVersion              2.0
     PSCompatibleVersions           {1.0, 2.0}
     SerializationVersion           1.1.0.1
     PSRemotingProtocolVersion      2.1



PS C:Program FilesIIS> get-host
    Name             : ConsoleHost
     Version          : 2.0
     InstanceId       : 445ad8f5-87fc-48f7-b010-f7faf948b86c
     UI               : System.Management.Automation.Internal.Host.InternalHostUserInterface
     CurrentCulture   : es-ES
     CurrentUICulture : es-ES
     PrivateData      : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
     IsRunspacePushed : False
     Runspace         : System.Management.Automation.Runspaces.LocalRunspace

2.)Set-ExecutionPolicy -ExecutionPolicy {你的执行策略}

PS C:Program FilesIIS> get-ExecutionPolicy
 Unrestricted

3.)导入模块Web管理

PS C:Program FilesIIS> Import-Module WebAdministration
 PS C:Program FilesIIS>

4.)存在C: Windows System32 WindowsPowerShell v1.0 Modules Web管理路径

5.)模块和管理单元

PS C:Program FilesIIS> get-module -listavailable

ModuleType Name                      ExportedCommands
 ---------- ----                      ----------------
 Manifest   AppLocker                 {}
 Manifest   BitsTransfer              {}
 Manifest   PSDiagnostics             {}
 Manifest   TroubleshootingPack       {}
 Manifest   WebAdministration         {}



PS C:Program FilesIIS> Get-PSSnapin -Registered


Name        : SqlServerCmdletSnapin100
 PSVersion   : 2.0
 Description : This is a PowerShell snap-in that includes various SQL Server cmdlets.

Name        : SqlServerProviderSnapin100
 PSVersion   : 2.0
 Description : SQL Server Provider

Name        : TfsBPAPowerShellSnapIn
 PSVersion   : 2.0
 Description : This is a PowerShell snap-in that includes Team Foundation Server cmdlets.



PS C:Program FilesIIS> get-pssnapin


Name        : Microsoft.PowerShell.Diagnostics
 PSVersion   : 2.0
 Description : Este complemento de Windows PowerShell contiene cmdlets de Eventos de Windows y de contador de rendimient
               o.

Name        : Microsoft.WSMan.Management
 PSVersion   : 2.0
 Description : Este complemento de Windows PowerShell contiene cmdlets (como Get-WSManInstance y Set-WSManInstance) que
               usa el host de Windows PowerShell para administrar operaciones WSMan.

Name        : Microsoft.PowerShell.Core
 PSVersion   : 2.0
 Description : Este complemento de Windows PowerShell contiene cmdlets usados para administrar los componentes de Window
               s PowerShell.

Name        : Microsoft.PowerShell.Utility
 PSVersion   : 2.0
 Description : Este complemento de Windows PowerShell contiene cmdlets de utilidad que sirven para manipular datos.

Name        : Microsoft.PowerShell.Host
 PSVersion   : 2.0
 Description : Este complemento de Windows PowerShell contiene cmdlets (como Start-Transcript y Stop-Transcript) proporc
               ionados para su uso con el host de la consola de Windows PowerShell.

Name        : Microsoft.PowerShell.Management
 PSVersion   : 2.0
 Description : El complemento Windows PowerShell contiene cmdlets de administración para administrar los componentes de
               Windows.

Name        : Microsoft.PowerShell.Security
 PSVersion   : 2.0
 Description : Este complemento de Windows PowerShell contiene varios cmdlets para la administración de la seguridad de
               Windows PowerShell.





PS C:Program FilesIIS> [System.Reflection.Assembly]::LoadFrom( "C:windowssystem32inetsrvMicrosoft.Web.Administration.dll" )

GAC    Version        Location
 ---    -------        --------
 True   v2.0.50727     C:WindowsassemblyGAC_MSILMicrosoft.Web.Administration7.0.0.0__31bf3856ad364e35Microsoft....



PS C:Program FilesIIS> (New-Object Microsoft.Web.Administration.ServerManager)


ApplicationDefaults      : Microsoft.Web.Administration.ApplicationDefaults
 ApplicationPoolDefaults  : Microsoft.Web.Administration.ApplicationPoolDefaults
 ApplicationPools         : {DefaultAppPool}
 SiteDefaults             : Microsoft.Web.Administration.SiteDefaults
 Sites                    : {Default Web Site}
 VirtualDirectoryDefaults : Microsoft.Web.Administration.VirtualDirectoryDefaults
 WorkerProcesses          : {}




PS C:Program FilesIIS> (New-Object Microsoft.Web.Administration.ServerManager).Sites


ApplicationDefaults        : Microsoft.Web.Administration.ApplicationDefaults
 Applications               : {Default Web Site/}
 Bindings                   : {[http] *:80:}
 Id                         : 1
 Limits                     : Microsoft.Web.Administration.SiteLimits
 LogFile                    : Microsoft.Web.Administration.SiteLogFile
 Name                       : Default Web Site
 ServerAutoStart            : True
 State                      : Started
 TraceFailedRequestsLogging : Microsoft.Web.Administration.SiteTraceFailedRequestsLogging
 VirtualDirectoryDefaults   : Microsoft.Web.Administration.VirtualDirectoryDefaults
 Attributes                 : {name, id, serverAutoStart, state}
 ChildElements              : {bindings, limits, logFile, traceFailedRequestsLogging...}
 ElementTagName             : site
 IsLocallyStored            : True
 Methods                    : {Start, Stop}
 RawAttributes              : {[name, Default Web Site], [id, 1], [serverAutoStart, True], [state, 1]}
 Schema                     : Microsoft.Web.Administration.ConfigurationElementSchema

6.)我尝试在ps1文件

$succeeded = import-module WebAdministration
 Write-Host  $succeeded

if (($succeeded -ne $null) -and ($succeeded.GetType() -eq [System.Exception]))
 {
   #Could not import, trying to snapin
   add-pssnapin WebAdministration
 }

$ succeeded为null,并且“add-pssnapin WebAdministration”产生错误消息:Add-PSSnapin:此计算机上未安装Windows PowerShell管理单元'WebAdministration'。

PS C:Program FilesIIS> Add-PSSnapin WebAdministration
 Add-PSSnapin : El complemento WebAdministration de Windows PowerShell no está instalado en este equipo
 En línea: 1 Carácter: 13
 + Add-PSSnapin <<<<  WebAdministration
     + CategoryInfo          : InvalidArgument: (WebAdministration:String) [Add-PSSnapin], PSArgum
     + FullyQualifiedErrorId : AddPSSnapInRead,Microsoft.PowerShell.Commands.AddPSSnapinCommand

对此有何建议? 为什么Add-PSSnapin Web管理失败?

更新:当我使用Add-PSSnapin时以及何时使用Import-Module,我很困惑

http://social.technet.microsoft.com/Forums/en/ITCG/thread/3e1ca6e1-d197-4c04-a145-1e922814a618

当然,Web管理只是模块,并没有PSSnapin。 也许...

参考文献:

PowerShell IIS Snapin

无法安装Powershell管理单元

http://www.iis.net/download/PowerShell

http://learn.iis.net/page.aspx/429/installing-the-iis-powershell-snap-in/

http://learningpcs.blogspot.com.es/2010/08/powershell-iis-7-webadministration.html

Versiónde PowerShell instalada

确定已安装的PowerShell版本


以下是我的profile.ps1中加载WebAdmin模块的功能。 它涵盖了IIS 7和7.5

# Web administration is loaded as a module on Windows 2008 R2 but as a set of snapins
# for Windows 2008 (not 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
        }
    }
}
链接地址: http://www.djcxy.com/p/29009.html

上一篇: PsSnapin WebAdministration in Windows7

下一篇: Path to Powershell.exe (v 2.0)