Powershell Module

Glenn Maxwell 10,146 Reputation points
2024-04-14T06:41:43.02+00:00

Hi All

I have a Azure Virtual Machine which is running on Windows Server 2012 R2, i want to decommission this VM. This VM has many powershell modules installed. I came up with a new 2019 VM. I want to install the same PowerShell modules on the new VM. How can i export the list of powershell modules installed on my Windows Server 2012R2 machine so that i can install the same on the new VM. On my new VM i want the powershell modules to be used by any user who logs in, when i install the powershell module if i use this switch -Scope Allusers will this work. Before installing powershell modules should i use the below syntax as i will schedule some powershell scripts through task scheduler using service account.

Set-ExecutionPolicy -ExecutionPolicy Unrestricted

Windows Server 2019
Windows Server 2019
A Microsoft server operating system that supports enterprise-level management updated to data storage.
3,464 questions
Windows Server 2016
Windows Server 2016
A Microsoft server operating system that supports enterprise-level management updated to data storage.
2,374 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,377 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,069 questions
0 comments No comments
{count} votes

Accepted answer
  1. Marcin Policht 10,845 Reputation points MVP
    2024-04-14T11:11:14.1666667+00:00

    To export the list of PowerShell modules installed on your Windows Server 2012 R2 machine, you can use the Get-Module cmdlet with the -ListAvailable parameter to retrieve a list of all installed modules. You can then export this list to a text file for reference.

    Run the following command to retrieve a list of installed PowerShell modules:

    Get-Module -ListAvailable | Select-Object Name, Version | Export-Csv -Path C:\Path\To\Export\Modules.csv -NoTypeInformation
    
    

    Copy the exported Modules.csv file to your new Windows Server 2019 VM. On your new VM running Windows Server 2019, open PowerShell as an administrator. Run the following command to install the PowerShell modules listed in the Modules.csv file:

    $modules = Import-Csv -Path C:\Path\To\Export\Modules.csv
    foreach ($module in $modules) {
        Install-Module -Name $module.Name -Scope AllUsers -Force
    }
    
    

    You can bypass the dxecution policy by using the -ExecutionPolicy Bypass parameter with the powershell.exe command in your Task Scheduler action.


    If the above response helps answer your question, remember to "Accept Answer" so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.

    hth

    Marcin

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Ian Xue (Shanghai Wicresoft Co., Ltd.) 29,891 Reputation points Microsoft Vendor
    2024-04-15T02:01:28.5366667+00:00

    Hi Glenn Maxwell,

    On Windows Server the default execution policy is RemoteSigned so it's allowed to run local scripts on your machine and there is no need to set the execution policy to Unrestricted unless your script is downloaded from Internet.

    Best Regards,

    Ian Xue


    If the Answer is helpful, please click "Accept Answer" and upvote it.

    0 comments No comments