试图在这里编写脚本来将所有应用程序更改为虚拟目录。 我使用Powershell,但是我的技能有点弱。 我使用正确的工具吗?
以下是我到目前为止:
cd $env:SystemRoot\system32\inetsrv\ #Find all applications below RootAppName, convert them to virtual directories $RootAppName = 'Default Web Site/RootApp' ./appcmd list app | Where { [Regex]::IsMatch($_, $RootAppName + '/') } | Foreach{ $FirstIndex = $_.IndexOf('"', 0) $SecondIndex = $_.IndexOf('"', $FirstIndex + 1) $Appname = $_.Substring($FirstIndex + 1, $SecondIndex - $FirstIndex - 1) $PhysicalPath = '' #Can't figure out how to get this $VDirPath = $Appname.Replace($RootAppName, '') # Need to invoke here appcmd delete app $Appname # Need to invoke here appcmd add vdir /app.name:$RootAppName /path:$VDirPath /physicalPath:$PhysicalPath }
有任何想法吗? 我正在以正确的方式进行吗?
Urgh! PowerShell 2? 不要掏出AppCMD.exe 。
在PowerShell提示符下执行Import-Module WebAdministration ,或者右键单击PowerShell图标并select“导入系统模块”
然后尝试Get-WebApplication和Remove-WebApplication 。
以下是使用Webpipe理的后代脚本:
Import-Module WebAdministration #Find all applications below AppName in site SiteName, convert them to virtual directories $RootAppName = 'AppName' $SiteName = 'SiteName' $SitePath = 'IIS:\Sites\' + $SiteName cd $SitePath dir | Where { [Regex]::IsMatch($_.Name, $RootAppName + '\\') } | Foreach { $AppName = $_.Name $PhysicalPath = $_.PhysicalPath Remove-WebApplication -Name $AppName -Site $SiteName Write-Host 'Removing application' $AppName 'from site' $SiteName New-WebVirtualDirectory -Site $SiteName -Name $AppName -PhysicalPath $PhysicalPath Write-Host 'Adding virtual directory' $AppName 'to site' $SiteName 'at path' $PhysicalPath }