0

I am trying to get the sites being hosted in multiple remote servers using the below script:

Import-Module WebAdministration
$servers = Get-Content -Path C:\Users\Administrator\Desktop\serv.txt
foreach($server in $servers)
{
    Invoke-Command  -ComputerName $servers { Import-Module WebAdministration; Get-ChildItem -path IIS:\Sites | Format-Table} | Out-File "C:\Users

    \Administrator\Desktop\detail.txt"
}

But I am getting error. Detail.txt has been created. But the file is empty. Please suggest.

Martin Tournoij
  • 26,737
  • 24
  • 105
  • 146
Muktesh
  • 1
  • 1
  • Possible duplicate of [WebAdministration powershell module not found on windows server data center](http://stackoverflow.com/questions/5963647/webadministration-powershell-module-not-found-on-windows-server-data-center) – Martin Tournoij Aug 28 '16 at 13:29
  • Welcome to StackoverFlow! Please share the error details. – user4317867 Aug 28 '16 at 18:16
  • when i executed above script i got the below error: [server01] Connecting to remote server failed with the following error message : The client cannot connect to the destination specified in the request. Verify that the service on the destination is running and is accepting requests. I have checked the WinRm service and is installed and running fine. Latter i tried below script: – Muktesh Aug 29 '16 at 04:49
  • Import-Module WebAdministration $servers = Get-Content -Path C:\Users\administrator\Desktop\serv.txt Function Load-WebAdmin { $webAdminModule = get-module -ListAvailable | ? { $_.Name -eq "webadministration" } If ($webAdminModule -ne $null) { import-module WebAdministration }else{ Add-pssnapin WebAdministration } } foreach($server in $servers) { Invoke-Command -ComputerName $server {Import-Module WebAdministration; Get-Website} | Out-File "C:\Users\administrator\Desktop\detail.txt" } No errors on execution, but detail.txt file is empty. – Muktesh Aug 29 '16 at 04:55

0 Answers0