Reputation: 21
On my button click event, following script is run. But when the services are executed, it does not display anything in the text file and the import module WebAdministration line shows the error message :
Cannot find a provider with the name 'WebAdministration'
Same script runs fine from powershell cmd
My script:
$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
Upvotes: 2
Views: 6720
Reputation: 31
Yep, run powershell/Exchange Management Console as Administrator by right clicking the icon -> 'run as administrator'.
Upvotes: 3
Reputation: 4119
Try to run the Powershell script as administrator, there is no need to import the WebAdministration module
Upvotes: 3