본문 바로가기

VMware Cloud Foundation/NSX-T

Powershell을 이용한 NSX-T 정보 수집

NSX-T UI를 사용하다 보면 간혹 여러 정보를 한번에 모두 보고 싶은 마음이 간절해 지는 경우가 있습니다.

각각의 메뉴와 정보는 연관성을 가지고 이동을 해야 하다 보니, 많은 서비스가 올라가고, 많은 설정이 들어가면서 직관적으로 확인이 어려운 경우가 발생하기도 합니다.

 

내가 원하는 정보만을 수집하여, 정리해서 보고 싶은 경우 우리는 API 혹은 SDK 도구를 사용하게 될 것입니다.

 

Windows Powershell 은 강력한 script 도구로서 사용자가 직관적으로 변수를 핸들링할 수 있도록 제공하고 있기에 많은 운영자들이 powershell script를 이용하게 되곤 합니다. 특히 많은 벤더사에서 powershell 을 지원하는 경우가 점차 늘어나고 있습니다.

 

VMware 또한 오래 전부터 powershell을 통한 도구로 PowerCLI를 지원하고 있으며, vsphere, automation, vsan, nsx-t등 주요 제품들에 대해서 powershell을 통한 제어를 제공하고 있습니다.

 

NSX-T의 경우 API에 호출되는 인스턴스 항목을 powershell을 통해서 호출하여 사용중이며, 처음 접근 시 사용하는데 익숙치 않기에 어려움이 있으나, 구조적인 이해를 하고서 몇 번 시도를 하고 나면, 매우 쉽게 활용하여 정보 수집을 하거나, 혹은 내가 자주 반복하는 설정으로 예를 들어 방화벽 rule을 추가하거나, 삭제하는 작업,  Logical segment를 만들거나, Load Balancer를 만드는 작업등을 통한 automation으로서 역할을 수행할 수 있습니다.

 

우선 vmware powercli 도구를 vmware 홈페이지를 통해서 다운로드 하거나, 혹은 windows powershell prompt 상에서 즉시 설치를 할 수 있습니다.

 

Download Powercli 12.7: https://developer.vmware.com/web/tool/12.7.0/vmware-powercli

 

VMware PowerCLI - VMware {code}

Overview VMware PowerCLI is a command-line and scripting tool built on Windows PowerShell, and provides more than 800 cmdlets for managing and automating VMware vSphere, VMware Cloud Director, vRealize Operations Manager, vSAN, VMware NSX-T Data Center, VM

developer.vmware.com

 

Install guide: https://docs.vmware.com/en/VMware-vSphere/7.0/com.vmware.esxi.install.doc/GUID-F02D0C2D-B226-4908-9E5C-2E783D41FE2D.html

 

Install PowerCLI

Before you can manage vSphere Auto Deploy with rules that you create with PowerCLI cmdlets, you must install PowerCLI.

docs.vmware.com

 

Powercli 도구 설치가 완료되었다면, Windows powershell을 실행하고서 NSX-T와 관련된 기능을 수행할 수 있습니다.

 

우선 PowerCLI 도구에서 어떤식의 수행이 가능한지는 아래 blog를 통해서 참고하실 수 있습니다.

https://blogs.vmware.com/networkvirtualization/2022/05/navigating-nsx-module-in-powercli-12-6.html/

 

Navigating NSX Module in PowerCLI 12.6

This blog explains the use of PowerCLI NSX module. See different ways new cmdlets can be found and view documentation on the cmdlets.

blogs.vmware.com

 

vmware code의 개발자를 위한 페이지에서 제공되고 있는 cmdlet을 확인할 수 있습니다.

https://developer.vmware.com/docs/powercli/latest/products/vmwarensx-tdatacenter/

 

VMwareNSX-TDataCenter Module | VMware PowerCLI Reference

Provides cmdlets for managing NSX-T servers.

developer.vmware.com

 

** SAMPLE **

cmdlet에서 NSX-T Service 항목을 사용하여 아래와 같이 방화벽 rule 정보를 획득하거나, Load Balancer 정보를 획득하여, HTML 파일로 생성해서 아래와 같은 페이지 출력을 볼 수 있습니다.

 

1. windows powershell 명령줄에서 NSX-T에 로그인을 실행

connect-nsxtserver -server {host_ip or domain} -user admin

 

2. 명령줄에서 get-nsxtservice를 수행

get-nsxtservice | more

- 이 명령어를 통해서 nsxtservice에 포함되어 있는 호출 가능한 기능 항목들을 확인할 수 있습니다.

 

아래와 같이 하나의 명령줄을 실행해 봅니다.

$svcfwsecs = get-nsxtservice -name com.vmware.nsx.firewall.sections

