English 中文(简体)
如何在“url”档案中搜寻特定的URLs?
原标题:How to search for specific URLs in ".url" files?

我有一份名录<代码>D:DMS,有多份子。 在这些子里,有大量的“.url”文件,包括像URLs一样的URLs。

http://mmtst399:8080/dms/objekt?page=index&mode=browser&oid=K60081800
http://zrtpwvap877/dms/download?doc=N59748000

In order later on to replace some of the URLs I would like to search for such URLs by PowerShell eg. find a all URLs that start with http://mmtst399:8080/ or find all URLs that contain K60081800 or find all URLs that start with http://zrtpwvap877/dms/.

在<代码>.url文档中似乎难以查找这种URL。 我已经尝试过许多不同的PowerShell样本,如上,但最后常常显示“没有结果,没有发现任何文件”,甚至我知道有<代码>.url<<>>/code>的子文件,其中含有这种URLs。 当然,如果PowerShell甚至无法找到.url<>/code>文档,那么在这些档案中很难替换URLs。

我愿在<代码>.url文档中查找这些URLs,这是一个带有所发现结果途径的txt记录。 我猜测这种URL是困难的,因为有些含有<代码>=和?和其他特性。

最佳回答
问题回答

I tried to find a URL which contains D60081800, knowing it is there in a sub folder , but no result. Did I do anything wrongenter code here

# The literal URL parts to find, either prefixes or substrings.
$urlParts =  D60081800 

$regex =  ^URL=({0})  -f (
  $urlParts.ForEach({ 
    $escaped = [regex]::Escape($_) # Escape for literal matching, if needed.
    if ($escaped -match  ^https?: ) { $escaped } 
    else                            {  .+  + $escaped } # match anywhere in the URL
  }) -join  | 
)

# Search all *.url files in the subtree of D:DMS for the URL parts
# and output the full paths of matching files.
# Outputs to the screen and saves to a file.

$foundPaths = Get-ChildItem -Recurse D:DMS -Filter *.url | 
  Select-String -Pattern $regex -List | 
  ForEach-Object {
    $path = $_.Path
    Write-Output $path
    $path
  }

# Save the found paths to a text file in D:powershell
$foundPaths | Out-File -FilePath  D:powershellfound_paths.txt 




相关问题
Mutually exclusive powershell parameters

SCENARIO I m writing a cmdlet for Powershell 2.0 using Visual Studio 2008 and .NET 3.5 the cmdlet requires 3 arguments. my intended grammar of the cmdlet is something like this: cmdletname [foo|...

Run a program from PowerShell with timeout

I ll write a script that runs a program and wait for it finished. But if the program is not finished within a specified time I want that the program is killed.

How to transpose data in powershell

I have a file that looks like this: a,1 b,2 c,3 a,4 b,5 c,6 (...repeat 1,000s of lines) How can I transpose it into this? a,b,c 1,2,3 4,5,6 Thanks

Powershell v2 remoting and delegation

I have installed Powershell V2 on 2 machines and run Enable-PsRemoting on both of them. Both machines are Win 2003 R2 and are joined to the same active directory domain and I can successfully run ...

PowerShell -match operator and multiple groups

I have the following log entry that I am processing in PowerShell I m trying to extract all the activity names and durations using the -match operator but I am only getting one match group back. I m ...

热门标签