我正在使用下面的脚本,该脚本是我从这里获得的,并使用Google搜索进行了一些调整,它为我提供了大多数信息,但我也想添加IP信息。我做到了,但是没有拉任何东西,IP列为空白,并且到CSV的输出也无法正常工作。有人可以帮忙并添加该信息。
Clear-Host
$ps = "Windows PowerShell"
$RemoteComputers = 'myserver',
'myserver2'
ForEach ($RemoteComputer in $RemoteComputers)
{
#"`n" # Insert a new line.
#"*"*24 # Banner line record seperator
Invoke-Command -ComputerName $RemoteComputer -ScriptBlock {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
$IpAddress =$_.IpAddress
$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
-notypeinformation
$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 -GroupBy Host |$obj#| export-csv c:\temp\$date-$hostname.csv -Append -Notypeinformation
}