- svcfwsecs 변수에 firewall의 sections 항목에 대한 정보를 삽입하였습니다.

 

아래와 같이 현재 해당 기능 항목에 대한 help 옵션을 통해서 도움말을 확인할 수 있습니다.

$svcfwsecs.help

 

이러한 도움말을 통해서 우리가 어떤 기능에서 어떤 옵션을 수행하고, 요구되는 필수 값은 어떤 것인지를 확인하고 원하는 작업을 수행할 수 있습니다.

 

list라는 옵션에는 별도의 필수 요구 값이 없는 것을 도움말에서 확인할 수 있으며, list를 주고서 실행해 봤습니다.

$svcfwsecs.list

 

위와 같이 list를 수행할 때 도움 정보가 표시가 되었습니다. list에는 string에 대한 필수 값은 없으며(? 표시는 필수 값이 아니라는 걸 의미)  그 다음 명령줄로 아래와 같이 값이 없이 results 값을 받도록 수행했습니다.

$svcfwsecs.list().results

위와 같이 각 section에 대한 정보 값을 모두 확인할 수 있습니다. 여기서 다른 기능들과 연관성이 있는 ID와 같은 정보 값을 이용하여 다른 기능에서는 옵션 값을 주고서 get({id}) 와 같이 수행할 수 있을 것입니다.

 

 

*** 이미지 아래 있는 코드로 생성된 표시 화면 **

방화벽 rule
LB VS, profile 정보

 

Example-1 Firewall rule 정보 수집

####################################################################
#
# Created by Insung Choi
#
# Login: connect-nsxtserver -server {host_ip} -user admin
#
####################################################################

### Firewall Fuctions ###
#$svcfwexcludelist = get-nsxtservice -name com.vmware.nsx.firewall.excludelist
#$svcfwprofiles = get-nsxtservice -name com.vmware.nsx.firewall.profiles
#$svcfwrules =  get-nsxtservice -name com.vmware.nsx.firewall.rules
#$svcfwrulestat = get-nsxtservice -name com.vmware.nsx.firewall.rules.state
$svcfwsecs = get-nsxtservice -name com.vmware.nsx.firewall.sections
$svcfwsecsrules = get-nsxtservice -name com.vmware.nsx.firewall.sections.rules
#$svcfwsecrulestats = get-nsxtservice -name com.vmware.nsx.firewall.sections.rules.stats
#$svcfwsecstate = get-nsxtservice -name com.vmware.nsx.firewall.sections.state
#$svcfwsecsumm = get-nsxtservice -name com.vmware.nsx.firewall.sections.summary
#$svcfwstats = get-nsxtservice -name com.vmware.nsx.firewall.stats
#$svcfwstatus = get-nsxtservice -name com.vmware.nsx.firewall.status

### get section list
# $svcfwsecs.list().results

### required sections id
# $svcfwsecsrules.list('ffffffff-8a04-4924-a5b4-54d30e81befe').results
# $currentsecrules = $svcfwsecsrules.list('ffffffff-8a04-4924-a5b4-54d30e81befe').results

### required rule id
# $svcfwrules.get(‘2’)

### get all section info
$allsecids = $svcfwsecs.list().results | select category,display_name,id,section_type,stateful,create_time,create_user,last_modified_time,last_modified_user,revision

## setup a empty array
$allfwinfo=@()

ForEach ($secid in $allsecids){
	#$currentsecrules = $svcfwsecsrules.list($secid.id).results
	$currentsecrules = $svcfwsecsrules.list($secid.id).results	
	ForEach ($fw_rule in $currentsecrules){
			$fwinfo = "" | select section_category,section_name,rule_name,rule_id,rule_src_name,rule_dst_name,rule_action,rule_direction,rule_disabled,revision
			$fwinfo.section_category = $secid.category
			$fwinfo.section_name = $secid.display_name
			$fwinfo.rule_name = $fw_rule.display_name
			$fwinfo.rule_id = $fw_rule.id
			$fwinfo.rule_src_name = [string]$fw_rule.sources.target_display_name
			$fwinfo.rule_dst_name = [string]$fw_rule.destinations.target_display_name
			$fwinfo.rule_action = [string]$fw_rule.action
			$fwinfo.rule_direction = [string]$fw_rule.direction
			$fwinfo.rule_disabled = [string]$fw_rule.disabled
			$fwinfo.revision = [string]$fw_rule.revision
			## $fwinfo | ft -autosize
			$allfwinfo+=$fwinfo
	}
}
		
#display all info
$allfwinfo | ft -autosize

#export to csv
$allfwinfo | Export-Csv  all_fw_info.csv

