Last active
October 26, 2021 02:36
-
-
Save Rugby-Ball/affb4754827f769e9fb93367cb41bc09 to your computer and use it in GitHub Desktop.
Use this to backup you installed PowerShell Modules to a PS1 file so you can re-install onto another computer. #Utility #Backup #PowerShell-Modules #Powershell #Public
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #Backup-my-installed-posh-modules.ps1 | |
| # Use this to backup your installed PowerShell Modules to a PS1 file so you can re-install onto another computer. | |
| ##Check if c:\scripts\powershell\backups exists, if it doesnt create it. | |
| $foldertest = "c:\scripts\powershell\backups" | |
| If (-not(Test-Path -Path $foldertest)) | |
| { New-Item -ItemType Directory -Force -Path $foldertest } | |
| #Pull installed modules and join them in a single line comma seperated. | |
| $Modules_Installed = (Get-InstalledModule | sort name).name -join "," | |
| #Build the install Module Powershell line. | |
| $Backup_module_installer = "install-module -name $Modules_Installed" | |
| #Create a ps1 file to run on a new machine to install all the Modules you just backed up. | |
| $Backup_module_installer | Out-File -FilePath (join-path $foldertest "PowerShell-Installed-module-Backup-$(get-date -f yyyy-MM-dd-HH-mm-ss).ps1") | |
| #You can add an entry here to move the file to an S3 bucket, Azure Blob or a Network Folder for a more secure backup. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment