gpt4 book ai didi

c# - 从 C# 应用程序运行时未导入 Web 管理模块

转载 作者:行者123 更新时间:2023-12-02 00:53:35 25 4
gpt4 key购买 nike

在我的按钮单击事件中,运行以下脚本。但是当执行服务时,它不会在文本文件中显示任何内容,导入模块 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

最佳答案

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

关于c# - 从 C# 应用程序运行时未导入 Web 管理模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37669551/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com