#export to HTML
$css  = "table{ Margin: 0px 0px 0px 4px; Border: 1px solid rgb(200, 200, 200); Font-Family: Tahoma; Font-Size: 8pt; Background-Color: rgb(252, 252, 252); }"
$css += "tr:hover td { Background-Color: #6495ED; Color: rgb(255, 255, 255);}"
$css += "tr:nth-child(even) { Background-Color: rgb(242, 242, 242); }"
Set-Content -Value $css -Path all_LB_info.css
$allfwinfo | ConvertTo-Html -CSSUri "all_fw_info.css" | Set-Content "all_fw_info.html"

 

Example-2: LB VS, Pool, LB App profile 정보

$svclbappsp = get-nsxtservice -name com.vmware.nsx.loadbalancer.application_profiles
$svclbsslp = get-nsxtservice -name com.vmware.nsx.loadbalancer.client_ssl_profiles
$svclbmonitor = get-nsxtservice -name com.vmware.nsx.loadbalancer.monitors
$svclbusgsumm = get-nsxtservice -name com.vmware.nsx.loadbalancer.node_usage_summary
$svclblbpersis = get-nsxtservice -name com.vmware.nsx.loadbalancer.persistence_profiles
$svclbpools = get-nsxtservice -name com.vmware.nsx.loadbalancer.pools
$svclbrules = get-nsxtservice -name com.vmware.nsx.loadbalancer.rules
$svclbsslp = get-nsxtservice -name com.vmware.nsx.loadbalancer.server_ssl_profiles
$svclbsvcs = get-nsxtservice -name com.vmware.nsx.loadbalancer.services
$svclbsvcdebugs = get-nsxtservice -name com.vmware.nsx.loadbalancer.services.debug_info
$svclbsvcplsts = get-nsxtservice -name com.vmware.nsx.loadbalancer.services.pools.statistics
$svclbsvcplstatus = get-nsxtservice -name com.vmware.nsx.loadbalancer.services.pools.status
$svclbsvcstatistics = get-nsxtservice -name com.vmware.nsx.loadbalancer.services.statistics
$svclbsvcstatus = get-nsxtservice -name com.vmware.nsx.loadbalancer.services.status
$svclbsvcusages = get-nsxtservice -name com.vmware.nsx.loadbalancer.services.usage
$svclbsvcvists = get-nsxtservice -name com.vmware.nsx.loadbalancer.services.virtual_servers.statistics
$svclbsvcvistatus = get-nsxtservice -name com.vmware.nsx.loadbalancer.services.virtual_servers.status
$svclbsslcips = get-nsxtservice -name com.vmware.nsx.loadbalancer.ssl.ciphers_and_protocols
$svclbusages = get-nsxtservice -name com.vmware.nsx.loadbalancer.usage_per_node
$svclbvs = get-nsxtservice -name com.vmware.nsx.loadbalancer.virtual_servers

$oj_svclbsvcs = $svclbsvcs.list().results | select virtual_server_ids, size, enabled, attachment, display_name

## setup a empty array
$allhtml=@()
$alllbinfo=@()
ForEach ($lbsvc in $oj_svclbsvcs){
	Foreach ($lbsvcnum in $lbsvc.virtual_server_ids) {
		$lbinfo = '' | select LB_Name,VS,VIP,Status,Protocol,App_Profile,Pool_Name		
		$lbvs = $svclbvs.list().results | where-object {$_.id -eq $lbsvcnum}
		$lbinfo.LB_Name = $lbsvc.display_name
		$lbinfo.VS = $lbvs.display_name
		$lbinfo.VIP = $lbvs.ip_address
		$lbinfo.Status = $lbvs.enabled
		$lbinfo.Protocol = $lbvs.ip_protocol
		$lbapp_name = $svclbappsp.get($lbvs.application_profile_id)
		$lbinfo.App_Profile = $lbapp_name.display_name
		$lbpool_name = $svclbpools.get($lbvs.pool_id)
		$lbinfo.Pool_Name = $lbpool_name.display_name
		#ForEach ($poolmembers in $lbpool_name.members) {
			#$poolinfo.member_name = $poolmembers.display_name
			#$poolinfo.member_ip = $poolmembers.ip_address
			#$poolinfo.member_weight = $poolmembers.weight
			#$poolinfo.member_backup = $poolmembers.backup_member
		#}
		$alllbinfo+=$lbinfo
	}
}

$lbinfo_html = @()
	$lbinfo_html = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>HTML TABLE</title><link rel="stylesheet" type="text/css" href="all_css_info.css" /></head><body>'
	$lbinfo_html += '<table><colgroup><col/><col/><col/><col/><col/><col/><col/></colgroup><tr><th>LB_Name</th><th>VS</th><th>VIP</th><th>Status</th><th>Protocol</th><th>App_Profile</th><th>Pool_Name</th></tr><H3>NSX-T LB Virtual Service Informantion</H3>'
