0

I am using the following script to create URLs.

$files1 =Get-ChildItem $ENV:WORKSPACE/Pro_result
$prefix="https://test-jenkins-a-master-black.aws.jhgf.com/job/qa/job/TestDemo_email_PDF/ws/Pro_result/"
foreach ($file in $files1) {
  write-Output ($prefix+$file.Name)
 }

However, I am getting a url like this and I have no control over the filename https://test-jenkins-a-master-black.aws.jhgf.com/job/qa/job/TestDemo_email_PDF/ws/Pro_result/W0A-209-193-210_Dealer portal production smoke test_20220427-120342.pdf

It breaks after portal. How do I fix this?

1 Answer 1

2

Use the [uri]::EscapeUriString method to escape spaces and similar characters in URI paths:

foreach ($file in $files1) {
  [uri]::EscapeUriString($prefix+$file.Name)
}

This will correctly re-encode the spaces as %20, resulting in a valid URL with no whitespace a la:

https://test-jenkins-a-master-black.aws.jhgf.com/job/qa/job/TestDemo_email_PDF/ws/Pro_result/W0A-209-193-210_Dealer%20portal%20production%20smoke%20test_20220427-120342.pdf
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.