如何使用appcmd取得網站實體路徑

如何使用appcmd取得網站實體路徑

我正在嘗試以下 appcmd commnad:

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

Misechko.com.ua-DEV 是 IIS 中正確的網站名稱。 appcmd 已在路徑中註冊;

當我嘗試在 cmd.exe 中執行命令時,出現以下錯誤輸出:

錯誤(hresult:8007000d,訊息:輸入包含錯誤元素,這可能表示產生輸入的操作已失敗。)

應用程式設定中有什麼錯誤?我想我正在混合使用 cmd 和 powershell 方法,但是 aboce提到的腳本在 PowerShell 中也不起作用。最好使用 PowerShell 方式透過網站名稱取得路徑。

PS 我的 PowerShell 替代方案也不行:

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

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

謝謝!

答案1

自己研究了一下,找到了解決方法:

     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
    }

答案2

這對我也有用。以管理員身分執行cmd。

appcmd list app /site.name:"Default Web Site" /path:"/" /xml | appcmd list vdir /in /text:physicalPath

來源

相關內容