ForEach ($one_lbinfo in $alllbinfo) {
	$lbinfo_html += '<tr><td>'+$one_lbinfo.LB_Name+'</td>'
	$lbinfo_html += '<td>'+$one_lbinfo.VS+'</td>'
	$lbinfo_html += '<td>'+$one_lbinfo.VIP+'</td>'
	$lbinfo_html += '<td>'+$one_lbinfo.Status+'</td>'
	$lbinfo_html += '<td>'+$one_lbinfo.Protocol+'</td>'
	$lbinfo_html += '<td>'+$one_lbinfo.App_Profile+'</td>'
	$lbinfo_html += '<td>'+$one_lbinfo.Pool_Name+'</td></tr>'	
}
	$lbinfo_html += '</table><br><br><br><h3>NSX-T Pool members</h3><table><colgroup><col/><col/><col/><col/><col/><col/></colgroup><tr><th>Pool_Name</th><th>Algorithm</th><th>SNAT</th><th>Status</th><th>Members</th><th>Member IP Address</th></tr>'

$allpoolinfo=@()
$lbpools = $svclbpools.list().results
ForEach ($lbpool in $lbpools) {
	$poolinfo = '' | select name,algorithm,snat,tcpmultiplex,member_name,member_ip
	$poolinfo.name = $lbpool.display_name
	$poolinfo.algorithm = $lbpool.algorithm
	$poolinfo.snat = $lbpool.snat_translation.type
	$poolinfo.tcpmultiplex = $lbpool.tcp_multiplexing_enabled
	$poolinfo.member_name = $lbpool.members.display_name
	$poolinfo.member_ip = $lbpool.members.ip_address
	$allpoolinfo+=$poolinfo
}

ForEach ($object in $allpoolinfo) {
	$lbinfo_html += '<tr><td>'+$object.name+'</td>'
	$lbinfo_html += '<td>'+$object.algorithm+'</td>'
	$lbinfo_html += '<td>'+$object.snat+'</td>'
	$lbinfo_html += '<td>'+$object.tcpmultiplex+'</td>'
	$lbinfo_html += '<td>'+$object.member_name+'</td>'
	$lbinfo_html += '<td>'+$object.member_ip+'</td></tr>'
}

$lbinfo_html += '</table><br><br><br><h3>NSX-T L4 Profiles</h3><table><colgroup><col/><col/><col/><col/><col/><col/></colgroup><tr><th>Profile type</th><th>Profile name</th><th>Idle timeout</th><th>Close timeout</th><th>HA flow mirroring</th><th>Revision</th></tr>'

$lbL4Profiles = $svclbappsp.list().results | where-object {$_.resource_type -eq 'LBFastTcpProfile'}

$allL4profile = @()
ForEach ($object in $lbL4Profiles) {
	$L4profile = '' | select Profile_type,Name,Idle_timeout,Close_timeout,HA_flow_mirror,Revision
	$L4profile.Profile_type = $object.resource_type
	$L4profile.Name = $object.display_name
	$L4profile.Idle_timeout = $object.idle_timeout
	$L4profile.Close_timeout = $object.close_timeout
	$L4profile.HA_flow_mirror = $object.ha_flow_mirroring_enabled
	$L4profile.Revision = $object.revision
	$allL4profile += $L4profile
}

ForEach ($object in $allL4profile) {
	$lbinfo_html += '<tr><td>'+$object.Profile_type+'</td>'
	$lbinfo_html += '<td>'+$object.Name+'</td>'
	$lbinfo_html += '<td>'+$object.Idle_timeout+'</td>'
	$lbinfo_html += '<td>'+$object.Close_timeout+'</td>'
	$lbinfo_html += '<td>'+$object.HA_flow_mirror+'</td>'
	$lbinfo_html += '<td>'+$object.Revision+'</td></tr>'
}

$lbinfo_html += '</table><br><br><br><h3>NSX-T L7 Profiles</h3><table><colgroup><col/><col/><col/><col/><col/><col/><col/><col/><col/><col/><col/><col/><col/><col/></colgroup><tr><th>resource_type</th><th>Display_name</th><th>Idle_timeout</th><th>request_header_size</th><th>response_timeout</th><th>response_header_size</th><th>buffering</th><th>server_keep_alive</th><th>x_forwarded_for</th><th>http_redirect_to_https</th><th>ntlm</th><tt>http_redirect_to</th><th>request_body_size</th><th>revision</th></tr>'

$lbL7Profiles = $svclbappsp.list().results | where-object {$_.resource_type -eq 'LbHttpProfile'}

