So with the help of both of you guys and google. I was able to connect couple already available scripts and some changes, got script that gives me all the information that I need. Everything works fine But when I try to export it to csv it give me headers only no other information is getting populated. I have trying using the variable $results = @ () foreach {} $results += Select-Object …|export-csv But still does not populated. Can you guys help in formatting. So I can get the results the way I see in powershell window.
Thanks
Clear-Host
$ps = “Windows PowerShell”
$RemoteComputers = ‘local1’,‘local2’
ForEach ($RemoteComputer in $RemoteComputers)
{
#“`n” # Insert a new line.
#“*”*24 # Banner line record seperator
Invoke-Command -ComputerName $RemoteComputer -ScriptBlock {
$Service = ( $TargetServices = ‘W3SVC’,‘MSSQLSERVER’ | % { Get-Service -Name $_ -ErrorAction SilentlyContinue} )
$IPAddress = ([System.Net.Dns]::GetHostByName($Inputmachine).AddressList[0]).IpAddressToString
Import-Module WebAdministration
$hostname = hostname
$Websites = Get-ChildItem IIS:\Sites
$date = (Get-Date).ToString(‘MMddyyyy’)
foreach ($Site in $Websites) {
$Binding = $Site.bindings
[string]$BindingInfo = $Binding.Collection
[string]$Bindings = $BindingInfo.Split(" ")#[0]
$i = 0
$status = $site.state
$path = $site.PhysicalPath
$fullName = $site.name
$state = ($site.name -split “-”)[0]
$Collection = ($site.name -split “-”)[1]
$status = $site.State
$anon = get-WebConfigurationProperty -Filter /system.webServer/security/authentication/AnonymousAuthentication -Name Enabled -PSPath IIS:\sites -Location $site.name | select-object Value
$basic = get-WebConfigurationProperty -Filter /system.webServer/security/authentication/BasicAuthentication -Name Enabled -PSPath IIS:\ -location $site.name | select-object Value
Do{
if( $Bindings[($i)] -notlike “sslFlags=*”){
[string]$Bindings2 = $Bindings[($i+1)].Split(“:”)
$obj = New-Object PSObject
$obj | Add-Member Date $Date
$obj | Add-Member Host $hostname
$obj | Add-Member State $state
$obj | Add-Member SiteName $Site.name
$obj | Add-Member SiteID $site.id
$obj | Add-member Path $site.physicalPath
$obj | Add-Member Protocol $Bindings[($i)]
$obj | Add-Member Port $Bindings2[1]
$obj | Add-Member Header $Bindings2[2]
$obj | Add-member AuthAnon $Anon.value
$obj | Add-member AuthBasic $basic.value
$obj | Add-member Status $status
$obj | Add-Member Ipaddress $IpAddress
$obj | Add-Member Service $Service
$obj#
$i=$i+2
}
else{$i=$i+1}
} while ($i -lt ($bindings.count))
}}| Format-Table -AutoSize -Property Host,IpAddress,SiteID,Port,Protocol,Status,SiteName,Path,Header,Service -GroupBy IpAddress |
Select-Object Host,IpAddress,SiteID,Port,Protocol,Status,SiteName,Path,Header,Service | Export-csv -Append -notypeinformation -path c:\temp\iis.csv
}