extract http data

%3CLINGO-SUB%20id%3D%22lingo-sub-2102527%22%20slang%3D%22en-US%22%3Eextract%20http%20data%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2102527%22%20slang%3D%22en-US%22%3E%3CP%20class%3D%22x_MsoNormal%22%3EHi%20expert%2C%3C%2FP%3E%3CP%20class%3D%22x_MsoNormal%22%3EI%20am%20trying%20to%20extract%20http%3A%2F%2F%20URL%20from%20given%20file%20but%20getting%20empty%20file%20in%20export%3C%2FP%3E%3CP%20class%3D%22x_MsoNormal%22%3Ehere%20is%20the%20code%3C%2FP%3E%3CP%20class%3D%22x_MsoNormal%22%3E%24items%20%3D%20Get-ChildItem%20-LiteralPath%20%22E%3A%5CBackup_Testinstance%5C%22%20%7C%3C%2FP%3E%3CP%20class%3D%22x_MsoNormal%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Where-Object%20%7B%24_.Extension%20-eq%20%22http%3A%2F%2F%22%7D%3C%2FP%3E%3CP%20class%3D%22x_MsoNormal%22%3E%24array%20%3D%20New-Object%20System.Collections.ArrayList%3C%2FP%3E%3CP%20class%3D%22x_MsoNormal%22%3E%26nbsp%3B%3C%2FP%3E%3CP%20class%3D%22x_MsoNormal%22%3Eforeach%20(%24item%20in%20%24items)%3C%2FP%3E%3CP%20class%3D%22x_MsoNormal%22%3E%7B%3C%2FP%3E%3CP%20class%3D%22x_MsoNormal%22%3E%26nbsp%3B%20foreach%20(%24item%20in%20%24items)%20%7B%3C%2FP%3E%3CP%20class%3D%22x_MsoNormal%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%24array.Add(%5Bpscustomobject%5D%40%7B%3C%2FP%3E%3CP%20class%3D%22x_MsoNormal%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%22Name%20File%22%20%3D%20%24item.name%3C%2FP%3E%3CP%20class%3D%22x_MsoNormal%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%22Path%22%20%3D%20%24item.FullName%3C%2FP%3E%3CP%20class%3D%22x_MsoNormal%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7D)%20%7C%20Out-Null%3C%2FP%3E%3CP%20class%3D%22x_MsoNormal%22%3E%7D%3C%2FP%3E%3CP%20class%3D%22x_MsoNormal%22%3E%24array%20%7C%20Export-csv%20E%3A%5CBackup_Testinstance%5Ctest2.csv%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Esdfadsfdsafadsf%20http%3A%2F%2F%20Google.com%2Fsearch%2Ffddggddfadfdsfdfdfadsfgdadsfdsfdsfd%26nbsp%3B%2099999999%3C%2FP%3E%3CP%3Esdfadsfdsafadsf%20http%3A%2F%2F%20van.com%2Fsearch%2Ffddggddfadfdsfdfdfdsfgdadsfdsfdsfd%26nbsp%3B%2099999999%3C%2FP%3E%3CP%3Esdfadsfdsafadsf%20http%3A%2F%2F%20gem.com%2Fsearch%2Ffddggddfadfdsfdfadsfgdadsfdsfdsfd%26nbsp%3B%2099999999%3C%2FP%3E%3CP%3Esdfadsfdsafadsf%20http%3A%2F%2F%20cart.com%2Fsearch%2Ffddggdfdsfdfdfadsfgdadsfdsfdsfd%26nbsp%3B%2099999999%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2102527%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3Eextract%20data%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2103146%22%20slang%3D%22en-US%22%3ERe%3A%20extract%20http%20data%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2103146%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F665447%22%20target%3D%22_blank%22%3E%40Shree2280%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20dont%20know%20if%20I%20miss%20a%20point%20in%20your%20code%2C%20but%20in%20the%20first%20line%2C%20the%20Where-Object%20%7B%24_.Extension%20-like%20%22https%3A%2F%2F%22%7D%3C%2FP%3E%3CP%3EI%20don't%20think%20this%20is%20a%20valid%20file%20extension.%3C%2FP%3E%3CP%3Ean%20Empty%20file%20in%20the%20export%20means%20an%20empty%20result%2C%20lets%20try%20the%20first%20step%3C%2FP%3E%3CP%3Ewhat%20is%20the%20output%20of%20this%20line%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3E%24items%20%3D%20Get-ChildItem%20-LiteralPath%20%22E%3A%5CBackup_Testinstance%5C%22%20%7C%20Where-Object%20%7B%24_.Extension%20-eq%20%22http%3A%2F%2F%22%7D%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2103193%22%20slang%3D%22en-US%22%3ERe%3A%20extract%20http%20data%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2103193%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F790105%22%20target%3D%22_blank%22%3E%40farismalaeb%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20tried%20this%26nbsp%3B%20but%26nbsp%3B%20getting%20http%26nbsp%3B%20plus%20some%20records%20i%20do%20not%20want%20records%20after%20space%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EGet-ChildItem%20-Path%20C%3A%5Ccheck%5Ctwo%20-recurse%20%7C%20Select-String%20-Pattern%20%22http%3A%2F%2F%22%20%7C%20%60%20Select-Object%20-Property%20Path%2CLineNumber%2CLine%20%7C%20%60%20Export-CSV%20%22C%3A%5Ccheck%5CResultFile.csv%22%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EShree%3C%2FP%3E%3C%2FLINGO-BODY%3E
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.