<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Why if condition does not work correctly in my script in VMware PowerCLI Discussions</title>
    <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Why-if-condition-does-not-work-correctly-in-my-script/m-p/2943264#M109502</link>
    <description>&lt;P&gt;In the last code, I posted those 2 options are already there&lt;BR /&gt;&lt;BR /&gt;Option 1&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;$esx = Get-VMHost -Name $hostname&lt;/LI-CODE&gt;
&lt;P&gt;Option 2&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;$esx = Get-VMHost&lt;/LI-CODE&gt;
&lt;P&gt;Not sure what you don't understand.&lt;BR /&gt;With option1 there is 1 ESXi node in the $esx variable.&lt;BR /&gt;With option 2 all the ESXi nodes are in the $esx variable&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 11 Dec 2022 12:00:38 GMT</pubDate>
    <dc:creator>LucD</dc:creator>
    <dc:date>2022-12-11T12:00:38Z</dc:date>
    <item>
      <title>Why if condition does not work correctly in my script</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Why-if-condition-does-not-work-correctly-in-my-script/m-p/2943210#M109488</link>
      <description>&lt;P&gt;I have written follow script with if condition but when I choose 3 it shows many error although I want it just show "Insert correct digit"&lt;/P&gt;&lt;P&gt;"Please choose an Option to apply configurations:"&lt;BR /&gt;"1- Select Host"&lt;BR /&gt;"2- Apply on All ESXi Host"&lt;/P&gt;&lt;P&gt;$options= Read-Host "Enter your Number 1/2"&lt;BR /&gt;if ( 1 -eq $options )&lt;BR /&gt;{&lt;/P&gt;&lt;P&gt;$hostname= read-host "Please enter your hostname"&lt;BR /&gt;Write-Output "esxi-7.account-auto-unlock-time" | Green&lt;BR /&gt;&lt;SPAN&gt;Get-VMHost $hostname | Get-AdvancedSetting Security.AccountUnlockTime | Set-AdvancedSetting -Value 900&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;if ( 2 -eq $options )&lt;BR /&gt;{&lt;/P&gt;&lt;P&gt;Write-Output "6- esxi-7.account-auto-unlock-time" | Green&lt;BR /&gt;Get-VMHost | Get-AdvancedSetting Security.AccountUnlockTime | Set-AdvancedSetting -Value 900&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;else {&lt;BR /&gt;Write-Output "Insert correct number"&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;When insert 3 it shows follow error&amp;nbsp;&lt;/P&gt;&lt;P&gt;Get-VMHost : Cannot validate argument on parameter 'Name'. The argument is null or empty. Provide an argument that is&lt;BR /&gt;not null or empty, and then try the command again.&lt;BR /&gt;At C:\HP server\security.ps1:92 char:14&lt;BR /&gt;+ Get-VMHost $hostname | New-AdvancedSetting -Entity $_ -Name log.kee ...&lt;BR /&gt;+ ~~~~~~~~~&lt;BR /&gt;+ CategoryInfo : InvalidData: (:) [Get-VMHost], ParameterBindingValidationException&lt;BR /&gt;+ FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVMHost&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Although it just shows&amp;nbsp;Insert correct number&lt;/P&gt;</description>
      <pubDate>Sat, 10 Dec 2022 16:34:33 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Why-if-condition-does-not-work-correctly-in-my-script/m-p/2943210#M109488</guid>
      <dc:creator>baber</dc:creator>
      <dc:date>2022-12-10T16:34:33Z</dc:date>
    </item>
    <item>
      <title>Re: Why if condition does not work correctly in my script</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Why-if-condition-does-not-work-correctly-in-my-script/m-p/2943212#M109489</link>
      <description>&lt;P&gt;Your code works perfectly for me.&lt;BR /&gt;Judging from the line number in the error message (line 92) there is more code you are not showing.&lt;BR /&gt;The error might be happening there&lt;/P&gt;</description>
      <pubDate>Sat, 10 Dec 2022 17:04:37 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Why-if-condition-does-not-work-correctly-in-my-script/m-p/2943212#M109489</guid>
      <dc:creator>LucD</dc:creator>
      <dc:date>2022-12-10T17:04:37Z</dc:date>
    </item>
    <item>
      <title>Re: Why if condition does not work correctly in my script</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Why-if-condition-does-not-work-correctly-in-my-script/m-p/2943216#M109490</link>
      <description>&lt;P&gt;Yes . The problem relates to this part that&amp;nbsp; I resided it between 2 if&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Get-Cluster -Name $clusterName | Get-VM |&lt;BR /&gt;ForEach-Object -Process {&lt;BR /&gt;Get-VMHost $hostname | New-AdvancedSetting -Entity $_ -Name log.keepOld -Value '10' -Confirm:$false -Force&lt;BR /&gt;Get-VMHost $hostname | New-AdvancedSetting -Entity $_ -Name RemoteDisplay.maxConnections -Value '1' -Confirm:$false -Force&lt;BR /&gt;Get-VMHost $hostname | New-AdvancedSetting -Entity $_ -Name log.rotateSize -Value '2048000' -Confirm:$false -Force&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;"Please choose an Option to apply configurations:"&lt;BR /&gt;"1- Select Host"&lt;BR /&gt;"2- Apply on All ESXi Host"&lt;/P&gt;&lt;P&gt;$options= Read-Host "Enter your Number 1/2"&lt;BR /&gt;if ( 1 -eq $options )&lt;BR /&gt;{&lt;/P&gt;&lt;P&gt;$hostname= read-host "Please enter your hostname"&lt;BR /&gt;Write-Output "esxi-7.account-auto-unlock-time"&lt;/P&gt;&lt;P&gt;Get-VMHost $hostname | Get-AdvancedSetting Security.AccountUnlockTime | Set-AdvancedSetting -Value 900&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;Get-Cluster -Name $clusterName | Get-VM |&lt;BR /&gt;ForEach-Object -Process {&lt;BR /&gt;Get-VMHost $hostname | New-AdvancedSetting -Entity $_ -Name log.keepOld -Value '10' -Confirm:$false -Force&lt;BR /&gt;Get-VMHost $hostname | New-AdvancedSetting -Entity $_ -Name RemoteDisplay.maxConnections -Value '1' -Confirm:$false -Force&lt;BR /&gt;Get-VMHost $hostname | New-AdvancedSetting -Entity $_ -Name log.rotateSize -Value '2048000' -Confirm:$false -Force&lt;/P&gt;&lt;P&gt;}&lt;BR /&gt;if&lt;BR /&gt;( 2 -eq $options )&lt;BR /&gt;{&lt;BR /&gt;Write-Output "6- esxi-7.account-auto-unlock-time" | Green&lt;BR /&gt;Get-VMHost | Get-AdvancedSetting Security.AccountUnlockTime | Set-AdvancedSetting -Value 900&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;}&lt;BR /&gt;else {&lt;BR /&gt;Write-Output "Insert correct number" | Red&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can correct it ?&lt;/P&gt;</description>
      <pubDate>Sat, 10 Dec 2022 17:23:48 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Why-if-condition-does-not-work-correctly-in-my-script/m-p/2943216#M109490</guid>
      <dc:creator>baber</dc:creator>
      <dc:date>2022-12-10T17:23:48Z</dc:date>
    </item>
    <item>
      <title>Re: Why if condition does not work correctly in my script</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Why-if-condition-does-not-work-correctly-in-my-script/m-p/2943223#M109491</link>
      <description>&lt;P&gt;Not exactly sure what you are trying to do, but the block of code in the red box is always executed, independent of the value in $options.&lt;BR /&gt;&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="options.jpg" style="width: 999px;"&gt;&lt;img src="https://communities.vmware.com/t5/image/serverpage/image-id/98848iB17763ED6F369395/image-size/large?v=v2&amp;amp;px=999" role="button" title="options.jpg" alt="options.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Should that code only be executed when $options is equal to 1?&lt;BR /&gt;&lt;BR /&gt;Also not sure why do the following at the start, before even asking for option 1 or 2?&lt;BR /&gt;&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="OPTIONS2.jpg" style="width: 999px;"&gt;&lt;img src="https://communities.vmware.com/t5/image/serverpage/image-id/98850i36C09CEA42C0A06D/image-size/large?v=v2&amp;amp;px=999" role="button" title="OPTIONS2.jpg" alt="OPTIONS2.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 10 Dec 2022 17:47:04 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Why-if-condition-does-not-work-correctly-in-my-script/m-p/2943223#M109491</guid>
      <dc:creator>LucD</dc:creator>
      <dc:date>2022-12-10T17:47:04Z</dc:date>
    </item>
    <item>
      <title>Re: Why if condition does not work correctly in my script</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Why-if-condition-does-not-work-correctly-in-my-script/m-p/2943224#M109492</link>
      <description>&lt;P&gt;It would help if you can tell us what you are actually trying to do with that code.&lt;/P&gt;</description>
      <pubDate>Sat, 10 Dec 2022 17:48:24 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Why-if-condition-does-not-work-correctly-in-my-script/m-p/2943224#M109492</guid>
      <dc:creator>LucD</dc:creator>
      <dc:date>2022-12-10T17:48:24Z</dc:date>
    </item>
    <item>
      <title>Re: Why if condition does not work correctly in my script</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Why-if-condition-does-not-work-correctly-in-my-script/m-p/2943230#M109495</link>
      <description>&lt;P&gt;Actually I want to apply some configuration on hosts and some configurations on VMS&lt;/P&gt;&lt;P&gt;when we choose 1 and enter host name follow parameters should apply on specific host :&lt;/P&gt;&lt;P&gt;$clusterName= Read-Host "Please enter your cluster_name"&lt;BR /&gt;"There are follow Hosts in your cluster:"&lt;BR /&gt;Get-VMHost | Format-Table Name&lt;BR /&gt;"Please choose an Option to apply security configurations:"&lt;BR /&gt;"1- Select Host"&lt;BR /&gt;"2- Apply on All ESXi Host"&lt;/P&gt;&lt;P&gt;$options= Read-Host "Enter your Number 1/2"&lt;BR /&gt;if ( 1 -eq $options )&lt;BR /&gt;{&lt;/P&gt;&lt;P&gt;$hostname= read-host "Please enter your hostname"&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Write-Output "esxi-7.account-auto-unlock-time"&amp;nbsp;&lt;/P&gt;&lt;P&gt;Get-VMHost $hostname | Get-AdvancedSetting Security.AccountUnlockTime | Set-AdvancedSetting -Value 900&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;After apply above changes on esxi host need to apply some configuration parameters on VMs on that host so I used this&lt;/P&gt;&lt;P&gt;Get-Cluster -Name $clusterName | Get-VM |&lt;BR /&gt;ForEach-Object -Process {&lt;BR /&gt;Get-VMHost $hostname | New-AdvancedSetting -Entity $_ -Name log.keepOld -Value '10' -Confirm:$false -Force&lt;BR /&gt;Get-VMHost $hostname | New-AdvancedSetting -Entity $_ -Name RemoteDisplay.maxConnections -Value '1' -Confirm:$false -Force&lt;BR /&gt;Get-VMHost $hostname | New-AdvancedSetting -Entity $_ -Name log.rotateSize -Value '2048000' -Confirm:$false -Force&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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 :&lt;/P&gt;&lt;P&gt;if&lt;BR /&gt;( 2 -eq $options )&lt;BR /&gt;{&lt;BR /&gt;Write-Output "6- esxi-7.account-auto-unlock-time" | Green&lt;BR /&gt;Get-VMHost | Get-AdvancedSetting Security.AccountUnlockTime | Set-AdvancedSetting -Value 900&lt;/P&gt;&lt;P&gt;and apply follow changes on all vms&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Get-Cluster -Name $clusterName | Get-VM |&lt;BR /&gt;ForEach-Object -Process {&lt;BR /&gt;New-AdvancedSetting -Entity $_ -Name log.keepOld -Value '10' -Confirm:$false -Force&lt;BR /&gt;&amp;nbsp;New-AdvancedSetting -Entity $_ -Name RemoteDisplay.maxConnections -Value '1' -Confirm:$false -Force&lt;BR /&gt;&amp;nbsp;New-AdvancedSetting -Entity $_ -Name log.rotateSize -Value '2048000' -Confirm:$false -Force&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;so finally wrote this one :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;$clusterName= Read-Host "Please enter your cluster_name"&lt;BR /&gt;"There are follow Hosts in your cluster:"&lt;BR /&gt;Get-VMHost | Format-Table Name&lt;BR /&gt;"Please choose an Option to apply security configurations:"&lt;BR /&gt;"1- Select Host"&lt;BR /&gt;"2- Apply on All ESXi Host"&lt;/P&gt;&lt;P&gt;$options= Read-Host "Enter your Number 1/2"&lt;BR /&gt;if ( 1 -eq $options )&lt;BR /&gt;{&lt;/P&gt;&lt;P&gt;$hostname= read-host "Please enter your hostname"&lt;/P&gt;&lt;P&gt;Write-Output "esxi-7.account-auto-unlock-time"&amp;nbsp;&lt;/P&gt;&lt;P&gt;Get-VMHost $hostname | Get-AdvancedSetting Security.AccountUnlockTime | Set-AdvancedSetting -Value 900&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;Get-Cluster -Name $clusterName | Get-VM |&lt;BR /&gt;ForEach-Object -Process {&lt;BR /&gt;Get-VMHost $hostname | New-AdvancedSetting -Entity $_ -Name log.keepOld -Value '10' -Confirm:$false -Force&lt;BR /&gt;Get-VMHost $hostname | New-AdvancedSetting -Entity $_ -Name RemoteDisplay.maxConnections -Value '1' -Confirm:$false -Force&lt;BR /&gt;Get-VMHost $hostname | New-AdvancedSetting -Entity $_ -Name log.rotateSize -Value '2048000' -Confirm:$false -Force&lt;/P&gt;&lt;P&gt;}&lt;BR /&gt;if&lt;BR /&gt;( 2 -eq $options )&lt;BR /&gt;{&lt;BR /&gt;Write-Output "6- esxi-7.account-auto-unlock-time" | Green&lt;BR /&gt;Get-VMHost | Get-AdvancedSetting Security.AccountUnlockTime | Set-AdvancedSetting -Value 900&lt;/P&gt;&lt;P&gt;Get-Cluster -Name $clusterName | Get-VM |&lt;BR /&gt;ForEach-Object -Process {&lt;BR /&gt;New-AdvancedSetting -Entity $_ -Name log.keepOld -Value '10' -Confirm:$false -Force&lt;BR /&gt;&amp;nbsp;New-AdvancedSetting -Entity $_ -Name RemoteDisplay.maxConnections -Value '1' -Confirm:$false -Force&lt;BR /&gt;&amp;nbsp;New-AdvancedSetting -Entity $_ -Name log.rotateSize -Value '2048000' -Confirm:$false -Force&lt;/P&gt;&lt;P&gt;}&lt;BR /&gt;}&lt;BR /&gt;else {&lt;BR /&gt;Write-Output "Insert correct number"&amp;nbsp;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;What is the issue ?&lt;/P&gt;</description>
      <pubDate>Sat, 10 Dec 2022 19:27:17 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Why-if-condition-does-not-work-correctly-in-my-script/m-p/2943230#M109495</guid>
      <dc:creator>baber</dc:creator>
      <dc:date>2022-12-10T19:27:17Z</dc:date>
    </item>
    <item>
      <title>Re: Why if condition does not work correctly in my script</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Why-if-condition-does-not-work-correctly-in-my-script/m-p/2943232#M109496</link>
      <description>&lt;P&gt;Then you should place the following lines inside the block for $options -eq 1&lt;BR /&gt;Now it is always executed, whatever the value in $options&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;Get-Cluster -Name $clusterName | Get-VM |&lt;BR /&gt;ForEach-Object -Process {&lt;BR /&gt;Get-VMHost $hostname | New-AdvancedSetting -Entity $_ -Name log.keepOld -Value '10' -Confirm:$false -Force&lt;BR /&gt;Get-VMHost $hostname | New-AdvancedSetting -Entity $_ -Name RemoteDisplay.maxConnections -Value '1' -Confirm:$false -Force&lt;BR /&gt;Get-VMHost $hostname | New-AdvancedSetting -Entity $_ -Name log.rotateSize -Value '2048000' -Confirm:$false -Force&lt;BR /&gt;}&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 10 Dec 2022 19:59:49 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Why-if-condition-does-not-work-correctly-in-my-script/m-p/2943232#M109496</guid>
      <dc:creator>LucD</dc:creator>
      <dc:date>2022-12-10T19:59:49Z</dc:date>
    </item>
    <item>
      <title>Re: Why if condition does not work correctly in my script</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Why-if-condition-does-not-work-correctly-in-my-script/m-p/2943233#M109497</link>
      <description>&lt;P&gt;Thanks. But as I said when we select 2 not define specific hosts and it should apply on all hosts and VMS so this part should be change such as this when select 2 :&lt;/P&gt;&lt;P&gt;Get-Cluster -Name $clusterName | Get-VM |&lt;BR /&gt;ForEach-Object -Process {&lt;BR /&gt;New-AdvancedSetting -Entity $_ -Name log.keepOld -Value '10' -Confirm:$false -Force&lt;BR /&gt;New-AdvancedSetting -Entity $_ -Name RemoteDisplay.maxConnections -Value '1' -Confirm:$false -Force&lt;BR /&gt;New-AdvancedSetting -Entity $_ -Name log.rotateSize -Value '2048000' -Confirm:$false -Force&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also I have resided that script here as I got error Would you please check it in your env ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;"Please choose an Option to apply security configurations:"&lt;BR /&gt;"1- Select Host"&lt;BR /&gt;"2- Apply on All ESXi Host"&lt;/P&gt;&lt;P&gt;$options= Read-Host "Enter your Number 1/2"&lt;BR /&gt;if ( 1 -eq $options )&lt;BR /&gt;{&lt;/P&gt;&lt;P&gt;$hostname= read-host "Please enter your hostname"&lt;/P&gt;&lt;P&gt;Write-Output "esxi-7.account-auto-unlock-time"&amp;nbsp;&lt;/P&gt;&lt;P&gt;Get-VMHost $hostname | Get-AdvancedSetting Security.AccountUnlockTime | Set-AdvancedSetting -Value 900 -Confirm:$false -Force&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Get-Cluster -Name $clusterName | Get-VM |&lt;BR /&gt;ForEach-Object -Process {&lt;BR /&gt;Get-VMHost $hostname | New-AdvancedSetting -Entity $_ -Name log.keepOld -Value '10' -Confirm:$false -Force&lt;BR /&gt;Get-VMHost $hostname | New-AdvancedSetting -Entity $_ -Name RemoteDisplay.maxConnections -Value '1' -Confirm:$false -Force&lt;BR /&gt;Get-VMHost $hostname | New-AdvancedSetting -Entity $_ -Name log.rotateSize -Value '2048000' -Confirm:$false -Force&lt;/P&gt;&lt;P&gt;}}&lt;BR /&gt;if&lt;BR /&gt;( 2 -eq $options )&lt;BR /&gt;{&lt;BR /&gt;Write-Output "6- esxi-7.account-auto-unlock-time" | Green&lt;BR /&gt;Get-VMHost | Get-AdvancedSetting Security.AccountUnlockTime | Set-AdvancedSetting -Value 900&lt;/P&gt;&lt;P&gt;Get-Cluster -Name $clusterName | Get-VM |&lt;BR /&gt;ForEach-Object -Process {&lt;BR /&gt;New-AdvancedSetting -Entity $_ -Name log.keepOld -Value '10' -Confirm:$false -Force&lt;BR /&gt;New-AdvancedSetting -Entity $_ -Name RemoteDisplay.maxConnections -Value '1' -Confirm:$false -Force&lt;BR /&gt;New-AdvancedSetting -Entity $_ -Name log.rotateSize -Value '2048000' -Confirm:$false -Force&lt;/P&gt;&lt;P&gt;}}&lt;BR /&gt;else {&lt;BR /&gt;Write-Output "Insert correct number"&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 10 Dec 2022 20:37:34 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Why-if-condition-does-not-work-correctly-in-my-script/m-p/2943233#M109497</guid>
      <dc:creator>baber</dc:creator>
      <dc:date>2022-12-10T20:37:34Z</dc:date>
    </item>
    <item>
      <title>Re: Why if condition does not work correctly in my script</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Why-if-condition-does-not-work-correctly-in-my-script/m-p/2943236#M109498</link>
      <description>&lt;P&gt;That looks ok.&lt;BR /&gt;I would make a few small changes to optimise the code&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;"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"
}&lt;/LI-CODE&gt;</description>
      <pubDate>Sat, 10 Dec 2022 21:17:12 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Why-if-condition-does-not-work-correctly-in-my-script/m-p/2943236#M109498</guid>
      <dc:creator>LucD</dc:creator>
      <dc:date>2022-12-10T21:17:12Z</dc:date>
    </item>
    <item>
      <title>Re: Why if condition does not work correctly in my script</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Why-if-condition-does-not-work-correctly-in-my-script/m-p/2943248#M109499</link>
      <description>&lt;P&gt;1- When we choose option 2 what does this mean here :&lt;/P&gt;&lt;P&gt;$esx = Get-VMHost&lt;/P&gt;&lt;P&gt;because we want to apply on all hosts and VMs&lt;/P&gt;&lt;P&gt;$esx = Get-VMHost&lt;BR /&gt;Get-AdvancedSetting -Entity $esx -Name 'Security.AccountUnlockTime' | Set-AdvancedSetting -Value 900&lt;/P&gt;&lt;P&gt;Get-VM -Location $esx |&lt;BR /&gt;ForEach-Object -Process {&lt;BR /&gt;New-AdvancedSetting -Entity $_ -Name 'log.keepOld' -Value '10' -Confirm:$false -Force&lt;BR /&gt;New-AdvancedSetting -Entity $_ -Name 'RemoteDisplay.maxConnections' -Value '1' -Confirm:$false -Force&lt;BR /&gt;New-AdvancedSetting -Entity $_ -Name 'log.rotateSize' -Value '2048000' -Confirm:$false -Force&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;2- How can change this such as your sample when we want to apply on all hosts and specific host?&lt;/P&gt;&lt;P&gt;Get-VMHost $hostname | Get-VMHostService | where {$_.Key -eq 'TSM-SSH'} | Set-VMHostService -Policy Off&lt;BR /&gt;Get-VMHost $hostname | Get-VMHostService | where {$_.Key -eq 'TSM-SSH'} | Stop-VMHostService -Confirm:$false&lt;/P&gt;</description>
      <pubDate>Sun, 11 Dec 2022 06:58:33 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Why-if-condition-does-not-work-correctly-in-my-script/m-p/2943248#M109499</guid>
      <dc:creator>baber</dc:creator>
      <dc:date>2022-12-11T06:58:33Z</dc:date>
    </item>
    <item>
      <title>Re: Why if condition does not work correctly in my script</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Why-if-condition-does-not-work-correctly-in-my-script/m-p/2943255#M109500</link>
      <description>&lt;P&gt;1. The Get-VMHost cmdlet gets all ESXi nodes&lt;BR /&gt;&lt;BR /&gt;2. With a single value in $hostname you get 1 ESXi node.&lt;BR /&gt;With just Get-VMHost, no value for the -Name parameter, you get all ESXi nodes (see 1.)&lt;/P&gt;</description>
      <pubDate>Sun, 11 Dec 2022 10:23:12 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Why-if-condition-does-not-work-correctly-in-my-script/m-p/2943255#M109500</guid>
      <dc:creator>LucD</dc:creator>
      <dc:date>2022-12-11T10:23:12Z</dc:date>
    </item>
    <item>
      <title>Re: Why if condition does not work correctly in my script</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Why-if-condition-does-not-work-correctly-in-my-script/m-p/2943263#M109501</link>
      <description>&lt;P&gt;Would you please correct this one for when using specific host and also for all hosts in cluster&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Get-VMHost $hostname | Get-VMHostService | where {$_.Key -eq 'TSM-SSH'} | Set-VMHostService -Policy Off&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Get-VMHost $hostname | Get-VMHostService | where {$_.Key -eq 'TSM-SSH'} | Stop-VMHostService -Confirm:$false&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 11 Dec 2022 11:42:11 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Why-if-condition-does-not-work-correctly-in-my-script/m-p/2943263#M109501</guid>
      <dc:creator>baber</dc:creator>
      <dc:date>2022-12-11T11:42:11Z</dc:date>
    </item>
    <item>
      <title>Re: Why if condition does not work correctly in my script</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Why-if-condition-does-not-work-correctly-in-my-script/m-p/2943264#M109502</link>
      <description>&lt;P&gt;In the last code, I posted those 2 options are already there&lt;BR /&gt;&lt;BR /&gt;Option 1&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;$esx = Get-VMHost -Name $hostname&lt;/LI-CODE&gt;
&lt;P&gt;Option 2&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;$esx = Get-VMHost&lt;/LI-CODE&gt;
&lt;P&gt;Not sure what you don't understand.&lt;BR /&gt;With option1 there is 1 ESXi node in the $esx variable.&lt;BR /&gt;With option 2 all the ESXi nodes are in the $esx variable&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 11 Dec 2022 12:00:38 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Why-if-condition-does-not-work-correctly-in-my-script/m-p/2943264#M109502</guid>
      <dc:creator>LucD</dc:creator>
      <dc:date>2022-12-11T12:00:38Z</dc:date>
    </item>
    <item>
      <title>Re: Why if condition does not work correctly in my script</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Why-if-condition-does-not-work-correctly-in-my-script/m-p/2943289#M109504</link>
      <description>&lt;P&gt;This is my question :&lt;/P&gt;&lt;P&gt;1- when I run "&amp;nbsp;Get-VMHostService | where {$_.Key -eq 'snmpd'} | Set-VMHostService -Policy Off" this will apply on all hosts how can define to apply on specific host ?&lt;/P&gt;&lt;P&gt;2- When I want to run below script on specific host is this correct ?&lt;BR /&gt;Get-VMHost $esx | Get-VMHostService | where {$_.Key -eq 'snmpd'} | Stop-VMHostService -Confirm:$false&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;3- Is this script correct if I want to run it on specific host ? "Get-VMHost $esx | Get-VMHostService | where {$_.Key -eq 'snmpd'} | Stop-VMHostService -Confirm:$false"&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;4- Is this script correct if I want to run it on all hosts ?&lt;/P&gt;&lt;P&gt;Get-VMHost $esx | Get-VMHostService | where {$_.Key -eq 'snmpd'} | Stop-VMHostService -Confirm:$false&lt;/P&gt;</description>
      <pubDate>Sun, 11 Dec 2022 15:30:51 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Why-if-condition-does-not-work-correctly-in-my-script/m-p/2943289#M109504</guid>
      <dc:creator>baber</dc:creator>
      <dc:date>2022-12-11T15:30:51Z</dc:date>
    </item>
    <item>
      <title>Re: Why if condition does not work correctly in my script</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Why-if-condition-does-not-work-correctly-in-my-script/m-p/2943295#M109505</link>
      <description>&lt;P&gt;Did you even try the script I provided earlier?&lt;BR /&gt;You can't just lift out a single line without considering the context.&lt;BR /&gt;The trick is that the $esx variable is populated with 1 ESXi node (option 1) or all ESXi nodes (option 2).&lt;/P&gt;</description>
      <pubDate>Sun, 11 Dec 2022 17:04:33 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Why-if-condition-does-not-work-correctly-in-my-script/m-p/2943295#M109505</guid>
      <dc:creator>LucD</dc:creator>
      <dc:date>2022-12-11T17:04:33Z</dc:date>
    </item>
    <item>
      <title>Re: Why if condition does not work correctly in my script</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Why-if-condition-does-not-work-correctly-in-my-script/m-p/2943302#M109506</link>
      <description>&lt;P&gt;I will try and inform&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 11 Dec 2022 20:13:34 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Why-if-condition-does-not-work-correctly-in-my-script/m-p/2943302#M109506</guid>
      <dc:creator>baber</dc:creator>
      <dc:date>2022-12-11T20:13:34Z</dc:date>
    </item>
    <item>
      <title>Re: Why if condition does not work correctly in my script</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Why-if-condition-does-not-work-correctly-in-my-script/m-p/2943309#M109507</link>
      <description>&lt;P&gt;What is the following line supposed to do:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;Write-Output "6- esxi-7.account-auto-unlock-time" | Green&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is this supposed to do something like:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;Write-Host -ForegroundColor Green "6- esxi-7.account-auto-unlock-time" &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Or is a different purpose intended?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 11 Dec 2022 22:10:40 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Why-if-condition-does-not-work-correctly-in-my-script/m-p/2943309#M109507</guid>
      <dc:creator>StephenMoll</dc:creator>
      <dc:date>2022-12-11T22:10:40Z</dc:date>
    </item>
  </channel>
</rss>

