0

I'am trying to use the return string from the function as file name for the downloaded file as timestamp. I'm not shure, why is does not work. Can you help me please?

Thank you!

    Push-Location $(Split-Path $Script:MyInvocation.MyCommand.Path)
Invoke-WebRequest https://chartership.eu/images/preislisten/CS-Preis-Belegung.xlsx.pdf -Outfile Get-TimeStamp

function Get-TimeStamp {

    return "[{0:MM/dd/yy} {0:HH:mm:ss}].pdf" -f (Get-Date)

}
1
  • If you problem has been answered satisfactorily, please mark it as the answer. If not, please comment on what you still are having trouble with. Commented May 3, 2020 at 21:06

1 Answer 1

1

Windows doesn't allow : in the filename. Additionally, PowerShell really doesn't like [ or ] in folder or filenames, either. I really just changed the format string and added parenthesis around Get-TimeStamp so it would call the function instead of using that as the filename.

This worked for me:

function Get-TimeStamp {
    "{0:MM-dd-yy} {0:HH_mm_ss}.pdf" -f (Get-Date)
}

Push-Location $(Split-Path $Script:MyInvocation.MyCommand.Path)

Invoke-WebRequest  https://chartership.eu/images/preislisten/CS-Preis-Belegung.xlsx.pdf -Outfile (Get-TimeStamp)
Sign up to request clarification or add additional context in comments.

2 Comments

You can simplify with "{0:MM-dd-yy HH_mm_ss}.pdf" -f (Get-Date)
Indeed you can. I was just working with what was provided.

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.