How to list out Virtual Directories in IIS from the all the websites in PowerShell
You write that you can't figure out how to retrieve:
- Physical Path
- is directly accessible through the
physicalPath
noteproperty
- is directly accessible through the
- App Pool Association
- doesn't make sense, Applications are assigned to app pools, directories themselves are not
- Site Name
- You already know this (
$Site.name
)
- You already know this (
- Credentials
- I assume you just want the username if present
These could all be retrieved with some slight alterations to your existing script:
Import-Module WebAdministration
$Websites = Get-ChildItem IIS:\Sites
$AllVDirs = @()
foreach($Site in $Websites)
{
$VDirs = Get-WebVirtualDirectory -Site $Site.name
foreach($webvdirectory in $VDirs)
{
$vdir = New-Object psobject -Property @{
"Name" = ($webvdirectory.path -split "/")[-1]
"Site" = $Site.name
"Path" = $webvdirectory.path
"PhysicalPath" = $webvdirectory.physicalPath
"PhysicalPathCredentials" = $webvdirectory.userName
}
$AllVDirs += $vdir
}
}
$AllVDirs
Now you can export $AllVDirs
to Xml, Csv or simply print it to the PowerShell host.
Thank you @Mathias R. Jessen , I forgot about this post and I should've came back because I figured most of it out. Your script works perfect and here's mine just for S&Gs, didn't realize all I had to do was call on the objects and properties.
$Websites = Get-ChildItem IIS:\Sites
foreach($Site in $Websites)
{
$webapps = Get-WebApplication -Site $Site.name
$VDir = Get-WebVirtualDirectory -Site $Site.name #-Application $webapps.name
foreach($webvdirectory in $VDir)
{
$webvdirectory2 = $webvdirectory.path
Write-Host $webvdirectory2.split("/")[-1] "::: is the Virtual Directory" -ForegroundColor Green
Write-Host $webvdirectory.physicalPath
Write-Host $webvdirectory.userName
Write-Host $webvdirectory.password
Write-Host $webvdirectory.logonMethod
}
#Write-Host $VDir
}
Also have another problem though and didn't know if you had the answer, how would I call on the Physical Path credentials property for web applications? I cant print out the username or password, but I can print the logonMethod which uses the same property? below is my code for web applications, it is very similar to my virtual directories code:
$Websites = Get-ChildItem IIS:\Sites
foreach($Site in $Websites)
{
$webapps = Get-WebApplication -Site $Site.name
foreach($webapp in $webAPPS)
{
Write-Host $webapp.applicationPool
Write-Host $WebApp.virtualDirectoryDefaults.userName
Write-Host $webapp.virtualDirectoryDefaults.password
Write-Host $webapp.virtualDirectoryDefaults.logonMethod
$webapp2 = $webapp.path
Write-Host $WebApp2.split("/")[-1] "::: is the Web Application" -ForegroundColor Green
}
}