Redirecting output to run on either PowerShell 1 or PowerShell 2 or PowerShell3

This topic contains 2 replies, has 3 voices, and was last updated by  Richard Siddaway 4 months, 2 weeks ago.

  • Author
    Posts
  • #72127

    matthew murdock
    Participant

    I am very very new to PowerShell scripting (basically just learned how to create the very simple script). However, I was able to get a script to run to pull information from a Computer using Get-WmiObject. This works on PowerShell ver.1 (windows Server 2008 R2 x64) however, I noticed from reading, the other releases (PS2 and PS3) may not have backward compatibility for PS1 syntax.
    Basicall the code is, along with about 6 or 8 other different commands.

     Get-WmiObject -Class Win32_Desktop -ComputerName . | Select-Object -Property [a-z]* 

    How can I redirect the output to a file on any release of PowerShell?
    If you can include the syntax instead of just the command to use, would help my brain immensely. PowerShell Scripting is not my life.

  • #72130

    Don Jones
    Keymaster

    I'm not sure where you learned that. PowerShell has never, to my knowledge, broken backward compatibility at a syntax level.

    If you want to direct output to a file, use Out-File. If you'd like an example of its extremely simple syntax, run "Help Out-File" from within the shell.

    I'll also heartily recommend "Learn Windows PowerShell in a Month of Lunches" as a wonderful way to learn PowerShell the right way, and to save yourself a lot of grief with some of PowerShell's "gotchas."

  • #72163

    Richard Siddaway
    Moderator

    I've just tried your code on PowerShell 5.1 and it works perfectly well. I'd be very surprised if that code didn't work on any version of PowerShell. My experience is that if you write code for version 1 it'll run on every subsequent version

You must be logged in to reply to this topic.