Adding Powershell to remove details from a link

Welcome Forums General PowerShell Q&A Adding Powershell to remove details from a link

Viewing 3 reply threads
  • Author
    Posts
    • #248869
      Participant
      Topics: 2
      Replies: 1
      Points: 29
      Rank: Member

      Hi All,

      I have a powershell query which extracts files of sharepoint and downloads them to a specified folder, for another system to combine with another file and emails or prints together.

      However recently we upgraded our Sharepoint and now at the end of each URL there is often ?csf=xyz.

      This recent addition is now causing the our scripts to not download the file.

      I am not sure on how in my below code (this person has left the company) and im just trying to learn, but could not see anywhere on the correct method to do it.

      There is 1 part of the script where data cleansing happens and would be good to know to do it.

      $DownloadPathandName = $DownloadPath + $outputFile
      $DownloadPathandName = $DownloadPathandName -replace “%20″,” ”
      $DownloadPathandName = $DownloadPathandName -replace “ t|n|`r”,””
      $DownloadPathandName = $DownloadPathandName -replace “&”,”&”

      Im just trying to get a strip everything after and include from “?csf=xxxxx”.

      Hoping someone can help me out.

      • This topic was modified 1 month, 2 weeks ago by 1981gkr42.
      • This topic was modified 1 month, 2 weeks ago by 1981gkr42.
    • #249098
      Participant
      Topics: 0
      Replies: 81
      Points: 362
      Helping Hand
      Rank: Contributor

      If you have a string where you want to remove ?csf=xxxx and everything after it, you can do the following:

      See Regex for an explanation of the regex match.

    • #249593
      Participant
      Topics: 15
      Replies: 1774
      Points: 3,210
      Helping Hand
      Rank: Community Hero

      Another option is setting it as URI type to automatically parse the URI components.

      Output:

    • #252077
      Participant
      Topics: 2
      Replies: 1
      Points: 29
      Rank: Member

      Thanking you both for the assistance.

       

      This is now working correctly.

       

      Cheers

      Graeme

Viewing 3 reply threads
  • You must be logged in to reply to this topic.