Skip to content

Instantly share code, notes, and snippets.

@joel74
Created March 1, 2017 19:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save joel74/f5acb78ca7dbe0d87bc95cab98de1388 to your computer and use it in GitHub Desktop.
Save joel74/f5acb78ca7dbe0d87bc95cab98de1388 to your computer and use it in GitHub Desktop.
PowerShell script to install F5-LTM module
# This script will download the latest version of the F5-LTM PowerShell module from github and install it for the current user.
# Thanks to DarkOperator for doing all the heavy lifting for this snippet
# https://gist.github.com/darkoperator/3f9da4b780b5a0206bca
# Make sure the module is not loaded
Remove-Module F5-LTM -ErrorAction SilentlyContinue
# Download latest version
$webclient = New-Object System.Net.WebClient
$url = "https://github.com/joel74/POSH-LTM-Rest/archive/master.zip"
Write-Output "Downloading latest version of F5-LTM from $url" -ForegroundColor Cyan
$file = "$($env:TEMP)\F5-LTM.zip"
$webclient.DownloadFile($url,$file)
Write-Output "File saved to $file" -ForegroundColor Green
# Unblock and decompress
Unblock-File -Path $file
$targetondisk = "$($env:USERPROFILE)\Documents\WindowsPowerShell\Modules"
New-Item -ItemType Directory -Force -Path $targetondisk | out-null
$shell_app=new-object -com shell.application
$zip_file = $shell_app.namespace($file)
Write-Output "Uncompressing the Zip file to $($targetondisk)" -ForegroundColor Cyan
$destination = $shell_app.namespace($targetondisk)
$destination.Copyhere($zip_file.items(), 0x10)
# Rename and import
Write-Output "Renaming folder" -ForegroundColor Cyan
Rename-Item -Path ($targetondisk+"\POSH-LTM-Rest-master") -NewName "F5-LTM" -Force
Write-Output "Module has been installed" -ForegroundColor Green
Import-Module -Name F5-LTM
Get-Command -Module F5-LTM
@myclau
Copy link

myclau commented Jul 19, 2017

seems the last few lines have some problem, I change it a little bit in order to work:
(from line 26 to end):

# Rename and import
Write-Output "Renaming folder" -ForegroundColor Cyan
Move-Item -Path ($targetondisk+"\POSH-LTM-Rest-master\F5-LTM") -Destination ($targetondisk+"\F5-LTM") -Force
Remove-Item -Path ($targetondisk+"\POSH-LTM-Rest-master") -Force -Recurse
Write-Output "Module has been installed" -ForegroundColor Green
Import-Module -Name F5-LTM
Get-Command -Module F5-LTM

@spuder
Copy link

spuder commented Jul 16, 2018

Not working for me

Module has been installed
-ForegroundColor
Green
Import-Module : The specified module 'F5-LTM' was not loaded because no valid module file was found in any module directory.
At C:\Users\sowen\powerform\lib\F5-Rest.ps1:34 char:5
+     Import-Module -Name F5-LTM
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (F5-LTM:String) [Import-Module], FileNotFoundException
    + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand

@tchia04
Copy link

tchia04 commented Aug 16, 2018

I manually moved the F5-LTM folder from $($env:USERPROFILE)\Documents\WindowsPowerShell\Modules to C:\Program Files\WindowsPowerShell\Modules for the "Get-Command -Module F5-LTM" to work. I am on windows 7 with powershell 4

@ShaneJ7769
Copy link

Working updated script for anyone who follows:

# This script will download the latest version of the F5-LTM PowerShell module from github and install it for the current user.
# Thanks to DarkOperator for doing all the heavy lifting for this snippet
# https://gist.github.com/darkoperator/3f9da4b780b5a0206bca

# Make sure the module is not loaded
Remove-Module F5-LTM -ErrorAction SilentlyContinue

# Download latest version
$webclient = New-Object System.Net.WebClient
$url = "https://github.com/joel74/POSH-LTM-Rest/archive/master.zip"
Write-Host "Downloading latest version of F5-LTM from $url" -ForegroundColor Cyan
$file = "$($env:TEMP)\F5-LTM.zip"
$webclient.DownloadFile($url,$file)
Write-Host "File saved to $file" -ForegroundColor Green

# Unblock and decompress
Unblock-File -Path $file
$targetondisk = "$($env:USERPROFILE)\Documents\WindowsPowerShell\Modules"
# no need to handle, this folder should just exist
New-Item -ItemType Directory -Force -Path $targetondisk -ErrorAction SilentlyContinue | out-null

# Unzip 
Write-Host "Uncompressing the Zip file to $($targetondisk)" -ForegroundColor Cyan
$shell_app=new-object -com shell.application
$zip_file = $shell_app.namespace($file)
$destination = $shell_app.namespace($targetondisk)
$destination.Copyhere($zip_file.items(), 0x10)

# Rename and import
Write-Host "Renaming folder" -ForegroundColor Cyan

if (Test-Path ($targetondisk+"\F5-LTM")) {
    Write-Host "Removing prior $($targetondisk+"\F5-LTM") folder" -ForegroundColor Yellow
    Remove-Item -Recurse -Force -Path ($targetondisk+"\F5-LTM")  | out-null    
}
Move-Item -Path ($targetondisk+"\POSH-LTM-Rest-master") -Destination "$($targetondisk+"\F5-LTM")" -Force  | out-null   

Write-Host "Module has been installed" -ForegroundColor Green
Import-Module -Name "$($targetondisk+"\F5-LTM\F5-LTM")" # Zip file has a sub F5-LTM folder with the module
Get-Command -Module F5-LTM

@jquirogat1820
Copy link

Hello @ShaneJ7769 thks por this code, it is work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment