The function in the toolsfile collects all info and return a populated object that can be used to export list to file or do something else with.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$scriptPath = $(split-path -Parent $MyInvocation.MyCommand.Definition) | |
import-module "$($scriptPath)\xssWebTools.psm1" -Force | |
$Site1Headers = get-SiteBindings -siteName "site1" | |
$Site2Headers = get-SiteBindings -siteName "site2" | |
if ($Site1Headers -ne $null) { | |
$Site1Headers |export-csv -Path "$($scriptPath)\site1Addresses.csv" -Encoding UTF8 -NoTypeInformation | |
write-output "Printed Site1Headers to $($scriptPath)" | |
} else {write-output "No Site1Headers found"} | |
if ($Site2Headers -ne $null) { | |
$Site2Headers |export-csv -Path "$($scriptPath)\site2Addresses.csv" -Encoding UTF8 -NoTypeInformation | |
write-output "Printed Site2Headers to $($scriptPath)" | |
} else { write-output "No Site2Headers found"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function get-SiteBindings { | |
param( | |
[parameter(mandatory=$true)] | |
[ValidateNotNullOrEmpty()] | |
$siteName | |
) | |
if (!(Get-Module -Name webadministration)) {import-module webadministration} | |
$selectedSite = Get-ChildItem -Path IIS:\Sites |where-object {$_.name -like $siteName} | |
if ($selectedSite.count -eq 1) { | |
$currentHostHeaders = Get-ItemProperty -Path $selectedSite.pspath -Name bindings.collection | |
$object = @() | |
foreach ($currentHostHeader in $currentHostHeaders) { | |
#$TrimmedHeader = $currentHostHeader.bindingInformation.TrimStart("*").trimstart(":80") | |
$TrimmedHeader = $currentHostHeader.bindingInformation.split(":")[-1] | |
$portHeader = $currentHostHeader.bindingInformation.split(":")[-2] | |
$tempObject = new-object psobject -Property @{hostheader=$TrimmedHeader;protocol=$currentHostHeader.protocol;port=$portHeader} | |
$object += $tempObject | |
} | |
return $object | |
} | |
elseif ($selectedSite.count -gt 1) { | |
write-warning "Too many hits. Skipping..." | |
return $null | |
} | |
elseif ($selectedSite.count -eq 0) { | |
write-warning "Couldn't find any sites matching '$siteName'!" | |
return $null | |
} | |
} |
No comments:
Post a Comment