# How to get site physical path with appcmd

I am trying the following appcmd commnad:

appcmd list app /site.name:"misechko.com.ua-DEV" /xml | appcmd list vdir /in /text:physicalPath


misechko.com.ua-DEV is a correct site name in IIS. appcmd is registered in path;

I get the following error output when I am trying to execute a command in cmd.exe:

ERROR ( hresult:8007000d, message:The input contained an error element, which may indicate that the operationproducing the input has failed. )

What is the mistake in the app setup? I guess I am mixing a cmd and powershell approach, but the abocementioned script doesn't work in PowerShell either. A PowerShell way of getting the path by web site name is preferable.

P.S. My PowerShell alternative that also doesn't work:

$appCmd = "$Env:SystemRoot\system32\inetsrv\appcmd.exe"

$appcmd list app /site.name:"misechko.com.ua-DEV" /xml |$appcmd list vdir /in /text:physicalPath


Thanks!

-

Researched myself and found an solution:

     function GetPhysicalPath ([String]$siteName) { function Get-PipelineInput { end { [xml]$appConfigXml = $input return$appConfigXml.application.virtualDirectory.physicalPath
}
}

$appCmd = "$Env:SystemRoot\system32\inetsrv\appcmd.exe"

return & $appCmd list app /site.name:"$siteName" /config | Get-PipelineInput
}

-
If this was the solution, please accept it as the answer. –  Ryan Gates Dec 3 '13 at 21:33
Nice solution. Have to be careful though, since appcmd list app ... will return all virtual directories as siblings i.e. it will break the XML parser. If you're only interested in the root of the site, better to use "vdir" $appCmd list vdir "$siteName/" /config (note the trailing slash on site name), and then tweak the xml path to suit i.e. \$appConfigXml.virtualDirectory.physicalPath –  Dave Transom May 28 at 4:07