【发布时间】: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