none
I have two versions of the same module in PowerShell how can i choose which one to use for a script. RRS feed

  • Question

  • I have 2 versions of hyper V.

    How can i import module 1.1 to run my script with? I dont want it to run with 2.0.0.0

     C:\Windows\system32\WindowsPowerShell\v1.0\Modules\Hyper-V\1.1\Hyper-V.psd1
     C:\Windows\system32\WindowsPowerShell\v1.0\Modules\Hyper-V\2.0.0.0\Hyper-V.psd1


    Lishron

    Wednesday, September 16, 2015 6:51 PM

Answers

  • You can also just load both like this:

    import-Module C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\Hyper-V\1.1\Hyper-V.psd1 -Prefix Old_

    Call the  version like this: Get-Old_VM

    Just preface all nouns with the prefix and it will refer to the older version.

    Flexisoft PowerShell.


    \_(ツ)_/

    • Marked as answer by Lishron Wednesday, September 16, 2015 8:14 PM
    Wednesday, September 16, 2015 7:10 PM
  • Try this:

    PS C:\scripts> import-Module C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\Hyper-V\1.1\Hyper-V.psd1
    PS C:\scripts> get-module
    
    ModuleType Version    Name                                ExportedCommands
    ---------- -------    ----                                ----------------
    Binary     1.1        Hyper-V                             {Add-VMDvdDrive, Add-VMFibreChannelHba, Add-VMHardDiskDrive, Add-VMMigrationNetwork...}


    \_(ツ)_/

    • Marked as answer by Lishron Wednesday, September 16, 2015 8:14 PM
    Wednesday, September 16, 2015 7:00 PM

All replies

  • Try this:

    PS C:\scripts> import-Module C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\Hyper-V\1.1\Hyper-V.psd1
    PS C:\scripts> get-module
    
    ModuleType Version    Name                                ExportedCommands
    ---------- -------    ----                                ----------------
    Binary     1.1        Hyper-V                             {Add-VMDvdDrive, Add-VMFibreChannelHba, Add-VMHardDiskDrive, Add-VMMigrationNetwork...}


    \_(ツ)_/

    • Marked as answer by Lishron Wednesday, September 16, 2015 8:14 PM
    Wednesday, September 16, 2015 7:00 PM
  • You can also just load both like this:

    import-Module C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\Hyper-V\1.1\Hyper-V.psd1 -Prefix Old_

    Call the  version like this: Get-Old_VM

    Just preface all nouns with the prefix and it will refer to the older version.

    Flexisoft PowerShell.


    \_(ツ)_/

    • Marked as answer by Lishron Wednesday, September 16, 2015 8:14 PM
    Wednesday, September 16, 2015 7:10 PM
  • That was it!

    Thanks!

    That also took care of the issue i was having running the hyper V script in the post yesterday.  I looked at my win 8 machine and my 10 and noticed it was running 2 versions of Hyper V module.  By adding the below line in to the script on my 10 machine it is now working on both my 8.1 and 10!

    Thank you!  

    try {import-Module C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\Hyper-V\1.1\Hyper-V.psd1 -ErrorAction Stop} catch {}



    Lishron


    • Edited by Lishron Wednesday, September 16, 2015 8:20 PM
    Wednesday, September 16, 2015 8:18 PM
  • You are welcome. I am glad it worked out.

    \_(ツ)_/

    Wednesday, September 16, 2015 8:52 PM