Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
46 lines (41 sloc) 1.57 KB
param (
[string] $resourceGroupName = "crankier",
[string] $vmNamePrefix = "crankier",
[string] $command = "printenv"
)
$vms = Get-AzVM
$password = "mypassword" | ConvertTo-SecureString -asPlainText -Force
$username = "crankier"
$credential = New-Object System.Management.Automation.PSCredential($username,$password)
$addresses = Get-AzPublicIpAddress | select -ExpandProperty DnsSettings | select -ExpandProperty Fqdn | where {$_.Contains("client")}
[System.Collections.ArrayList]$jobs = @()
$blockSize = 5
$count = $addresses.Count / $blockSize
#Write-Host $count in $addresses.Count
for ($i = 0 ; $i -le $count; $i++) {
#Write-Host i = $i
$start = $i*$blockSize
$end = $start + $blockSize-1
foreach ($fqdn in $addresses[$start..$end]) {
#Write-Host $fqdn
$job = Start-Job -ScriptBlock {
param([string]$fqdn, [System.Management.Automation.PSCredential] $credential, [string] $command)
Remove-SSHTrustedHost $fqdn
$session = New-SSHSession -ComputerName $fqdn -KeyFile ~\.ssh\id_rsa -credential $credential -AcceptKey
$result = Invoke-SSHCommand $session $command
Write-Host $result.Output
if ((Remove-SSHSession $session) -eq $true) {
} else {
Write-Host Could not close $session
}
} `
-ArgumentList $fqdn, $credential, $command
$length = $jobs.Add($job)
}
while ($jobs.Count -gt 0) {
$job = $jobs | Wait-Job -Any
$data = Receive-Job $job
Write-Host $data
$jobs.Remove($job)
}
}
You can’t perform that action at this time.