VMware Cloud Community
AnonAdmin
Enthusiast
Enthusiast
Jump to solution

cmdlet to copy files to multiple hosts

Is there a PowersCli cmdlet that allows for copying a directory/files to multple ESXi hosts? I'm looking to drop the latest version of vmTools on all 90 hosts across multiple clusters. I guess I could use scp if I needed to but I was hoping to find something more automated.

Thanks in advance!

Reply
0 Kudos
1 Solution

Accepted Solutions
AnonAdmin
Enthusiast
Enthusiast
Jump to solution

Thanks, LucD!

For anyone interested, I created the below script based off of LucD's suggestion of the Posh-SSH module - it seems that the command to copy out an entire directory was dropped and so I instead put each individual file into an array and copied them over in a foreach loop.

 

Install-Module -Name Posh-SSH

$credential = Get-Credential
$ProgressCounter = 0

$Hosts = Get-Content D:\Temp\ServerList.txt 
$Files = gci D:\Temp\vmTools\vmtools_12.3.0\ | % { $_.FullName }

foreach ($ESXhost in $Hosts){
$ProgressCounter = 0
foreach ($File in $Files) {
Set-SCPItem -ComputerName $ESXhost -Credential $credential -Path $File -Destination '/productLocker/vmtools/' -AcceptKey

Write-Host "Copying $File to $ESXhost"
$ProgressCounter++
Write-Progress -Activity "Copying Files" -Status "Progress: $ProgressCounter/$($Files.count)" -PercentComplete (($ProgressCounter / $Files.count) *100)
}
}

View solution in original post

Reply
0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

I assume you mean copying newer versions of the VMware Tools ISO files?
If yes, there is no cmdlet for that afaik.

But you can automate SCP commands easily with the cmdlets from the Posh-SSH module.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
AnonAdmin
Enthusiast
Enthusiast
Jump to solution

Thanks, LucD!

For anyone interested, I created the below script based off of LucD's suggestion of the Posh-SSH module - it seems that the command to copy out an entire directory was dropped and so I instead put each individual file into an array and copied them over in a foreach loop.

 

Install-Module -Name Posh-SSH

$credential = Get-Credential
$ProgressCounter = 0

$Hosts = Get-Content D:\Temp\ServerList.txt 
$Files = gci D:\Temp\vmTools\vmtools_12.3.0\ | % { $_.FullName }

foreach ($ESXhost in $Hosts){
$ProgressCounter = 0
foreach ($File in $Files) {
Set-SCPItem -ComputerName $ESXhost -Credential $credential -Path $File -Destination '/productLocker/vmtools/' -AcceptKey

Write-Host "Copying $File to $ESXhost"
$ProgressCounter++
Write-Progress -Activity "Copying Files" -Status "Progress: $ProgressCounter/$($Files.count)" -PercentComplete (($ProgressCounter / $Files.count) *100)
}
}

Reply
0 Kudos