VMware Cloud Community
skiser
Contributor
Contributor
Jump to solution

Any way to send asynchronis logins to ESXi host?

I have a need to send 50 failed logins to an ESXi host within a 5 minute time span to generate a security alert. This alert would be triggered on a scheduled basis to prove that alerting is working. Here's a snippit of the code I tried, however it takes about 10 seconds for each failed attempt, which puts me over the 5 minute mark.

1..50 | % {
     Connect-VIServer $myhost -User $TestUser -Password $TestPass -Port 443 -ErrorAction SilentlyContinue
}

Does anyone know of a way to send asynchronis logins to an ESXi host?

Thanks in advance!

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

In that case, you can use a Workflow with the Parallel switch

Workflow TestConnect {
  Param(
    [string]$Server,
    [String]$User,
    [String]$Pswd,
    [int]$Number
  )
  ForEach -Parallel ($i in (1..$number)) {
    Connect-VIServer -Server $Server -User $User -Password $pswd -Port 443 -ErrorAction SilentlyContinue
  }
}

TestConnect -Server 'myvcsa.some.domain'  -User 'me' -Pswd 'lala' -Number 50


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

View solution in original post

4 Replies
LucD
Leadership
Leadership
Jump to solution

When you are using PSv7, you could use the Parallel parameter.
Remember to use the 'using:' qualifier if referencing variables defined outside the Parallel code block

 

$myhost = 'myvcsa.some.domain'
$TestUser = 'me'
$TestPass = 'lala'

1..50 | ForEach-Object -Parallel {
  Connect-VIServer $using:myhost -User $using:TestUser -Password $using:TestPass -Port 443 -ErrorAction SilentlyContinue
}

 


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

0 Kudos
skiser
Contributor
Contributor
Jump to solution

@LucD Thank you. Unfortunately we are using PSv5 in this particular environment.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

In that case, you can use a Workflow with the Parallel switch

Workflow TestConnect {
  Param(
    [string]$Server,
    [String]$User,
    [String]$Pswd,
    [int]$Number
  )
  ForEach -Parallel ($i in (1..$number)) {
    Connect-VIServer -Server $Server -User $User -Password $pswd -Port 443 -ErrorAction SilentlyContinue
  }
}

TestConnect -Server 'myvcsa.some.domain'  -User 'me' -Pswd 'lala' -Number 50


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

skiser
Contributor
Contributor
Jump to solution

@LucD Thank you, Luc! That works like a champ.

0 Kudos