Mostrar todos los sitios y enlaces en powershell


Estoy documentando todos los sitios y enlaces relacionados con el sitio desde el IIS. ¿Se pregunta si hay una manera fácil de obtener esta lista a través del script de powershell en lugar de escribir manualmente mirando IIS?

Quiero la salida algo como esto:

Site                          Bindings  
TestSite                     www.hello.com
                             www.test.com
JonDoeSite                   www.johndoe.site 
Author: Kiquenet, 2013-03-20

7 answers

Prueba algo como esto para obtener el formato que querías:

Get-WebBinding | % {
    $name = $_.ItemXPath -replace '(?:.*?)name=''([^'']*)(?:.*)', '$1'
    New-Object psobject -Property @{
        Name = $name
        Binding = $_.bindinginformation.Split(":")[-1]
    }
} | Group-Object -Property Name | 
Format-Table Name, @{n="Bindings";e={$_.Group.Binding -join "`n"}} -Wrap
 39
Author: Frode F.,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-03-20 16:34:52

Prueba esto

Import-Module Webadministration
Get-ChildItem -Path IIS:\Sites

Debe devolver algo que se vea así:

Name             ID   State      Physical Path                  Bindings
----             --   -----      -------------                  --------
ChristophersWeb 22   Started    C:\temp             http *:8080:ChristophersWebsite.ChDom.com

Desde aquí puede refinar los resultados, pero tenga cuidado. Una tubería a la instrucción select no le dará lo que necesita. En función de sus requisitos, construiría un objeto personalizado o una tabla hash.

 69
Author: Christopher Douglas,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-03-20 16:21:25

El camino más fácil que vi:

Foreach ($Site in get-website) { Foreach ($Bind in $Site.bindings.collection) {[pscustomobject]@{name=$Site.name;Protocol=$Bind.Protocol;Bindings=$Bind.BindingInformation}}}
 19
Author: Alexander Shapkin,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-02-08 12:43:35

Si solo desea enumerar todos los sitios (es decir. para encontrar un enlace)

Cambie el directorio de trabajo a C:\Windows\system32\inetsrv

Cd c:\Windows\system32\inetsrv

A continuación, ejecute appcmd list site y envíe la salida a un archivo. e. g c:\IISSiteBindings.txt

Appcmd lista sitio > c:\IISSiteBindings.txt

Ahora abra con el bloc de notas desde el símbolo del sistema.

Bloc de notas c:\IISSiteBindings.txt

 13
Author: Armand G.,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-02-02 16:20:06

Prueba esto

function DisplayLocalSites
{

try{

Set-ExecutionPolicy unrestricted

$list = @()
foreach ($webapp in get-childitem IIS:\Sites\)
{
    $name = "IIS:\Sites\" + $webapp.name
    $item = @{}

$item.WebAppName = $webapp.name

foreach($Bind in $webapp.Bindings.collection)
{
    $item.SiteUrl = $Bind.Protocol +'://'+         $Bind.BindingInformation.Split(":")[-1]
}


$obj = New-Object PSObject -Property $item
$list += $obj
}

$list | Format-Table -a -Property "WebAppName","SiteUrl"

$list | Out-File -filepath C:\websites.txt

Set-ExecutionPolicy restricted

}
catch
{
$ExceptionMessage = "Error in Line: " + $_.Exception.Line + ". " +     $_.Exception.GetType().FullName + ": " + $_.Exception.Message + " Stacktrace: "    + $_.Exception.StackTrace
$ExceptionMessage
}
}
 2
Author: snimakom,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-04-13 23:56:28
function Get-ADDWebBindings {
param([string]$Name="*",[switch]$http,[switch]$https)
    try {
    if (-not (Get-Module WebAdministration)) { Import-Module WebAdministration }
    Get-WebBinding | ForEach-Object { $_.ItemXPath -replace '(?:.*?)name=''([^'']*)(?:.*)', '$1' } | Sort | Get-Unique | Where-Object {$_ -like $Name} | ForEach-Object {
        $n=$_
        Get-WebBinding | Where-Object { ($_.ItemXPath -replace '(?:.*?)name=''([^'']*)(?:.*)', '$1') -like $n } | ForEach-Object {
            if ($http -or $https) {
                if ( ($http -and ($_.protocol -like "http")) -or ($https -and ($_.protocol -like "https")) ) {
                    New-Object psobject -Property @{Name = $n;Protocol=$_.protocol;Binding = $_.bindinginformation}
                }
            } else {
                New-Object psobject -Property @{Name = $n;Protocol=$_.protocol;Binding = $_.bindinginformation}
            }
        }
    }
    }
    catch {
       $false
    }
}
 2
Author: user6804160,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-09-07 12:22:28

Encontré esta pregunta porque quería generar una página web con enlaces a todos los sitios web que se ejecutan en mi IIS. Usé la respuesta de Alexander Shapkin para llegar a lo siguiente para generar un montón de enlaces.

$hostname = "localhost"

Foreach ($Site in get-website) { 
    Foreach ($Bind in $Site.bindings.collection) {
        $data = [PSCustomObject]@{
            name=$Site.name;
            Protocol=$Bind.Protocol;
            Bindings=$Bind.BindingInformation
        }
        $data.Bindings = $data.Bindings -replace '(:$)', ''
        $html = "<a href=""" + $data.Protocol + "://" + $data.Bindings + """>" + $data.name + "</a>"
        $html.Replace("*", $hostname);
    }
}

Luego pego los resultados en este HTML escrito apresuradamente.

<html>
<style>
    a { display: block; }
</style>
{paste powershell results here}
</body>
</html>

Realmente no conozco Powershell, así que siéntase libre de editar mi respuesta para limpiarla.

 0
Author: Walter Stabosz,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-02-13 20:14:43