代码改变世界

天行健,君子以自强不息

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
  108 随笔 :: 0 文章 :: 3 评论 :: 23935 阅读
< 2025年4月 >
30 31 1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 1 2 3
4 5 6 7 8 9 10

摘要

SSH登入远程Windows,用PowerShell创建或修改IIS的虚拟目录。

用到的PowerShell命令

创建虚拟目录,微软官方例子:

PS IIS:\> New-Item 'IIS:\Sites\Default Web Site\DemoVirtualDir1' -type VirtualDirectory -physicalPath c:\test\virtualDirectory1
Name                                              PhysicalPath
----                                              ------------
DemoVirtualDir1                                   c:\test\virtualDirectory1

PS IIS:\> New-Item 'IIS:\Sites\Default Web Site\DemoApp\DemoVirtualDir2' -type VirtualDirectory -physicalPath c:\test\virtualDirectory2
Name                                              PhysicalPath
----                                              ------------
DemoVirtualDir2                                   c:\test\virtualDirectory2

我们用到的命令:

PS C:\Windows\system32> New-Item 'IIS:\Sites\Default Web Site\04140304' -type VirtualDirectory -PhysicalPath "x:\sites\publish"

Name     PhysicalPath
----     ------------
04140304 x:\sites\publish

在IIS管理器中看到了我们创建的网站:

img

修改现有的虚拟目录

Set-WebConfigurationProperty -Filter "//sites/site[@name='MyWebApp']/application[@path='/']/virtualDirectory[@path='/']" -Name physicalPath -Value "D:\apidd2"
posted on   终南山人  阅读(32)  评论(0)    收藏  举报
点击右上角即可分享
微信分享提示