Reply to Message

View discussion in a popup

Replying to:
LucD
Leadership
Leadership

That looks ok.
I would make a few small changes to optimise the code

"Please choose an Option to apply security configurations:"
"1- Select Host"
"2- Apply on All ESXi Host"

$options = Read-Host "Enter your Number 1/2"
if ( 1 -eq $options ) {
    $hostname = Read-Host "Please enter your hostname"
    Write-Output "esxi-7.account-auto-unlock-time"
    $esx = Get-VMHost -Name $hostname
    Get-AdvancedSetting -Entity $esx -Name 'Security.AccountUnlockTime' | Set-AdvancedSetting -Value 900 -Confirm:$false -Force

    Get-VM -Location $esx | ForEach-Object -Process {
            Get-VMHost $hostname | New-AdvancedSetting -Entity $_ -Name 'log.keepOld' -Value '10' -Confirm:$false -Force
            Get-VMHost $hostname | New-AdvancedSetting -Entity $_ -Name 'RemoteDisplay.maxConnections' -Value '1' -Confirm:$false -Force
            Get-VMHost $hostname | New-AdvancedSetting -Entity $_ -Name 'log.rotateSize' -Value '2048000' -Confirm:$false -Force

        }
} elseif ( 2 -eq $options ) {
    Write-Output "6- esxi-7.account-auto-unlock-time" | Green
    $esx = Get-VMHost
    Get-AdvancedSetting -Entity $esx -Name 'Security.AccountUnlockTime' | Set-AdvancedSetting -Value 900

    Get-VM -Location $esx |
        ForEach-Object -Process {
            New-AdvancedSetting -Entity $_ -Name 'log.keepOld' -Value '10' -Confirm:$false -Force
            New-AdvancedSetting -Entity $_ -Name 'RemoteDisplay.maxConnections' -Value '1' -Confirm:$false -Force
            New-AdvancedSetting -Entity $_ -Name 'log.rotateSize' -Value '2048000' -Confirm:$false -Force

        }
} else {
    Write-Output "Insert correct number"
}


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

Reply
0 Kudos