Powershell Module

Glenn Maxwell 13,141 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 for business | Windows Server | User experience | PowerShell
Windows for business | Windows Server | User experience | Other
0 comments No comments
{count} votes

Answer accepted by question author
  1. Marcin Policht 73,320 Reputation points MVP Volunteer Moderator
    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. Anonymous
    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

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.