Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Find Default Document

$
0
0

Has anyone been able to figure out  how can you loop through and get the default documents for apps/virtual directories from an iis 7.5 server using Powershell v2. I can get the applications and virtual directory paths easily, but the default docs I am having issues with.  Here's the code I have so far.  I searched this site but didn't find anything.  Thank you in advance!!

New-Item d:\sites.txt -type file -force

write-Output  ("URL" + "`t" + "appPath" + "`t" + "virtPath" + "`t" + "virtPhysicalPath" ) >> d:\sites.txt

$dummy = [System.Reflection.Assembly]::LoadFrom(

    "c:\windows\System32\InetSrv\Microsoft.Web.Administration.dll")

 

$srvmgr = new-object Microsoft.Web.Administration.ServerManager

 

write-Output  ("site`tstate`tapp`tvirtdir`tphys.path")

 

foreach($site in $srvmgr.Sites | Sort-Object Name ) {

 

                #This gets a million subfolders

                #Get-ChildItem $site.PhysicalPath -recurse | Where-Object {$_.Attributes -eq 'Directory'}

 

  foreach($app in $site.Applications | Sort-Object Path ) {

 

    foreach($virt in $app.VirtualDirectories | Sort-Object Path ) {

 

      #write-Output  ($site.Name + "`t" + $site.State + "`t" +

                #write-Output  ($site.Name + "`t" + #"`t" +

        #$app.Path + "`t" + $virt.Path + "`t" + $virt.PhysicalPath + "`t" + "https://" + $site.Name + $virt.Path)

 

if ($virt.Path -ne "/"){

                write-Output  ($virt.psbase.properties.defaultdoc  + "`t" + $site.Name + $virt.Path + "`t" + $app.Path + "`t" + $virt.Path + "`t" + $virt.PhysicalPath )

                write-Output  ($site.Name + $virt.Path + "`t" + $app.Path + "`t" + $virt.Path + "`t" + $virt.PhysicalPath ) >> d:\sites.txt

}

else  {

                write-Output  ($virt.psbase.properties.defaultdoc  + "`t" + $site.Name + $app.Path + "`t" + $app.Path + "`t" + $virt.Path + "`t" + $virt.PhysicalPath )

                write-Output  ($site.Name + $app.Path + "`t" + $app.Path + "`t" + $virt.Path + "`t" + $virt.PhysicalPath ) >> d:\sites.txt

}

                $count++

    }

 

  }

 

}

                write-Output "===================================================================================="

                write-Output "Total Virtual Dirs: $count "

 

 


Viewing all articles
Browse latest Browse all 6937

Trending Articles