locked
Multiple computers, different PS versions, sinlge script? RRS feed

  • Question

  • Our Windows servers whose PowerShell versions running from v2, to v5.  I want to write a script, using v5,  that updates several of them. How do I code for all the versions? (For example, is there a list of v2 cmdlets that I should restrict my code to?)

    TIA,

    edm2

    Sunday, December 3, 2017 9:13 PM

Answers

  • Place the following line at the very top of your script:

    #requires -version 2

    Any time you try yo use a non-V2 CmdLet or syntax the script will warn you.

    help about_requires


    \_(ツ)_/

    • Marked as answer by edm2 Sunday, December 3, 2017 10:20 PM
    Sunday, December 3, 2017 9:54 PM

All replies

  • Place the following line at the very top of your script:

    #requires -version 2

    Any time you try yo use a non-V2 CmdLet or syntax the script will warn you.

    help about_requires


    \_(ツ)_/

    • Marked as answer by edm2 Sunday, December 3, 2017 10:20 PM
    Sunday, December 3, 2017 9:54 PM
  • Jrv,

    You know your stuff!  "Live long and prosper"!

    edm2

    Sunday, December 3, 2017 10:20 PM