VMware Cloud Community
baber
Expert
Expert

How can change script to apply AdvancedSetting on all hosts in the cluster / vCenter

I have written this script :

function Green
{
process { Write-Host $_ -ForegroundColor Green }
}

function Red
{
process { Write-Host $_ -ForegroundColor Red }
}
$vcsa= Read-Host "Please enter your VCSA IP/FQDN"
Connect-VIServer -server $vcsa
"There are follow Hosts in your cluster:"
Get-VMHost | Format-Table Name
"Please Press any key to apply changes:"
Read-Host
Write-Output "6- esxi-7.account-auto-unlock-time" | Green

At the first step it shows all hosts in vCenter and after that I have a few changes that want to apply such as below:

Write-Output "6- esxi-7.account-auto-unlock-time" | Green
Get-AdvancedSetting Security.AccountUnlockTime | Set-AdvancedSetting -Value 900
Write-Output "7- esxi-7.account-lockout" | Green
Get-AdvancedSetting Security.AccountLockFailures | Set-AdvancedSetting -Value 3

How should change it ?

Please mark helpful or correct if my answer resolved your issue.
0 Kudos
1 Reply
LucD
Leadership
Leadership

You could do

Get-VMHost |
ForEach-Object -Process {
    Get-AdvancedSetting -Entity $_ -Name 'Security.AccountUnlockTime' | 
        Set-AdvancedSetting -Value 900
    Get-AdvancedSetting -Entity $_ -Name 'Security.AccountLockFailures' | 
        Set-AdvancedSetting -Value 3
}


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

0 Kudos