How to get site physical path with appcmd

cmd.exepowershell

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!

Best Answer

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
    }
Related Question