extract http data

Contributor

Hi expert,

I am trying to extract http:// URL from given file but getting empty file in export

here is the code

$items = Get-ChildItem -LiteralPath "E:\Backup_Testinstance\" |

         Where-Object {$_.Extension -eq "http://"}

$array = New-Object System.Collections.ArrayList

 

foreach ($item in $items)

{

  foreach ($item in $items) {

    $array.Add([pscustomobject]@{

        "Name File" = $item.name

        "Path" = $item.FullName

    }) | Out-Null

}

$array | Export-csv E:\Backup_Testinstance\test2.csv

 

sdfadsfdsafadsf http:// Google.com/search/fddggddfadfdsfdfdfadsfgdadsfdsfdsfd  99999999

sdfadsfdsafadsf http:// van.com/search/fddggddfadfdsfdfdfdsfgdadsfdsfdsfd  99999999

sdfadsfdsafadsf http:// gem.com/search/fddggddfadfdsfdfadsfgdadsfdsfdsfd  99999999

sdfadsfdsafadsf http:// cart.com/search/fddggdfdsfdfdfadsfgdadsfdsfdsfd  99999999

10 Replies

@Shree2280 

I dont know if I miss a point in your code, but in the first line, the Where-Object {$_.Extension -like "https://"}

I don't think this is a valid file extension.

an Empty file in the export means an empty result, lets try the first step

what is the output of this line

$items = Get-ChildItem -LiteralPath "E:\Backup_Testinstance\" | Where-Object {$_.Extension -eq "http://"}

@farismalaeb

 

I tried this  but  getting http  plus some records i do not want records after space

 

Get-ChildItem -Path C:\check\two -recurse | Select-String -Pattern "http://" | ` Select-Object -Property Path,LineNumber,Line | ` Export-CSV "C:\check\ResultFile.csv"

 

Shree

@Shree2280 

 

output coming with space

 

http://hdfcebank.com/jhgsfgdsf kuhsdfkhdsf

@Shree2280 

OK, would you please post a sample of the text file you are reading from.

and also explain a bit more on how the result should look like

Just to give you a small hint, what you need to do is using Regex, but I will wait for your reply to confirm.

 

@farismalaeb 

 

http://hdfcebank.com/jhgsfgdsf ;kkjhadsf;kjnsdf ;kkjhadsf;kjnsdf ;kkjhadsf;kjnsdf ;kkjhadsf;kjnsdf
http://hdfcebank.com/jhgsfgdsf ;kkjhadsf;kjnsdf ;kkjhadsf;kjnsdf ;kkjhadsf;kjnsdf ;kkjhadsf;kjnsdf ;kkjhadsf;kjnsdf
http://cart.com/jhgsfgdsf ;kkjhadsf;kjnsdf ;kkjhadsf;kjnsdf
http://hdfcebank.com/jhgsfgdsf kuhsdfkhdsf
http://hdfcebank.com/jhgsfgdsf uhsfdhkjlsfd
lksdfsdkndsf
;lnskfdkjnsdf
hblshdfkjhdfs

@Shree2280 

 

 

i run it on windows server power shell now it is showing empty file

@Shree2280 

 

Any Sugestions

@Shree2280 

I had created a file and add the sample you provide

and using this code, was able to get the result with only http://websitename without spaces

$items=(($x=Get-Content -Path C:\test.txt).split(";") | where {$_ -like "http://*"})

foreach ($item in $items){
($item.split(" "))[0]
   
    }

 

@farismalaeb 

 

Hi Get_content access is blocked. Any other solution

@Shree2280 

What is the error you are getting, Are you sure that Powershell is running as Administartor.

cause usually the Get-Content will throw an Access Denied exception if reach the file was blocked, but not running the command it self.