2 Replies Latest reply on Nov 15, 2017 4:40 AM by jvm2016

    script-structure_powercli

    jvm2016 Enthusiast

      Hello Luc,

       

      By mistake i deleted previous post for this query.

       

      however below is your response.but i dont see any changes to what i posted .

      also we are using RemoveAllSnapshots($true) so that means it shoud remove all snapshots .

      my specific question is once snapshotdeletion started will script not pick the second task of traffic remediation.

       

       

       

       

      $conn = $global:defaultviserver

       

      if ($conn -cne $null) {

          write-output "there is already session to" $conn.name

          disconnect-viserver "*" -force -confirm:$true

       

      }

       

      $vc = read-host "provide the vcenter name"

      connect-viserver -server $vc -username "administrator@vsphere.local" -password ""

      $cluster = read-host "provide the cluster name"

       

       

      foreach ($vm_snapshot in (Get-View -ViewType VirtualMachine -Property Name, snapshot -SearchRoot $cluster.MoRef|? {$_.snapshot -cne $null})) {

          $vm_snapshot.name

          if ($vm_snapshot -eq $null) {

              write-output "nothing to remediate for snapshot"

          }

          else {

              $rem = read-host "do yu want to remediate snapshot"

          }

          if ($rem -eq "yes") {

       

              write-output "deleting snapshot please wait"

              $vm_snapshot.RemoveAllSnapshots($true)

          }

      }

       

      #traffic separation

       

      $vmhosts = get-vmhost -location $cluster

       

      foreach ($hos in $vmhosts) {

          $vmkernel = Get-VMHostNetworkAdapter -VMKernel -VMHost $hos|Where-Object {$_.managementtrafficenabled -eq $true -and $_.vmotionenabled -eq $true}

          $vmkernel|select @{N = 'esxi name'; E = {$hos.name}}, @{N = 'vmkernel port'; E = {$_.name}}

          if ($vmkernel -eq $null) {

              Write-Output "nothing to remediate for traffic separation"

          }

          else {

              $rem1 = read-host " do yu want to remediate traffic separation"

          }

          if ($rem1 -eq "yes") {

              write-output "remediating traffic separation"

       

              $vmkernel|Set-VMHostNetworkAdapter -VMotionEnabled $false -confirm:$false

       

       

          }

       

       

      }

       

      #sshdisable

       

      foreach ($esxi in $vmhosts) {

          $sshpolicy = Get-VMHostService -VMHost $esxi | Where {$_.Key -eq "TSM-SSH"}

       

       

          if ($sshpolicy.running -eq $false) {

              write-output "nothing to remediate for ssh service in $esxi"

       

          }

          else {

              $rem2 = read-host " do yu want to remediate ssh"

       

          }

          if ($rem2 -eq "yes") {

              write-output "remediating ssh"

       

              Stop-VMHostService $sshpolicy -Confirm:$true

       

          }

      }