Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the Physical Path property of a site

Tags:

powershell

iis

When I just list the sites with the default formatting, it shows the physical path.

PS C:\Windows\system32> $sm = Get-IISServerManager

PS C:\Windows\system32> $sm.Sites

Name             ID   State      Physical Path                  Bindings                                                                                                                                                                                                 
----             --   -----      -------------                  --------                                                                                                                                                                                                 
Default Web Site 1    Started    %SystemDrive%\inetpub\wwwroot  http *:80:                                                                                                                                                                                               
Test             2    Started    C:\inetpub\wwwroot_Test       http *:5007:                                                                                                                                                                                             



PS C:\Windows\system32> 

But I can't find any corresponding property on the object.

$sm.Sites[0] | Format-List *



ApplicationDefaults        : Microsoft.Web.Administration.ApplicationDefaults
Applications               : {Default Web Site/, ...}
Bindings                   : {http *:80:}
Id                         : 1
Limits                     : Microsoft.Web.Administration.SiteLimits
LogFile                    : Microsoft.Web.Administration.SiteLogFile
Name                       : Default Web Site
ServerAutoStart            : True
State                      : Started
TraceFailedRequestsLogging : Microsoft.Web.Administration.SiteTraceFailedRequestsLogging
VirtualDirectoryDefaults   : Microsoft.Web.Administration.VirtualDirectoryDefaults
Attributes                 : {name, id, serverAutoStart, state}
ChildElements              : {bindings, limits, logFile, traceFailedRequestsLogging...}
ElementTagName             : site
IsLocallyStored            : True
Methods                    : {Start, Stop}
RawAttributes              : {[name, Default Web Site], [id, 1], [serverAutoStart, True], [state, 1]}
Schema                     : Microsoft.Web.Administration.ConfigurationElementSchema

Direct Question: How can I get the physical path of a site?

Indirect Question: Is there a way to find how the object is formatted by default? Then I could look up the Physical Path from there.

like image 408
Lukas Rieger Avatar asked Dec 03 '22 19:12

Lukas Rieger


1 Answers

After decompiling and debugging this for a few hours, I found the expression powershell uses internally:

$_.Applications["/"].VirtualDirectories["/"].PhysicalPath

No idea how you are supposed to find that out without a decompiler.

like image 175
Lukas Rieger Avatar answered Dec 06 '22 20:12

Lukas Rieger