$allL7profile = @()
ForEach ($object in $lbL7Profiles) {
	$L7profile = "" | select Resource_type,Display_name,Idle_timeout,Request_header_size,Response_timeout,Response_header_size,Buffering,Server_keep_alive,X_forwarded_for,Http_redirect_to_https,Ntlm,Http_redirect_to,Request_body_size,revision
	$L7profile.resource_type = $object.resource_type
	$L7profile.display_name = $object.display_name
	$L7profile.idle_timeout = $object.idle_timeout
	$L7profile.request_header_size = $object.request_header_size
	$L7profile.response_timeout = $object.response_timeout
	$L7profile.response_header_size = $object.response_header_size
	$L7profile.buffering = $object.buffering
	$L7profile.server_keep_alive = $object.server_keep_alive
	$L7profile.x_forwarded_for = $object.x_forwarded_for
	$L7profile.http_redirect_to_https = $object.http_redirect_to_https
	$L7profile.ntlm = $object.ntlm
	$L7profile.http_redirect_to = $object.http_redirect_to
	$L7profile.request_body_size = $object.request_body_size
	$L7profile.revision = $object.revision
	$allL7profile += $L7profile
}

ForEach ($object in $allL7profile) {
	$lbinfo_html += '<tr><td>'+$object.resource_type+'</td>'
	$lbinfo_html += '<td>'+$object.display_name+'</td>'
	$lbinfo_html += '<td>'+$object.Idle_timeout+'</td>'
	$lbinfo_html += '<td>'+$object.request_header_size+'</td>'
	$lbinfo_html += '<td>'+$object.response_timeout+'</td>'
	$lbinfo_html += '<td>'+$object.response_header_size+'</td>'
	$lbinfo_html += '<td>'+$object.buffering+'</td>'
	$lbinfo_html += '<td>'+$object.server_keep_alive+'</td>'
	$lbinfo_html += '<td>'+$object.x_forwarded_for+'</td>'
	$lbinfo_html += '<td>'+$object.http_redirect_to_https+'</td>'
	$lbinfo_html += '<td>'+$object.ntlm+'</td>'
	$lbinfo_html += '<td>'+$object.http_redirect_to+'</td>'
	$lbinfo_html += '<td>'+$object.request_body_size+'</td>'
	$lbinfo_html += '<td>'+$object.revision+'</td></tr>'
}

	$lbinfo_html += '</table></body></html>'

$alllbinfo | ft -autosize
$allpoolinfo | ft -autosize
$allL4profile | ft -autosize
$allL7profile | ft -autosize

#export to HTML
$css  = "table{ Margin: 0px 0px 0px 4px; Border: 1px solid rgb(200, 200, 200); Font-Family: Tahoma; Font-Size: 10pt; Background-Color: rgb(252, 252, 252); }"
$css += "tr:hover td { Background-Color: #6495ED; Color: rgb(255, 255, 255);}"
$css += "tr:nth-child(even) { Background-Color: rgb(242, 242, 242); }"
Set-Content -Value $css -Path all_css_info.css

$lbinfo_html | Set-Content "all_lb_info.html"

 

Example-3: LB 성능 정보

####################################################################################
# Created by Insung Choi
# Login: connect-nsxtserver -host domain or ip -u admin
# Gathering LB infos and performance
####################################################################################
$svclbappsp = get-nsxtservice -name com.vmware.nsx.loadbalancer.application_profiles
$svclbsslp = get-nsxtservice -name com.vmware.nsx.loadbalancer.client_ssl_profiles
$svclbmonitor = get-nsxtservice -name com.vmware.nsx.loadbalancer.monitors
$svclbusgsumm = get-nsxtservice -name com.vmware.nsx.loadbalancer.node_usage_summary
$svclblbpersis = get-nsxtservice -name com.vmware.nsx.loadbalancer.persistence_profiles
$svclbpools = get-nsxtservice -name com.vmware.nsx.loadbalancer.pools
$svclbrules = get-nsxtservice -name com.vmware.nsx.loadbalancer.rules
$svclbsslp = get-nsxtservice -name com.vmware.nsx.loadbalancer.server_ssl_profiles
$svclbsvcs = get-nsxtservice -name com.vmware.nsx.loadbalancer.services
$svclbsvcdebugs = get-nsxtservice -name com.vmware.nsx.loadbalancer.services.debug_info
$svclbsvcplsts = get-nsxtservice -name com.vmware.nsx.loadbalancer.services.pools.statistics
$svclbsvcplstatus = get-nsxtservice -name com.vmware.nsx.loadbalancer.services.pools.status
$svclbsvcstatistics = get-nsxtservice -name com.vmware.nsx.loadbalancer.services.statistics
$svclbsvcstatus = get-nsxtservice -name com.vmware.nsx.loadbalancer.services.status
$svclbsvcusages = get-nsxtservice -name com.vmware.nsx.loadbalancer.services.usage
$svclbsvcvists = get-nsxtservice -name com.vmware.nsx.loadbalancer.services.virtual_servers.statistics
$svclbsvcvistatus = get-nsxtservice -name com.vmware.nsx.loadbalancer.services.virtual_servers.status
$svclbsslcips = get-nsxtservice -name com.vmware.nsx.loadbalancer.ssl.ciphers_and_protocols
$svclbusages = get-nsxtservice -name com.vmware.nsx.loadbalancer.usage_per_node
$svclbvs = get-nsxtservice -name com.vmware.nsx.loadbalancer.virtual_servers

