locked
Filtering URLs results RRS feed

  • Question

  • Good evening all.

    I am trying to automate some config file filling and wondered if anyone can assist with filtering the elements from a get content command.

    I have a folder of shortcuts (*.url) that contain a shortcut text such as 

    [InternetShortcut]
    URL=https://mydataserveracme.com/website1

    [InternetShortcut]
    URL=https://mydataserveracme.com/website2

    ETC. i can send the contents of the files to a file but would like to remove the unwanted text namely:

    [InternetShortcut]

    URL=

    My script looks as below.

    $Text = get-content -Path 'C:\urls\*.url'
    $URLString = ((Select-String '(http[s]?)(:\/\/)([^\s,]+)(?=")' -Input $Text).Matches.Value)

    write-output $Text > c:\configfile.txt

    This appears to wite the contents of each file which is great BUT i only want the URL and wondered if any experts on here can help a novice.

    Thanks

    Saturday, January 5, 2019 8:57 PM

Answers

  • get-content -Path C:\urls\*.url |
        Select-String 'URL=(.*)' | 
        ForEach-Object{$_.Matches.Groups[1].Value}


    \_(ツ)_/

    Saturday, January 5, 2019 9:24 PM

All replies

  • get-content -Path C:\urls\*.url |
        Select-String 'URL=(.*)' | 
        ForEach-Object{$_.Matches.Groups[1].Value}


    \_(ツ)_/

    Saturday, January 5, 2019 9:24 PM
  • Amazing thank you. How simple it was :)
    Monday, January 7, 2019 12:00 PM