- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Actually I want to apply some configuration on hosts and some configurations on VMS
when we choose 1 and enter host name follow parameters should apply on specific host :
$clusterName= Read-Host "Please enter your cluster_name"
"There are follow Hosts in your cluster:"
Get-VMHost | Format-Table Name
"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"
Get-VMHost $hostname | Get-AdvancedSetting Security.AccountUnlockTime | Set-AdvancedSetting -Value 900
}
After apply above changes on esxi host need to apply some configuration parameters on VMs on that host so I used this
Get-Cluster -Name $clusterName | Get-VM |
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
}
Now the other option is 2 when the user choose it means want to apply configuration on all hosts and VMS so use this one to apply changes on all hosts :
if
( 2 -eq $options )
{
Write-Output "6- esxi-7.account-auto-unlock-time" | Green
Get-VMHost | Get-AdvancedSetting Security.AccountUnlockTime | Set-AdvancedSetting -Value 900
and apply follow changes on all vms
Get-Cluster -Name $clusterName | Get-VM |
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
so finally wrote this one :
$clusterName= Read-Host "Please enter your cluster_name"
"There are follow Hosts in your cluster:"
Get-VMHost | Format-Table Name
"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"
Get-VMHost $hostname | Get-AdvancedSetting Security.AccountUnlockTime | Set-AdvancedSetting -Value 900
}
Get-Cluster -Name $clusterName | Get-VM |
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
}
if
( 2 -eq $options )
{
Write-Output "6- esxi-7.account-auto-unlock-time" | Green
Get-VMHost | Get-AdvancedSetting Security.AccountUnlockTime | Set-AdvancedSetting -Value 900
Get-Cluster -Name $clusterName | Get-VM |
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"
}
What is the issue ?