$oj_svclbsvcs = $svclbsvcs.list().results | select virtual_server_ids, size, enabled, attachment, display_name

## setup a empty array
$allhtml=@()
$alllbinfo=@()
ForEach ($lbsvc in $oj_svclbsvcs){
	Foreach ($lbsvcnum in $lbsvc.virtual_server_ids) {
		$lbinfo = '' | select LB_Name,VS,VIP,Status,Protocol,App_Profile,Pool_Name		
		$lbvs = $svclbvs.list().results | where-object {$_.id -eq $lbsvcnum}
		$lbinfo.LB_Name = $lbsvc.display_name
		$lbinfo.VS = $lbvs.display_name
		$lbinfo.VIP = $lbvs.ip_address
		$lbinfo.Status = $lbvs.enabled
		$lbinfo.Protocol = $lbvs.ip_protocol
		$lbapp_name = $svclbappsp.get($lbvs.application_profile_id)
		$lbinfo.App_Profile = $lbapp_name.display_name
		$lbpool_name = $svclbpools.get($lbvs.pool_id)
		$lbinfo.Pool_Name = $lbpool_name.display_name
		#ForEach ($poolmembers in $lbpool_name.members) {
			#$poolinfo.member_name = $poolmembers.display_name
			#$poolinfo.member_ip = $poolmembers.ip_address
			#$poolinfo.member_weight = $poolmembers.weight
			#$poolinfo.member_backup = $poolmembers.backup_member
		#}
		$alllbinfo+=$lbinfo
	}
}

$lbinfo_html = @()
	$lbinfo_html = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>HTML TABLE</title><link rel="stylesheet" type="text/css" href="all_css_info.css" /></head><body>'
	$lbinfo_html += '<table><colgroup><col/><col/><col/><col/><col/><col/><col/></colgroup><tr><th>LB_Name</th><th>VS</th><th>VIP</th><th>Status</th><th>Protocol</th><th>App_Profile</th><th>Pool_Name</th></tr><H3>NSX-T LB Virtual Service Informantion</H3>'
ForEach ($one_lbinfo in $alllbinfo) {
	$lbinfo_html += '<tr><td>'+$one_lbinfo.LB_Name+'</td>'
	$lbinfo_html += '<td>'+$one_lbinfo.VS+'</td>'
	$lbinfo_html += '<td>'+$one_lbinfo.VIP+'</td>'
	$lbinfo_html += '<td>'+$one_lbinfo.Status+'</td>'
	$lbinfo_html += '<td>'+$one_lbinfo.Protocol+'</td>'
	$lbinfo_html += '<td>'+$one_lbinfo.App_Profile+'</td>'
	$lbinfo_html += '<td>'+$one_lbinfo.Pool_Name+'</td></tr>'	
}
	$lbinfo_html += '</table><br><h3>NSX-T Pool members</h3><table><colgroup><col/><col/><col/><col/><col/><col/></colgroup><tr><th>Pool_Name</th><th>Algorithm</th><th>SNAT</th><th>Status</th><th>Members</th><th>Member IP Address</th></tr>'

$allpoolinfo=@()
$lbpools = $svclbpools.list().results
ForEach ($lbpool in $lbpools) {
	$poolinfo = '' | select name,algorithm,snat,tcpmultiplex,member_name,member_ip
	$poolinfo.name = $lbpool.display_name
	$poolinfo.algorithm = $lbpool.algorithm
	$poolinfo.snat = $lbpool.snat_translation.type
	$poolinfo.tcpmultiplex = $lbpool.tcp_multiplexing_enabled
	$poolinfo.member_name = $lbpool.members.display_name
	$poolinfo.member_ip = $lbpool.members.ip_address
	$allpoolinfo+=$poolinfo
}

ForEach ($one_plinfo in $allpoolinfo) {
	$lbinfo_html += '<tr><td>'+$one_plinfo.name+'</td>'
	$lbinfo_html += '<td>'+$one_plinfo.algorithm+'</td>'
	$lbinfo_html += '<td>'+$one_plinfo.snat+'</td>'
	$lbinfo_html += '<td>'+$one_plinfo.tcpmultiplex+'</td>'
	$lbinfo_html += '<td>'+$one_plinfo.member_name+'</td>'
	$lbinfo_html += '<td>'+$one_plinfo.member_ip+'</td></tr>'
}

