Iis

如何使用 appcmd.exe 在添加站點命令中創建目錄?

  • May 15, 2021

當我使用 appcmd.exe 創建網站時,我需要命令中的物理路徑地址。執行此地址時如何創建目錄:

%systemroot%\system32\inetsrv\AppCmd.exe add site /name:websitename /id:4 /physicalPath:C:\inetpub\wwwroot\example12 /bindings:http/*:80:example.com

在上面的命令中,“example12”目錄不存在。我希望在執行命令時,該目錄自動創建該地址。

我從來沒有真正使用過Appcmd.exe,但它是用於操作 IIS 對象而不是文件系統對象。所以我認為沒有辦法在使用 AppCmd.exe 時自動創建目錄

在您的批處理文件中,只需使用:

md C:\inetpub\wwwroot\example12
%systemroot%\system32\inetsrv\AppCmd.exe add site /name:websitename /id:4 /physicalPath:C:\inetpub\wwwroot\example12 /bindings:http/*:80:example.com

或者更好地使用 PowerShell cmdlet 而不是AppCmd.exe

引用自:https://serverfault.com/questions/1063638