From 93c4a12927028f510f6186bc5d557d5687f16d67 Mon Sep 17 00:00:00 2001 From: Charlie Silverman Date: Sun, 18 Oct 2026 12:24:37 -0700 Subject: [PATCH] Update RunESXiCommand.ps1 --- vSphere Tools/RunESXiCommand.ps1 | 33 +++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/vSphere Tools/RunESXiCommand.ps1 b/vSphere Tools/RunESXiCommand.ps1 index 89f2e88..c77ae4f 100644 --- a/vSphere Tools/RunESXiCommand.ps1 +++ b/vSphere Tools/RunESXiCommand.ps1 @@ -1,4 +1,4 @@ -#requires -Modules posh-ssh +##requires -Modules posh-ssh param ( [string]$vCenter = "", @@ -9,8 +9,8 @@ param ( ) # Variables -$FileVersion = "1.0.1" -$FileDate = "2026-04-18" +$FileVersion = "1.1.0" +$FileDate = "2026-10-06" # Display Script Banner Write-Host "--------------------------------------------------" -ForegroundColor White @@ -19,6 +19,31 @@ Write-Host "Version $($FileVersion) ($($FileDate))" -ForegroundColor Green Write-Host "Written by Charlie Silverman" -ForegroundColor Green Write-Host "--------------------------------------------------" -ForegroundColor White +function CheckModuleInstalled($moduleName, $command) { + Write-Host "Checking that package $moduleName is installed..." -NoNewLine + if (-not(get-command $command -erroraction silentlycontinue)) { + Write-Host " Missing" -ForegroundColor Red + if (-not (Get-Module -ListAvailable -Name $moduleName)) { + $response = "" + while (($response -ne "yes") -and ($response -ne "no")) { + $response = (Read-Host "$moduleName module not instaled. Install now? (yes/no)").ToLower() + } + if ($response -eq "no") { + Write-Host "Operation Cancelled." -ForegroundColor Yellow + exit + } + Write-Host "Installing PowerShell module $moduleName..." -NoNewLine + Install-Module -Name $moduleName -Scope CurrentUser -Force + Write-Host " Success" -ForegroundColor Green + } + Write-Host "Loading PowerShell module $moduleName..." -NoNewLine + Import-Module $moduleName + Write-Host " Success" -ForegroundColor Green + } else { + Write-Host " Found" -ForegroundColor Green + } +} + if ($Help) { Write-Host Write-Host "Purpose: Run a CLI command on all hosts in a cluster." @@ -44,6 +69,8 @@ if ($Help) { exit } +CheckModuleInstalled -moduleName "posh-ssh" -command "New-SSHSession" + $quiet = Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false if ($vCenter -eq "") {