$lbusage = $svclbusgsumm.get()

$lbinfo_html += '</table><br><h3>LB Credit Cumsumption</h3><table><colgroup><col/><col/><col/><col/><col/><col/></colgroup><tr><th>usage%</th><th>Current credit</th><th>Remaining credit</th><th>current pool members</th><th>remaining pool members</th><th>Severity</th></tr>'
ForEach ($object in $lbusage) {
	$lbinfo_html += '<tr><td>'+$object.usage_percentage+'</td>'
	$lbinfo_html += '<td>'+$object.current_credit_number+'</td>'
	$lbinfo_html += '<td>'+$object.remaining_credit_number+'</td>'
	$lbinfo_html += '<td>'+$Object.current_pool_members+'</td>'
	$lbinfo_html += '<td>'+$object.remaining_pool_members+'</td>'
	$lbinfo_html += '<td>'+$object.severity+'</td></tr>'	
}

$oj_svclbsvcs = $svclbsvcs.list().results | select id,virtual_server_ids, size, enabled, attachment, display_name
$allperfinfo = @()
ForEach ($lbsvc in $oj_svclbsvcs){
	ForEach ($lbsvcnum in $lbsvc.virtual_server_ids) {
		$lbsvcstat = $svclbsvcvists.get($lbsvc.id,$lbsvcnum,'realtime').statistics
		$lbvs = $svclbvs.list().results | where-object {$_.id -eq $lbsvcnum}
		$perfinfo = '' | select lb_name,vs_name,currsessions,maxsessions,totalsessions,bytesin,bytesout,packetsin,packetsout,currsecrate,bytesinrate,bytesoutrate,httpreqrate,httpreq,packetsinrate,packetsoutrate
		$perfinfo.lb_name = $lbsvc.display_name
		$perfinfo.vs_name = $lbvs.display_name
		$perfinfo.currsessions = $lbsvcstat.current_sessions
		$perfinfo.maxsessions = $lbsvcstat.max_sessions
		$perfinfo.totalsessions = $lbsvcstat.total_sessions
		$perfinfo.bytesin = $lbsvcstat.bytes_in
		$perfinfo.bytesout = $lbsvcstat.bytes_out
		$perfinfo.packetsin = $lbsvcstat.packets_in
		$perfinfo.packetsout = $lbsvcstat.packets_out
		$perfinfo.currsecrate = $lbsvcstat.current_session_rate
		$perfinfo.bytesinrate = $lbsvcstat.bytes_in_rate
		$perfinfo.bytesoutrate = $lbsvcstat.bytes_out_rate
		$perfinfo.httpreqrate = $lbsvcstat.http_request_rate
		$perfinfo.httpreq = $lbsvcstat.http_requests
		$perfinfo.packetsinrate = $lbsvcstat.packets_in_rate
		$perfinfo.packetsoutrate = $lbsvcstat.packets_out_rate
		$allperfinfo += $perfinfo
	}
}

$lbinfo_html += '</table><br><h3>LB VS Performance</h3><table><colgroup></col></col></col></col></col></col></col></col></col></col></col></col></col></col></col></col></colgroup><tr><th>LB Name</th><th>VS Name</th><th>Current sessions</th><th>Max sessions</th><th>Total sessions</th><th>Bytes in</th><th>Bytes Out</th><th>Packets in</th><th>Packets out</th><th>Current session rate</th><th>Bytes in rate</th><th>Bytes out rate</th><th>Http request rate</th><th>Http request</th><th>Packets in rate</th>Packets out rate<th></th></tr>'

ForEach ($object in $allperfinfo) {
	$lbinfo_html += '<tr><td>'+$object.lb_name+'</td>'
	$lbinfo_html += '<td>'+$object.vs_name+'</td>'
	$lbinfo_html += '<td>'+$object.currsessions+'</td>'
	$lbinfo_html += '<td>'+$object.maxsessions+'</td>'
	$lbinfo_html += '<td>'+$object.totalsessions+'</td>'
	$lbinfo_html += '<td>'+$object.bytesin+'</td>'
	$lbinfo_html += '<td>'+$object.bytesout+'</td>'
	$lbinfo_html += '<td>'+$object.packetsin+'</td>'
	$lbinfo_html += '<td>'+$object.packetsout+'</td>'
	$lbinfo_html += '<td>'+$object.currsecrate+'</td>'
	$lbinfo_html += '<td>'+$object.bytesinrate+'</td>'
	$lbinfo_html += '<td>'+$object.bytesoutrate+'</td>'
	$lbinfo_html += '<td>'+$object.httpreqrate+'</td>'
	$lbinfo_html += '<td>'+$object.httpreq+'</td>'
	$lbinfo_html += '<td>'+$object.packetsinrate+'</td>'
	$lbinfo_html += '<td>'+$object.packetsoutrate+'</td></tr>'
}


