trzxycx 发表于 2018-9-2 13:21:07

[Powershell]列出IIS绑定的端口

  
$IISsetting=Get-Content "C:\windows\system32\inetsrv\config\applicationHost.config"
  
$BindingInformation=((($IISsetting -match "bindinginformation") -split "information=") -replace '"',"") -match ":"
  
$BindingPort=(($BindingInformation -split ":") -match "$") -notmatch "\."
  

  
echo $BindingPort |sort -unique
  IIS的配置文档是"C:\windows\system32\inetsrv\config\applicationHost.config";
  参数说明:
  split: 以引号中的文本参数来分割整行文本,并返回分割后的结果文本;
  match: 匹配包含文本所在的行,并显示匹配的行;
  notmatch:匹配包含文本所在的行,并显示不匹配的行;
  -replace 'var1',"var2"   :用var2来替代文本中的var1,并返回替代后的文本;
  sort: 排序;“-unique”返回唯一值,避免重复显示;
  正则表达式见博客:http://281816327.blog.51cto.com/907015/1414286


页: [1]
查看完整版本: [Powershell]列出IIS绑定的端口