Help with data in a varible

Welcome Forums General PowerShell Q&A Help with data in a varible

Viewing 1 reply thread
  • Author
    Posts
    • #207768
      Participant
      Topics: 1
      Replies: 0
      Points: -8
      Rank: Member

      up front didn’t know how to word the Topic

      I have some code to pull settings off of some esxi host

      I borrowed this from

      http://www.stigviewer.com/stig/vmware_vsphere_vcenter_server_version_6/2015-12-09/finding/V-63971

      Get-VDPortgroup | Get-View |
      Select Name,
      @{N=”VlanOverrideAllowed”;E={$_.Config.Policy.VlanOverrideAllowed}},
      @{N=”UplinkTeamingOverrideAllowed”;E={$_.Config.Policy.UplinkTeamingOverrideAllowed}},
      @{N=”SecurityPolicyOverrideAllowed”;E={$_.Config.Policy.SecurityPolicyOverrideAllowed}},
      @{N=”IpfixOverrideAllowed”;E={$_.Config.Policy.IpfixOverrideAllowed}},
      @{N=”BlockOverrideAllowed”;E={$_.Config.Policy.BlockOverrideAllowed}},
      @{N=”ShapingOverrideAllowed”;E={$_.Config.Policy.ShapingOverrideAllowed}},
      @{N=”VendorConfigOverrideAllowed”;E={$_.Config.Policy.VendorConfigOverrideAllowed}},
      @{N=”TrafficFilterOverrideAllowed”;E={$_.Config.Policy.TrafficFilterOverrideAllowed}}

      now I can put it into a variable and the output looks like this

      Name : VLAN_02
      VlanOverrideAllowed : False
      UplinkTeamingOverrideAllowed : False
      SecurityPolicyOverrideAllowed : False
      IpfixOverrideAllowed : False
      BlockOverrideAllowed : False
      ShapingOverrideAllowed : False
      VendorConfigOverrideAllowed : False
      TrafficFilterOverrideAllowed : False

      Name : vMotion
      VlanOverrideAllowed : False
      UplinkTeamingOverrideAllowed : False
      SecurityPolicyOverrideAllowed : False
      IpfixOverrideAllowed : False
      BlockOverrideAllowed : False
      ShapingOverrideAllowed : False
      VendorConfigOverrideAllowed : False
      TrafficFilterOverrideAllowed : False

      what I want to do is like a If {} ELse {} statement  or the like

      so Like

      If ( all settings are False) { All Setting are False } Else { if any settings are True , output True statements }

      so if say each one had a true setting have the output

      Name : vMotion

      TrafficFilterOverrideAllowed : True

      Name : VLAN_02
      VlanOverrideAllowed : True

      this is part of an array , been banging my head how to do this , and its hard as I am not sure how to google it

      here is the script so far , its a work in progress

      Set-PowerCLIConfiguration -InvalidCertificateAction Prompt -Scope Session -Confirm:$false |Out-Null
      #$vESXi = Read-Host "Enter ESXi\vCenter name or IP"
      $vESXi =""
      
      
      Connect-VIServer $vESXi -user -password
      
      #$ErrorActionPreference = 'SilentlyContinue'
      $array = @()
      foreach($esx in ((get-vmhost).name)){
      $run = "" | Select Host,GN115,GN125,GN1454,GN1411,GN152,GN218,GN219
      $run.host = $esx
      $run.GN115 = (Get-AdvancedSetting -entity $esx -name Security.PasswordQualityControl).Value
      $125 = (Get-AdvancedSetting -entity $esx -name Syslog.global.logHost).Value
      if ($125) {$run.GN125 = $125} Else {$run.GN125 = "Not Set"}
      $1454 = Get-VDPortgroup | Get-View | 
      Select Name,
      @{N="VlanOverrideAllowed";E={$_.Config.Policy.VlanOverrideAllowed}},
      @{N="UplinkTeamingOverrideAllowed";E={$_.Config.Policy.UplinkTeamingOverrideAllowed}},
      @{N="SecurityPolicyOverrideAllowed";E={$_.Config.Policy.SecurityPolicyOverrideAllowed}},
      @{N="IpfixOverrideAllowed";E={$_.Config.Policy.IpfixOverrideAllowed}},
      @{N="BlockOverrideAllowed";E={$_.Config.Policy.BlockOverrideAllowed}},
      @{N="ShapingOverrideAllowed";E={$_.Config.Policy.ShapingOverrideAllowed}},
      @{N="VendorConfigOverrideAllowed";E={$_.Config.Policy.VendorConfigOverrideAllowed}},
      @{N="TrafficFilterOverrideAllowed";E={$_.Config.Policy.TrafficFilterOverrideAllowed}}
      If ($1454 -contains $true){}
      Else {$run.GN1454 = "All Port-level configuration overrides are disabled"}
      
      
      $1411 = (Get-AdvancedSetting -entity $esx -name Net.DVFilterBindIpAddress).Value
      if ($1411){$run.GN1411 = $1411} Else {$run.GN1411 = "Blank"}
      (Get-VMHostFirewallException -vmhost $esx |Select Name,Enabled | Where { $_.Enabled -eq $True})| % {$run.GN152 += $_.Name + " is " + ($_.Enabled |foreach-object { $_ -Replace "True","Enabled" -Replace "False","Disabled"})+ " | "}
      $218 = (Get-AdvancedSetting -Entity $esx -Name "Config.Defaults.security.host.ruissl").Value
      if ($218){$run.GN218 = "Checked"} Else {$run.GN218 = "Not Checked"}
      $run.GN219 += (Get-AdvancedSetting -Entity $esx -Name "UserVars.ESXiVPsDisabledProtocols").Value + " ARE Disabled"
      
      
      $array += $run
      [System.GC]::Collect() 
      }
      $array | Export-CSV ".\$vESXi Gap Check.csv" -NoTypeInformation
      Disconnect-VIServer $vesxi -Confirm:$false |Out-Null

       

       

       

    • #208143
      Participant
      Topics: 4
      Replies: 82
      Points: 251
      Helping Hand
      Rank: Contributor

      This is a little ugly but what I came up with is to iterate over your settings and then each property in those settings.

      foreach ($setting in $1454) {
         $check = $false
         foreach ($prop in $setting | 
            Select-Object -Property * -ExcludeProperty name |
               Get-Member -MemberType NoteProperty |
                  Select-Object -ExpandProperty name ) {
            if ($setting.$prop) {
               $setting | 
                  select-object name, $prop | 
                     Format-List
               $check = $true
            } #if property is true
         } #foreach prop
         if (!$check) {
            $setting.name
            "All settings are false"
         } #if all are false
      } #foreach setting

       

Viewing 1 reply thread
  • You must be logged in to reply to this topic.