Forum Discussion

Alan1679's avatar
Alan1679
Copper Contributor
Sep 15, 2026
Solved

How to save powershell script to a text file on desktop?

I am learning out-file and I want to save this to desktop as text file.

get-date | get-member -name "AddM*" | out-file -filepath "C:\Users\yungm\desktop \ test.txt"

It doesn't work. What did I do wrong?

 

Thanks

  • I'd probably suggest formatting your code, but you have space after desktop in your path which is probably ur issue. I also would remove the space before test, but technically that would work. before test, that's probably the issue.

3 Replies

  • nrvonogd's avatar
    nrvonogd
    Brass Contributor

    I'd probably suggest formatting your code, but you have space after desktop in your path which is probably ur issue. I also would remove the space before test, but technically that would work. before test, that's probably the issue.

    • Alan1679's avatar
      Alan1679
      Copper Contributor

      Thanks Nrvonogd

      I am surprised the two spaces caused the problem. I thought PowerShell ignore empty space!!

      I am glad it works because I am running out of ideas.

      Thanks

      • nrvonogd's avatar
        nrvonogd
        Brass Contributor

        Well - there's a difference in empty space in code and empty space in a path. Spaces are supported in windows paths, so PowerShell has no idea if it should trim that space or leave it. Since spaces are supported in paths, it's not going to ignore it. I hope that helps better explain why.