Reputation: 35
I wrote a PS script where in it will export all the IIS site details and App-pool details to the Excel sheet, but when i use the command Get-IISSite the physical path and the binding details are not displaying in the output console as below, the code is as follows, please help me to fix the issue which i am facing to export the IIS site and app-pool details
Code
#Clearing the Console host in PS
Clear-Host
$Computers = Get-Content "C:\TEMP\servers.txt"
Invoke-Command -ComputerName $Computers -ScriptBlock {
# Changed to newer IISAdministration Module to match Get-IISAppPool
$Websites = Get-IISSite
foreach ($Website in $Websites) {
$AppPool = Get-IISAppPool -Name $Website.Applications[0].ApplicationPoolName
[PSCustomObject]@{
Website_Name = $Website.Name
Website_Id = $Website.Id -join ';'
Website_State = $Website.State -join ';'
Website_PhysicalPath = Get-ChildItem -Path IIS:\Sites\P #$Website.PhysicalPath -join ';'
Website_Bindings = $Website.Bindings.Collection -join ';'
Website_Attributes = ($Website.Attributes | ForEach-Object { $_.name + "=" + $_.value }) -join ';'
AppPool_Name = $AppPool.Name -join';'
AppPool_State = $AppPool.State -join ';'
AppPool_ManagedRuntimeVersion = $AppPool.ManagedRuntimeVersion -join ';'
AppPool_ManagedPipelineMode = $AppPool.ManagedPipelineMode -join ';'
AppPool_StartMode = $AppPool.StartMode -join ';'
}
}
} | Export-Excel -Path C:\users\$env:username\documents\Site_App-pool_Details.xlsx -AutoSize -BoldTopRow
OutPut
Website_Name : Test
Website_Id : 2
Website_State : Started
Website_PhysicalPath :
Website_Bindings :
Website_Attributes : name=Test;id=2;serverAutoStart=False;state=
1
AppPool_Name : Test
AppPool_State : Started
AppPool_ManagedRuntimeVersion : v4.0
AppPool_ManagedPipelineMode : Integrated
AppPool_StartMode : OnDemand
PSComputerName : AAA
RunspaceId : 47d..
When i use the command **Get-Website** i will get all the output details of the IIS site but not the IIS App-pool details the code is a below
Output
Website_Name : Test
Website_Id : 2
Website_State : Started
Website_PhysicalPath : C:\AAA
Website_Bindings : http 10.62.:Test.com
Website_Attributes : name=Test;id=2;serverAutoStart=False;state=
1
AppPool_Name :
AppPool_State :
AppPool_ManagedRuntimeVersion :
AppPool_ManagedPipelineMode :
AppPool_StartMode :
PSComputerName : AAA
RunspaceId : 15d..
Please help me like how to get all the IIS site and App-pool details by using any of the command from both (Get-Website or Get-WebSite)
Thanks in Advance.
Upvotes: 1
Views: 3885
Reputation: 25021
You can do the following with Get-Website
and Get-IISAppPool
.
$Websites = Get-Website
foreach ($Website in $Websites) {
$AppPool = Get-IISAppPool -Name $Website.ApplicationPool
[PSCustomObject]@{
Website_Name = $Website.Name
Website_Id = $Website.Id -join ';'
Website_State = $Website.State -join ';'
Website_PhysicalPath = $Website.PhysicalPath
Website_Bindings = $Website.Bindings.Collection -join ';'
Website_Attributes = ($Website.Attributes | ForEach-Object { $_.name + "=" + $_.value }) -join ';'
AppPool_Name = $AppPool.Name -join';'
AppPool_State = $AppPool.State -join ';'
AppPool_ManagedRuntimeVersion = $AppPool.ManagedRuntimeVersion -join ';'
AppPool_ManagedPipelineMode = $AppPool.ManagedPipelineMode -join ';'
AppPool_StartMode = $AppPool.StartMode -join ';'
}
}
Sample Output
Website_Name : Default Web Site Website_Id : 1 Website_State : Started Website_PhysicalPath : %SystemDrive%\inetpub\wwwroot Website_Bindings : net.msmq localhost;msmq.formatname localhost;net.tcp 808:*;net.pipe *;http *:80: Website_Attributes : name=Default Web Site;id=1;serverAutoStart=True;state=1 AppPool_Name : DefaultAppPool AppPool_State : Started AppPool_ManagedRuntimeVersion : v4.0 AppPool_ManagedPipelineMode : Integrated AppPool_StartMode : OnDemand
Changes Made
Get-Website
to populate $Websites
.$Website.ApplicationPool
into the -Name
parameter of Get-IISAppPool
.Website_PhysicalPath
to $Website.PhysicalPath
Upvotes: 1
Reputation: 21
you have a weird comment in your code on that line which breaks it; but, try this:
Get-Item IIS:\Sites\$Website | Select-Object -ExpandProperty physicalPath
instead of
Get-ChildItem -Path IIS:\Sites\$Website.PhysicalPath
for bindings:
$Website.Bindings.bindingInformation
instead of
$Website.Bindings.Collection
Upvotes: 1