# Adding Powershell to remove details from a link

**URL:** <https://forums.powershell.org/t/adding-powershell-to-remove-details-from-a-link/14788>\
**Category:** PowerShell Help\
**Created:** [August 11, 2020, 1:47pm UTC](https://forums.powershell.org/t/adding-powershell-to-remove-details-from-a-link/14788 "2020-08-11T13:47:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![1981gkr](https://avatars.discourse-cdn.com/v4/letter/1/58956e/32.png) [@1981gkr](https://forums.powershell.org/u/1981gkr)\
**Post date:** [August 11, 2020, 1:47pm UTC](https://forums.powershell.org/t/adding-powershell-to-remove-details-from-a-link/14788/1 "2020-08-11T13:47:17Z")

</div>

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 “&amp;”,“&”

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

Hoping someone can help me out.

##

---

<div class="post-metadata">

**Author:** ![adminofthings](https://avatars.discourse-cdn.com/v4/letter/a/90ced4/32.png) [@adminofthings](https://forums.powershell.org/u/adminofthings)\
**Post date:** [August 12, 2020, 5:21am UTC](https://forums.powershell.org/t/adding-powershell-to-remove-details-from-a-link/14788/2 "2020-08-12T05:21:37Z")

</div>

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

```
$uri = 'https://sharepoint.domain.com/MyData?csf=xyz&SomethingElse'$newuri = $uri -replace '\?csf=.\*'
```

See [Regex](https://regex101.com/r/c8Lj98/1) for an explanation of the regex match.

---

<div class="post-metadata">

**Author:** ![rob-simmers](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/rob-simmers/32/1010_2.png) [@rob-simmers](https://forums.powershell.org/u/rob-simmers)\
**Post date:** [August 14, 2020, 5:32am UTC](https://forums.powershell.org/t/adding-powershell-to-remove-details-from-a-link/14788/3 "2020-08-14T05:32:05Z")

</div>

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

```
[System.Uri]$uri = 'https://sharepoint.domain.com/MyData?csf=xyz&SomethingElse'

$uri.AbsoluteUri.Replace($uri.Query,'')
```

Output:

```
PS C:\Users\rasim> $uri

AbsolutePath : /MyData
AbsoluteUri : https://sharepoint.domain.com/MyData?csf=xyz&SomethingElse
LocalPath : /MyData
Authority : sharepoint.domain.com
HostNameType : Dns
IsDefaultPort : True
IsFile : False
IsLoopback : False
PathAndQuery : /MyData?csf=xyz&SomethingElse
Segments : {/, MyData}
IsUnc : False
Host : sharepoint.domain.com
Port : 443
Query : ?csf=xyz&SomethingElse
Fragment : 
Scheme : https
OriginalString : https://sharepoint.domain.com/MyData?csf=xyz&SomethingElse
DnsSafeHost : sharepoint.domain.com
IdnHost : sharepoint.domain.com
IsAbsoluteUri : True
UserEscaped : False
UserInfo : 

PS C:\Users\rasim> $uri.AbsoluteUri.Replace($uri.Query,'')

https://sharepoint.domain.com/MyData
```

---

<div class="post-metadata">

**Author:** ![1981gkr](https://avatars.discourse-cdn.com/v4/letter/1/58956e/32.png) [@1981gkr](https://forums.powershell.org/u/1981gkr)\
**Post date:** [August 23, 2020, 8:02pm UTC](https://forums.powershell.org/t/adding-powershell-to-remove-details-from-a-link/14788/4 "2020-08-23T20:02:00Z")

</div>

Thanking you both for the assistance.

&nbsp;

This is now working correctly.

&nbsp;

Cheers

Graeme

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:29pm UTC](https://forums.powershell.org/t/adding-powershell-to-remove-details-from-a-link/14788/5 "2024-05-16T20:29:00Z")

</div>


