Friday, August 2, 2024

A couple of PowerShell scripts for IIS I've found handy

 A couple of handy IIS Dumps of sites and virtual directories.

Sites

Import-Module Webadministration
Get-ChildItem -Path IIS:\Sites > d:\allsites.txt

 Virtual Directories

$SiteVirtualDirectories = @()
$Sites = gci IIS:\Sites
foreach($Site in $Sites)
    {
    $VirtualDirectories = gci "IIS:\Sites\$($Site.Name)" | ?{$_.NodeType -match "virtualDirectory"}
    foreach($VirtualDirectory in $VirtualDirectories)
        {
        $SiteVirtualDirectories += @([pscustomobject]@{Site=$Site.Name;VirtualDirectory=$VirtualDirectory.Name;PhysicalPath=$VirtualDirectory.PhysicalPath})
        }
    }

Out-File -FilePath D:\VirtualDirectories.txt -InputObject $SiteVirtualDirectories -Encoding ASCII


No comments:

Post a Comment