如何删除添加到"添加可信站点所需的详细信息?"

时间:2014-12-19 07:10:33

标签: powershell

我们的应用程序使用包含以下详细信息的url文件

[DEFAULT]
BASEURL=http://MachineName:1800/App/LandingPage.aspx
[InternetShortcut]
URL=http://MachineName:1800/App/LandingPage.aspx

我需要将此网址添加到可信站点。

首先我需要单独http://MachineName

如果我运行followind命令,则它具有BASEURL存在的完整行。

$URL = Get-content FileName.url | Select-string -pattern "BASEURL"

如何仅使用PowerShell从http://MachineName获取内容?

1 个答案:

答案 0 :(得分:4)

Select-String cmdlet返回布尔值或MatchInfo。根据{{​​3}}:

  

输出Microsoft.PowerShell.Commands.MatchInfo或System.Boolean By   默认情况下,输出是一组MatchInfo对象,每个匹配一个   找到。如果使用Quiet参数,则输出为布尔值   表明是否找到了模式。

当您在不使用-quiet的情况下获得多个匹配项时,您将获得一组MatchInfo个对象。可以通过Matches[]数组Value属性访问结果,

PS C:\> $URL = Get-content \temp\FileName.url | Select-string -pattern "(http://[^:]+)"
PS C:\> $URL

BASEURL=http://MachineName:1800/App/LandingPage.aspx
URL=http://MachineName:1800/App/LandingPage.aspx

PS C:\> $URL[0].Matches[0].value
http://MachineName
PS C:\> $URL[1].Matches[0].value
http://MachineName

为了仅捕获没有前缀的BASEURL字符串,请使用非捕获组,

PS C:\> $URL = Get-content \temp\FileName.url | Select-string -pattern "(?:BASEURL=)(http://[^:]+)"
PS C:\> $url

BASEURL=http://MachineName:1800/App/LandingPage.aspx

PS C:\> $url.Matches[0].Groups[1].Value
http://MachineName
相关问题