$oj_svclbsvcs = $svclbsvcs.list().results | select id,virtual_server_ids, size, enabled, attachment, display_name
$allpoolperf = @()
ForEach ($lbsvc in $oj_svclbsvcs){
	ForEach ($object in $lbsvc.virtual_server_ids) {
		$poolid = $svclbvs.get($object).pool_id
		$lbsvcstat = $svclbsvcplsts.get($lbsvc.id,$poolid,'realtime').statistics
		$perfinfo = '' | select lb_name,pool_name,currsessions,maxsessions,totalsessions,bytesin,bytesout,packetsin,packetsout,currsecrate,bytesinrate,bytesoutrate,httpreqrate,httpreq,packetsinrate,packetsoutrate
		$perfinfo.lb_name = $lbsvc.display_name
		$perfinfo.pool_name =  $svclbpools.get($poolid).display_name
		$perfinfo.currsessions = $lbsvcstat.current_sessions
		$perfinfo.maxsessions = $lbsvcstat.max_sessions
		$perfinfo.totalsessions = $lbsvcstat.total_sessions
		$perfinfo.bytesin = $lbsvcstat.bytes_in
		$perfinfo.bytesout = $lbsvcstat.bytes_out
		$perfinfo.packetsin = $lbsvcstat.packets_in
		$perfinfo.packetsout = $lbsvcstat.packets_out
		$perfinfo.currsecrate = $lbsvcstat.current_session_rate
		$perfinfo.bytesinrate = $lbsvcstat.bytes_in_rate
		$perfinfo.bytesoutrate = $lbsvcstat.bytes_out_rate
		$perfinfo.httpreqrate = $lbsvcstat.http_request_rate
		$perfinfo.httpreq = $lbsvcstat.http_requests
		$perfinfo.packetsinrate = $lbsvcstat.packets_in_rate
		$perfinfo.packetsoutrate = $lbsvcstat.packets_out_rate
		$allpoolperf += $perfinfo
	}
}

$lbinfo_html += '</table><br><h3>LB Pool Performance</h3><table><colgroup></col></col></col></col></col></col></col></col></col></col></col></col></col></col></col></col></colgroup><tr><th>LB Name</th><th>Pool Name</th><th>Current sessions</th><th>Max sessions</th><th>Total sessions</th><th>Bytes in</th><th>Bytes Out</th><th>Packets in</th><th>Packets out</th><th>Current session rate</th><th>Bytes in rate</th><th>Bytes out rate</th><th>Http request rate</th><th>Http request</th><th>Packets in rate</th>Packets out rate<th></th></tr>'

ForEach ($object in $allpoolperf) {
	$lbinfo_html += '<tr><td>'+$object.lb_name+'</td>'
	$lbinfo_html += '<td>'+$object.pool_name+'</td>'
	$lbinfo_html += '<td>'+$object.currsessions+'</td>'
	$lbinfo_html += '<td>'+$object.maxsessions+'</td>'
	$lbinfo_html += '<td>'+$object.totalsessions+'</td>'
	$lbinfo_html += '<td>'+$object.bytesin+'</td>'
	$lbinfo_html += '<td>'+$object.bytesout+'</td>'
	$lbinfo_html += '<td>'+$object.packetsin+'</td>'
	$lbinfo_html += '<td>'+$object.packetsout+'</td>'
	$lbinfo_html += '<td>'+$object.currsecrate+'</td>'
	$lbinfo_html += '<td>'+$object.bytesinrate+'</td>'
	$lbinfo_html += '<td>'+$object.bytesoutrate+'</td>'
	$lbinfo_html += '<td>'+$object.httpreqrate+'</td>'
	$lbinfo_html += '<td>'+$object.httpreq+'</td>'
	$lbinfo_html += '<td>'+$object.packetsinrate+'</td>'
	$lbinfo_html += '<td>'+$object.packetsoutrate+'</td></tr>'
}

$lbinfo_html += '</table></body></thml>'

#export to HTML
$css  = "table{ Margin: 0px 0px 0px 4px; Border: 1px solid rgb(200, 200, 200); Font-Family: Tahoma; Font-Size: 10pt; Background-Color: rgb(252, 252, 252); }"
$css += "tr:hover td { Background-Color: #6495ED; Color: rgb(255, 255, 255);}"
$css += "tr:nth-child(even) { Background-Color: rgb(242, 242, 242); }"
Set-Content -Value $css -Path all_css_info.css

$lbinfo_html | Set-Content "all_lb_perf.html"