【问题标题】:Webadministration module is not imported while running from C# application从 C# 应用程序运行时未导入 Web 管理模块
【发布时间】:2023-04-04 23:34:02
【问题描述】:

在我的按钮单击事件中,运行以下脚本。但是在执行服务时,它不会在文本文件中显示任何内容,并且导入模块 WebAdministration 行会显示错误消息:

找不到名为“WebAdministration”的提供程序

相同的脚本在 powershell cmd 中运行良好

我的脚本:

        $a = (Get-Service | Where {$_.DisplayName -Like "Microsoft Exchange*"} | % {$_.name + ' :' + $_.status}) -join "`n"


        write-output $a >> C:\temp.txt


            import-module WebAdministration
        $webapps = Get-WebSite Powershell
        $list = @()
        foreach ($webapp in get-childitem IIS:\AppPools\)
        {
                $name = "IIS:\AppPools\" + $webapp.name
                $item = @{}

                $item.WebAppName = $webapp.name
                $item.Version = (Get-ItemProperty $name managedRuntimeVersion).Value
                $item.State = (Get-WebAppPoolState -Name $webapp.name).Value
                $item.UserIdentityType = $webapp.processModel.identityType
                $item.Username = $webapp.processModel.userName
                $item.Password = $webapp.processModel.password

                $obj = New-Object PSObject -Property $item
                $list += $obj
        }

        $abc = ($list | %{$_.Name+":"+ $_.ApplicatonPool+":"+$_.Protocol+":"+$_.PhysicalPath}) -join "`n"
        write-output "Details For Default WebApplication: `n $abc" >> C:\temp.txt
        cd iis:\
        $path ='Sites\Default Web Site\' + $website
        $abcd = (Get-WebConfiguration -Filter "System.WebServer/Security/Authentication/*" -PSPath $path | where {$_.enabled -eq $True} | % {$_.SectionPath + ' :' + $_.Location}) -join "`n" -replace "/system.webServer/security/authentication/",""
        write-output " Enable Authentication Mode For Given Websites:`n $abcd" >> C:\temp.txt

【问题讨论】:

    标签: c# powershell


    【解决方案1】:

    尝试以管理员身份运行Powershell脚本,无需导入WebAdministration模块

    【讨论】:

      【解决方案2】:

      是的,通过右键单击图标 ->“以管理员身份运行”以管理员身份运行 powershell/Exchange 管理控制台。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-02-10
        • 1970-01-01
        • 1970-01-01
        • 2010-09-05
        • 1970-01-01
        • 1970-01-01
        • 2011-02-08
        • 1970-01-01
        相关资源
        最近更新 更多