#------------------------------------------------------------------------
# Source File Information (DO NOT MODIFY)
# Source ID: ca09b758-5602-4532-9a86-880866408af4
# Source File: Host Memory Assessment Tool.psf
#------------------------------------------------------------------------
#========================================================================
# Code Generated By: SAPIEN Technologies, Inc., PowerShell Studio 2014 v4.1.57
# Generated On: 3/23/2015 3:20 PM
# Generated By: Brian Graf
#========================================================================
#----------------------------------------------
#region Application Functions
#----------------------------------------------

function OnApplicationLoad {
	#Note: This function is not called in Projects
	#Note: This function runs before the form is created
	#Note: To get the script directory in the Packager use: Split-Path $hostinvocation.MyCommand.path
	#Note: To get the console output in the Packager (Windows Mode) use: $ConsoleOutput (Type: System.Collections.ArrayList)
	#Important: Form controls cannot be accessed in this function
	#TODO: Add modules and custom code to validate the application load
	Add-PSSnapin VMware.VimAutomation.Core

	return $true #return true for success or false for failure
	
}

function OnApplicationExit {
	#Note: This function is not called in Projects
	#Note: This function runs after the form is closed
	#TODO: Add custom code to clean up and unload modules when the application exits
	
	$script:ExitCode = 0 #Set the exit code for the Packager
}

#endregion Application Functions

#----------------------------------------------
# Generated Form Function
#----------------------------------------------
function Call-Host_Memory_Assessment_Tool_psf {

	#----------------------------------------------
	#region Import the Assemblies
	#----------------------------------------------
	[void][reflection.assembly]::Load('mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089')
	[void][reflection.assembly]::Load('System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089')
	[void][reflection.assembly]::Load('System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089')
	[void][reflection.assembly]::Load('System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089')
	[void][reflection.assembly]::Load('System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a')
	[void][reflection.assembly]::Load('System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089')
	[void][reflection.assembly]::Load('System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a')
	[void][reflection.assembly]::Load('System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089')
	[void][reflection.assembly]::Load('System.ServiceProcess, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a')
	#endregion Import Assemblies

	#----------------------------------------------
	#region Generated Form Objects
	#----------------------------------------------
	[System.Windows.Forms.Application]::EnableVisualStyles()
	$formInterIntraTPSHostMem = New-Object 'System.Windows.Forms.Form'
	$lbl_Createdby = New-Object 'System.Windows.Forms.Label'
	$groupbox1 = New-Object 'System.Windows.Forms.GroupBox'
	$labelStatus = New-Object 'System.Windows.Forms.Label'
	$tb_user = New-Object 'System.Windows.Forms.TextBox'
	$labelESXiPassword = New-Object 'System.Windows.Forms.Label'
	$tb_vcenter = New-Object 'System.Windows.Forms.TextBox'
	$labelESXiUser = New-Object 'System.Windows.Forms.Label'
	$tb_pass = New-Object 'System.Windows.Forms.TextBox'
	$textbox1 = New-Object 'System.Windows.Forms.TextBox'
	$tb_ESXPass = New-Object 'System.Windows.Forms.TextBox'
	$lbl_vCenter = New-Object 'System.Windows.Forms.Label'
	$tb_ESXUser = New-Object 'System.Windows.Forms.TextBox'
	$btn_connect = New-Object 'System.Windows.Forms.Button'
	$lbl_user = New-Object 'System.Windows.Forms.Label'
	$lbl_pass = New-Object 'System.Windows.Forms.Label'
	$buttonDisableSSH = New-Object 'System.Windows.Forms.Button'
	$buttonEnableSSH = New-Object 'System.Windows.Forms.Button'
	$btn_Select = New-Object 'System.Windows.Forms.Button'
	$listview2 = New-Object 'System.Windows.Forms.ListView'
	$buttonExportToCSV = New-Object 'System.Windows.Forms.Button'
	$listview1 = New-Object 'System.Windows.Forms.ListView'
	$Total_Host_Mem = New-Object 'System.Windows.Forms.ColumnHeader'
	$PotentialHostMemLost = New-Object 'System.Windows.Forms.ColumnHeader'
	$HostFreeMem = New-Object 'System.Windows.Forms.ColumnHeader'
	$HostInfo = New-Object 'System.Windows.Forms.ColumnHeader'
	$SSH_Enabled = New-Object 'System.Windows.Forms.ColumnHeader'
	$ESX_Host = New-Object 'System.Windows.Forms.ColumnHeader'
	$HostMemSaved = New-Object 'System.Windows.Forms.ColumnHeader'
	$HostMemSavedZP = New-Object 'System.Windows.Forms.ColumnHeader'
	$ESX_Cluster = New-Object 'System.Windows.Forms.ColumnHeader'
	$InitialFormWindowState = New-Object 'System.Windows.Forms.FormWindowState'
	#endregion Generated Form Objects

	#----------------------------------------------
	# User Generated Script
	#----------------------------------------------
	<#	
		.NOTES
		===========================================================================
		 Created on:   	1/10/2015 11:22 AM
		 Created by:   	Brian Graf
		 Twitter: 		@vBrianGraf
		 Website: 		www.vtagion.com
		 Organization: 	VMware
		===========================================================================
		.DESCRIPTION
			This script will allow users to assess Host TPS Memory Savings
			This script requires PowerShell v3 and Plink.exe to run correctly.
			If users do not have Plink.exe in c:\temp, the script will prompt for action.
	#>
	
	Add-Type -ReferencedAssemblies ('System.Windows.Forms') -TypeDefinition  @" 
    using System;
    using System.Windows.Forms;
    using System.Collections;
    public class ListViewItemComparer : IComparer
    {
        public int column;
        public SortOrder sortOrder;
        public ListViewItemComparer()
        {
            column = 0;
            sortOrder = SortOrder.Ascending;
        }
        public ListViewItemComparer(int column, SortOrder sort)
        {
            this.column = column;
            sortOrder = sort;
        }
        public int Compare(object x, object y)
        {
            if(column >= ((ListViewItem)x).ListView.Columns.Count ||
                column >= ((ListViewItem)x).SubItems.Count ||
                column >= ((ListViewItem)y).SubItems.Count)
                column = 0;
        
            if(sortOrder == SortOrder.Ascending)
                return String.Compare(((ListViewItem)x).SubItems[column].Text,`
 ((ListViewItem)y).SubItems[column].Text);
            else
                return String.Compare(((ListViewItem)y).SubItems[column].Text,`
 ((ListViewItem)x).SubItems[column].Text);
        }
    }
"@ | Out-Null
	
	
	
	Function exportToCSV([System.Object[]] $expArray){
		Write-Host "Generating Export..."
		$global:CsvArray = @()
		$listView1.Items | ForEach-Object {
			$Object = New-Object PSObject
			$lvItem = $_
			$listview1.Columns | %{
				$Object | add-member Noteproperty -Name $_.Text -Value $lvItem.SubItems[$_.index].text -Force
			}
			$global:CsvArray += $Object
			Remove-Variable Object
		}
		#$global:CsvArray | Export-Csv -NoTypeInformation -Path c:\temp\export.csv
		Write-Host " Export Generated..."
		
		$save = New-Object System.Windows.Forms.SaveFileDialog
		$save.CreatePrompt = $False
		$save.SupportMultiDottedExtensions = $True
		$save.DefaultExt = "csv"
		$save.Filter = "CSV (*.csv) | *.csv*"
		$save.Title = "Export to CSV"
		if ($save.ShowDialog() -eq "OK")
		{
			$global:CsvArray | export-csv $save.FileName
			[System.Windows.Forms.MessageBox]::Show("CSV has been created successfully.", "CSV Created")
		}
	}
	function Connection-State {
		if (-not $Global:connected.IsConnected)
		{
			Write-Error "[ERROR] Unable to connect to $($tb_vcenter.text), please ensure you have correctly entered the ESXi address and username/password"
			$textbox1.BackColor = 'Red'
			$textbox1.Text = "Cannot connect."
		}
		Else
		{
			$textbox1.BackColor = 'Green'
			write-host "[INFO] Successfully connected to $($tb_vcenter.text)"
			write-host "[INFO] Retrieving ESXi information"
			$textbox1.Text = "connected"
		}
	}
	function Scan {
		param ($ESX)
		Write-Host "Scanning host $ESX"
		
		Echo Y | c:\Temp\plink.exe "$ESX" -pw "$($tb_ESXPASS.text)" -l "$($tb_ESXUser.text)" 'vsish -e get /memory/comprehensive' > c:\Temp\comprehensive.csv
		Echo Y | c:\Temp\plink.exe "$ESX" -pw "$($tb_ESXPASS.text)" -l "$($tb_ESXUser.text)" 'vsish -e get /memory/pshare/stats' > c:\Temp\pshare.csv
		
		#Pull Comprehensive Data
		$path = "C:\Temp\comprehensive.csv"
		Import-Csv $path | ForEach-Object {
			foreach ($property in $_.PSObject.Properties)
			{
				#Given to VMKernel:
				if ($property.value -like "*Given to VMKernel*")
				{
					$GiventoKernel = $property.value
					$GiventoKernel = $GiventoKernel.split(':')[1]
					$GiventoKernel = $GiventoKernel -replace 'kb'
					[long]$GiventoKernel = $GiventoKernel / 1048576
				}
				
				#Comprehensive FREE:
				if ($property.value -like "Free*")
				{
					$FREE = $property.value
					$FREE = $FREE.split(':')[1]
					$FREE = $FREE -replace 'kb'
					[long]$FREE = $FREE / 1048576
				}
			}
		}
		
		#Pull pshare
		$path = "C:\Temp\pshare.csv"
		Import-Csv $path | ForEach-Object {
			foreach ($property in $_.PSObject.Properties)
			{
				#MPNs Zero-pages:
				if ($property.value -like "*VM zero-pages *")
				{
					$MPNZeroPages = $property.value
					$MPNZeroPages = $MPNZeroPages.split(':')[1]
					if ($MPNZeroPages -gt 0)
					{
						[long]$MPNZeroPages = [long]$MPNZeroPages * 4
						[long]$MPNZeroPages = [long]$MPNZeroPages / 1048576
						
					}
				}
				
				#MPNs psharing VM memory:
				if ($property.value -like "*psharing VM memory*")
				{
					$MPNpSharing = $property.value
					$MPNpSharing = $MPNpSharing.split(':')[1]
					if ($MPNpSharing -gt 0)
					{
						[long]$MPNpSharing = [long]$MPNpSharing * 4
						[long]$MPNpSharing = [long]$MPNpSharing / 1048576
						
					}
				}
			}
		}
		
		#Remove-Item -Path c:\temp\comprehensive.csv -ErrorAction 'SilentlyContinue'
		#Remove-Item -Path c:\temp\pshare.csv -ErrorAction 'SilentlyContinue'
		$cluster = Get-VMHost -Name $ESX | get-cluster
		#Add-ListViewItem -ListView $listview1 -Items $ESX -SubItems (($giventokernel)/1048576), ((($MPNpSharing)*4096)/1048576), ((($MPNZeroPages)*4096)/1048576), ((($MPNpSharing-$MPNZeroPages)*4096)/1048576), (($FREE)/1048576)
		Add-ListViewItem -ListView $listview1 -Items $ESX -SubItems $cluster.name, ($giventokernel), ($MPNpSharing), ($MPNZeroPages), (($MPNpSharing - $MPNZeroPages)), (($FREE))
		
		$listview1.Columns[0].width = "-1"
		$listview1.Columns[1].width = "-2"
		$listview1.Columns[2].width = "-2"
		$listview1.Columns[3].width = "-2"
		$listview1.Columns[4].width = "-2"
		$listview1.Columns[5].width = "-2"
		$listview1.Columns[6].width = "-2"
		
		$listview1.Refresh()
		$textbox1.Text = "Connected"
		$textbox1.BackColor = 'Green'
	}
	
	$formInterIntraTPSHostMem_Load={
		if (!(Test-Path -path "c:\temp\plink.exe" -ErrorAction 'SilentlyContinue'))
		{
			$OUTPUT = [System.Windows.Forms.MessageBox]::Show("Plink.exe was not found in C:\Temp. Would you like this tool to attempt to download Plink?", "Plink.exe not found", 4)
			
			if ($OUTPUT -eq "YES")
			{
				$download = New-Object Net.WebClient
				$url = "http://the.earth.li/~sgtatham/putty/latest/x86/plink.exe"
				$file = ("C:\Temp\plink.exe")
				$download.Downloadfile($url, $file)
				Start-Sleep -Seconds 4
				if (!(Test-Path -path "c:\temp\plink.exe" -ErrorAction 'SilentlyContinue'))
				{
				$OUTPUT = [System.Windows.Forms.MessageBox]::Show("Plink.exe was not found in c:\Temp. Please place Plink.exe in the C:\Temp folder to continue. ", "Warning")
				if ($OUTPUT -eq "OK")
				{
				[environment]::Exit(0)
				}
				}
			}
			else
			{
				[environment]::Exit(0)
			}
			
			
			
			
		}
	}
	
	#region Control Helper Functions
	function Sort-ListViewColumn {
		<#
		.SYNOPSIS
			Sort the ListView's item using the specified column.
	
		.DESCRIPTION
			Sort the ListView's item using the specified column.
			This function uses Add-Type to define a class that sort the items.
			The ListView's Tag property is used to keep track of the sorting.
	
		.PARAMETER ListView
			The ListView control to sort.
	
		.PARAMETER ColumnIndex
			The index of the column to use for sorting.
			
		.PARAMETER  SortOrder
			The direction to sort the items. If not specified or set to None, it will toggle.
		
		.EXAMPLE
			Sort-ListViewColumn -ListView $listview1 -ColumnIndex 0
	#>
		param(	
				[ValidateNotNull()]
				[Parameter(Mandatory=$true)]
				[System.Windows.Forms.ListView]$ListView,
				[Parameter(Mandatory=$true)]
				[int]$ColumnIndex,
				[System.Windows.Forms.SortOrder]$SortOrder = 'None')
		
		if(($ListView.Items.Count -eq 0) -or ($ColumnIndex -lt 0) -or ($ColumnIndex -ge $ListView.Columns.Count))
		{
			return;
		}
		
		#region Define ListViewItemComparer
			try{
			$local:type = [ListViewItemComparer]
		}
		catch{
		Add-Type -ReferencedAssemblies ('System.Windows.Forms') -TypeDefinition  @" 
	using System;
	using System.Windows.Forms;
	using System.Collections;
	public class ListViewItemComparer : IComparer
	{
	    public int column;
	    public SortOrder sortOrder;
	    public ListViewItemComparer()
	    {
	        column = 0;
			sortOrder = SortOrder.Ascending;
	    }
	    public ListViewItemComparer(int column, SortOrder sort)
	    {
	        this.column = column;
			sortOrder = sort;
	    }
	    public int Compare(object x, object y)
	    {
			if(column >= ((ListViewItem)x).SubItems.Count)
				return  sortOrder == SortOrder.Ascending ? -1 : 1;
		
			if(column >= ((ListViewItem)y).SubItems.Count)
				return sortOrder == SortOrder.Ascending ? 1 : -1;
		
			if(sortOrder == SortOrder.Ascending)
	        	return String.Compare(((ListViewItem)x).SubItems[column].Text, ((ListViewItem)y).SubItems[column].Text);
			else
				return String.Compare(((ListViewItem)y).SubItems[column].Text, ((ListViewItem)x).SubItems[column].Text);
	    }
	}
"@  | Out-Null
		}
		#endregion
		
		if($ListView.Tag -is [ListViewItemComparer])
		{
			#Toggle the Sort Order
			if($SortOrder -eq [System.Windows.Forms.SortOrder]::None)
			{
				if($ListView.Tag.column -eq $ColumnIndex -and $ListView.Tag.sortOrder -eq 'Ascending')
				{
					$ListView.Tag.sortOrder = 'Descending'
				}
				else
				{
					$ListView.Tag.sortOrder = 'Ascending'
				}
			}
			else
			{
				$ListView.Tag.sortOrder = $SortOrder
			}
			
			$ListView.Tag.column = $ColumnIndex
			$ListView.Sort()#Sort the items
		}
		else
		{
			if($Sort -eq [System.Windows.Forms.SortOrder]::None)
			{
				$Sort = [System.Windows.Forms.SortOrder]::Ascending	
			}
			
			#Set to Tag because for some reason in PowerShell ListViewItemSorter prop returns null
			$ListView.Tag = New-Object ListViewItemComparer ($ColumnIndex, $SortOrder) 
			$ListView.ListViewItemSorter = $ListView.Tag #Automatically sorts
		}
	}
	function Add-ListViewItem {
	<#
		.SYNOPSIS
			Adds the item(s) to the ListView and stores the object in the ListViewItem's Tag property.
	
		.DESCRIPTION
			Adds the item(s) to the ListView and stores the object in the ListViewItem's Tag property.
	
		.PARAMETER ListView
			The ListView control to add the items to.
	
		.PARAMETER Items
			The object or objects you wish to load into the ListView's Items collection.
			
		.PARAMETER  ImageIndex
			The index of a predefined image in the ListView's ImageList.
		
		.PARAMETER  SubItems
			List of strings to add as Subitems.
		
		.PARAMETER Group
			The group to place the item(s) in.
		
		.PARAMETER Clear
			This switch clears the ListView's Items before adding the new item(s).
		
		.EXAMPLE
			Add-ListViewItem -ListView $listview1 -Items "Test" -Group $listview1.Groups[0] -ImageIndex 0 -SubItems "Installed"
	#>
		
		Param( 
		[ValidateNotNull()]
		[Parameter(Mandatory=$true)]
		[System.Windows.Forms.ListView]$ListView,
		[ValidateNotNull()]
		[Parameter(Mandatory=$true)]
		$Items,
		[int]$ImageIndex = -1,
		[string[]]$SubItems,
		[System.Windows.Forms.ListViewGroup]$Group,
		[switch]$Clear)
		
		if($Clear)
		{
			$ListView.Items.Clear();
		}
		
		if($Items -is [Array])
		{
			$ListView.BeginUpdate()
			foreach ($item in $Items)
			{		
				$listitem  = $ListView.Items.Add($item.ToString(), $ImageIndex)
				#Store the object in the Tag
				$listitem.Tag = $item
				
				if($SubItems -ne $null)
				{
					$listitem.SubItems.AddRange($SubItems)
				}
				
				if($Group -ne $null)
				{
					$listitem.Group = $Group
				}
			}
			$ListView.EndUpdate()
		}
		else
		{
			#Add a new item to the ListView
			$listitem  = $ListView.Items.Add($Items.ToString(), $ImageIndex)
			#Store the object in the Tag
			$listitem.Tag = $Items
			
			if($SubItems -ne $null)
			{
				$listitem.SubItems.AddRange($SubItems)
			}
			
			if($Group -ne $null)
			{
				$listitem.Group = $Group
			}
		}
	}
	
	#endregion
	
	$btn_connect_Click = {
		$textbox1.BackColor = 'Yellow'
		$textbox1.Text = "Connecting..."
		$global:connected = Connect-VIServer -Server $tb_vcenter.Text -User $tb_user.Text -Password $tb_pass.text
		if (-not $connected.IsConnected)
		{
			Write-Error "[ERROR] Unable to connect to $($tb_vcenter.text), please ensure you have correctly entered the ESXi address and username/password"
			$textbox1.BackColor = 'Red'
			$textbox1.Text = "Cannot connect."
		}
		Else
		{
			$textbox1.BackColor = 'Green'
			write-host "[INFO] Successfully connected to $($tb_vcenter.text)"
			write-host "[INFO] Retrieving ESXi information"
			$textbox1.Text = "connected"
			
			#scan
			$listview2.BeginUpdate()
			$listview2.Items.Clear()
			
			foreach ($cluster in (get-cluster))
			{
				$hosts = Get-Cluster -Name $cluster | Get-VMHost | Where { $_.PowerState -eq "PoweredOn" -and $_.ConnectionState -eq "Connected" }
				$listview2.Groups.Add("$($cluster.name)", "$($cluster.name)")
				
				foreach ($esx in $hosts)
				{
					#$cluster = Get-VMHost $esx | Get-Cluster
					$running = $esx | Get-VMHostService | where { $_.key -eq "TSM-SSH" }
					if ($running.running -eq $false)
					{
						$sshstatus = "Stopped"
					}
					else { $sshstatus = "Running" }
					
					Add-ListViewItem -ListView $listview2 -Group $listview2.Groups[$($cluster.name)] -Items $esx -SubItems $sshstatus
				}
			}
			$listview2.EndUpdate()
			$listview2.Columns[0].width = "-1"
			$listview2.Columns[1].width = "-2"
			$textbox1.Text = "Connected"
			$textbox1.BackColor = 'Green'
		}
	}
	$buttonExportToCSV_Click = {
		exportToCSV
	}
	
	$btn_Select_Click = {
		$textbox1.Text = "Working..."
		$textbox1.BackColor = 'Yellow'
		$buttonExportToCSV.Visible= $true
		$SSH_Error = @()
		$listview1.BeginUpdate()
	
		if ($tb_ESXPass.Text -eq "" -or $tb_ESXUser.Text -eq "")
		{
			[System.Windows.Forms.MessageBox]::Show("Please enter ESX credentials in their respective textboxes.")
			Connection-State
			$listview1.EndUpdate()
		}
		else
		{
			
			if ($SSH_Error -contains "error")
			{
				Write-Host "One or more hosts does not have SSH Enabled. Please enable SSH on all hosts that will be modified."
				[System.Windows.Forms.MessageBox]::Show("One or more hosts does not have SSH Enabled. Please enable SSH on all hosts that will be modified.")
				Connection-State
				$listview1.EndUpdate()
			}
			else
			{
				$listview1.Items.Clear()
				$listview2.CheckedItems | ForEach-Object {
					$listview1.Groups.Add("$($_.text)", "$($_.text)")
					Scan -ESX "$($_.text)"
				}
				$listview1.EndUpdate()
			}
			
		}
		$listview1.EndUpdate()
		Connection-State
	}
	
	$buttonEnableSSH_Click = {
		$textbox1.BackColor = 'Yellow'
		$textbox1.Text = "Enabling SSH..."
		$listview2.CheckedItems | ForEach-Object {
			
			Get-VMHost $_.Text | Get-VMHostService | where { $_.key -eq "TSM-SSH" } | Start-VMHostService -Confirm:$false
			Write-Host "SSH started on $($_.text)"
			$_.SubItems[-1].Text = "Running"
		}
		Connection-State
	}
	
	$buttonDisableSSH_Click={
		$textbox1.BackColor = 'Yellow'
		$textbox1.Text = "Disabling SSH..."
		$listview2.CheckedItems | ForEach-Object {
			
			Get-VMHost $_.Text | Get-VMHostService | where { $_.key -eq "TSM-SSH" } | Stop-VMHostService -Confirm:$false
			Write-Host "SSH stopped on $($_.text)"
			$_.SubItems[-1].Text = "Stopped"
			
		}
		Connection-State
	}
	
	$listview2_ColumnClick=[System.Windows.Forms.ColumnClickEventHandler]{
		Sort-ListViewColumn $this $_.Column
	}
	
	# --End User Generated Script--
	#----------------------------------------------
	#region Generated Events
	#----------------------------------------------
	
	$Form_StateCorrection_Load=
	{
		#Correct the initial state of the form to prevent the .Net maximized form issue
		$formInterIntraTPSHostMem.WindowState = $InitialFormWindowState
	}
	
	$Form_Cleanup_FormClosed=
	{
		#Remove all event handlers from the controls
		try
		{
			$btn_connect.remove_Click($btn_connect_Click)
			$buttonDisableSSH.remove_Click($buttonDisableSSH_Click)
			$buttonEnableSSH.remove_Click($buttonEnableSSH_Click)
			$btn_Select.remove_Click($btn_Select_Click)
			$listview2.remove_ColumnClick($listview2_ColumnClick)
			$buttonExportToCSV.remove_Click($buttonExportToCSV_Click)
			$formInterIntraTPSHostMem.remove_Load($formInterIntraTPSHostMem_Load)
			$formInterIntraTPSHostMem.remove_Load($Form_StateCorrection_Load)
			$formInterIntraTPSHostMem.remove_FormClosed($Form_Cleanup_FormClosed)
		}
		catch [Exception]
		{ }
	}
	#endregion Generated Events

	#----------------------------------------------
	#region Generated Form Code
	#----------------------------------------------
	$formInterIntraTPSHostMem.SuspendLayout()
	$groupbox1.SuspendLayout()
	#
	# formInterIntraTPSHostMem
	#
	$formInterIntraTPSHostMem.Controls.Add($lbl_Createdby)
	$formInterIntraTPSHostMem.Controls.Add($groupbox1)
	$formInterIntraTPSHostMem.Controls.Add($buttonDisableSSH)
	$formInterIntraTPSHostMem.Controls.Add($buttonEnableSSH)
	$formInterIntraTPSHostMem.Controls.Add($btn_Select)
	$formInterIntraTPSHostMem.Controls.Add($listview2)
	$formInterIntraTPSHostMem.Controls.Add($buttonExportToCSV)
	$formInterIntraTPSHostMem.Controls.Add($listview1)
	$formInterIntraTPSHostMem.BackColor = 'Black'
	#region Binary Data
	$formInterIntraTPSHostMem.BackgroundImage = [System.Convert]::FromBase64String('
[encoded data, 242858 characters]
uxV2KuxV2KuxV2KuxV2KuxV2KuxV2Kv/2Q==')
	#endregion
	$formInterIntraTPSHostMem.BackgroundImageLayout = 'Stretch'
	$formInterIntraTPSHostMem.ClientSize = '993, 662'
	$formInterIntraTPSHostMem.FormBorderStyle = 'FixedSingle'
	#region Binary Data
	$formInterIntraTPSHostMem.Icon = [System.Convert]::FromBase64String('
[encoded data, 499884 characters]
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=')
	#endregion
	$formInterIntraTPSHostMem.MaximizeBox = $False
	$formInterIntraTPSHostMem.Name = "formInterIntraTPSHostMem"
	$formInterIntraTPSHostMem.Text = "Inter -> Intra TPS Host Memory Assessment"
	$formInterIntraTPSHostMem.add_Load($formInterIntraTPSHostMem_Load)
	#
	# lbl_Createdby
	#
	$lbl_Createdby.BackColor = 'Transparent'
	$lbl_Createdby.ForeColor = 'White'
	$lbl_Createdby.Location = '327, 643'
	$lbl_Createdby.Name = "lbl_Createdby"
	$lbl_Createdby.Size = '654, 19'
	$lbl_Createdby.TabIndex = 21
	$lbl_Createdby.Text = "Created by: Brian Graf (@vBrianGraf),  Mark Achtemichuk (@vmMarkA)"
	$lbl_Createdby.TextAlign = 'TopRight'
	#
	# groupbox1
	#
	$groupbox1.Controls.Add($labelStatus)
	$groupbox1.Controls.Add($tb_user)
	$groupbox1.Controls.Add($labelESXiPassword)
	$groupbox1.Controls.Add($tb_vcenter)
	$groupbox1.Controls.Add($labelESXiUser)
	$groupbox1.Controls.Add($tb_pass)
	$groupbox1.Controls.Add($textbox1)
	$groupbox1.Controls.Add($tb_ESXPass)
	$groupbox1.Controls.Add($lbl_vCenter)
	$groupbox1.Controls.Add($tb_ESXUser)
	$groupbox1.Controls.Add($btn_connect)
	$groupbox1.Controls.Add($lbl_user)
	$groupbox1.Controls.Add($lbl_pass)
	$groupbox1.BackColor = 'Transparent'
	$groupbox1.ForeColor = 'DodgerBlue'
	$groupbox1.Location = '13, 12'
	$groupbox1.Name = "groupbox1"
	$groupbox1.Size = '459, 136'
	$groupbox1.TabIndex = 20
	$groupbox1.TabStop = $False
	$groupbox1.Text = "Login Information"
	#
	# labelStatus
	#
	$labelStatus.BackColor = 'Transparent'
	$labelStatus.ForeColor = 'White'
	$labelStatus.Location = '234, 74'
	$labelStatus.Name = "labelStatus"
	$labelStatus.Size = '115, 20'
	$labelStatus.TabIndex = 20
	$labelStatus.Text = "Status:"
	$labelStatus.TextAlign = 'MiddleCenter'
	#
	# tb_user
	#
	$tb_user.BackColor = 'Black'
	$tb_user.ForeColor = 'White'
	$tb_user.Location = '174, 42'
	$tb_user.Name = "tb_user"
	$tb_user.Size = '150, 20'
	$tb_user.TabIndex = 1
	#
	# labelESXiPassword
	#
	$labelESXiPassword.BackColor = 'Transparent'
	$labelESXiPassword.ForeColor = 'White'
	$labelESXiPassword.Location = '125, 74'
	$labelESXiPassword.Name = "labelESXiPassword"
	$labelESXiPassword.Size = '100, 20'
	$labelESXiPassword.TabIndex = 19
	$labelESXiPassword.Text = "ESXi Password:"
	$labelESXiPassword.TextAlign = 'MiddleCenter'
	#
	# tb_vcenter
	#
	$tb_vcenter.BackColor = 'Black'
	$tb_vcenter.ForeColor = 'White'
	$tb_vcenter.Location = '18, 42'
	$tb_vcenter.Name = "tb_vcenter"
	$tb_vcenter.Size = '150, 20'
	$tb_vcenter.TabIndex = 0
	#
	# labelESXiUser
	#
	$labelESXiUser.BackColor = 'Transparent'
	$labelESXiUser.ForeColor = 'White'
	$labelESXiUser.Location = '18, 74'
	$labelESXiUser.Name = "labelESXiUser"
	$labelESXiUser.Size = '100, 20'
	$labelESXiUser.TabIndex = 18
	$labelESXiUser.Text = "ESXi User:"
	$labelESXiUser.TextAlign = 'MiddleCenter'
	#
	# tb_pass
	#
	$tb_pass.BackColor = 'Black'
	$tb_pass.ForeColor = 'White'
	$tb_pass.Location = '330, 42'
	$tb_pass.Name = "tb_pass"
	$tb_pass.PasswordChar = '*'
	$tb_pass.Size = '105, 20'
	$tb_pass.TabIndex = 2
	#
	# textbox1
	#
	$textbox1.BackColor = 'Yellow'
	$textbox1.Font = "Microsoft Sans Serif, 8.25pt, style=Bold"
	$textbox1.Location = '234, 97'
	$textbox1.Name = "textbox1"
	$textbox1.Size = '115, 20'
	$textbox1.TabIndex = 10
	$textbox1.Text = "Not Connected"
	$textbox1.TextAlign = 'Center'
	#
	# tb_ESXPass
	#
	$tb_ESXPass.BackColor = 'Black'
	$tb_ESXPass.ForeColor = 'White'
	$tb_ESXPass.Location = '125, 97'
	$tb_ESXPass.Name = "tb_ESXPass"
	$tb_ESXPass.PasswordChar = '*'
	$tb_ESXPass.Size = '100, 20'
	$tb_ESXPass.TabIndex = 4
	#
	# lbl_vCenter
	#
	$lbl_vCenter.BackColor = 'Transparent'
	$lbl_vCenter.ForeColor = 'White'
	$lbl_vCenter.Location = '18, 19'
	$lbl_vCenter.Name = "lbl_vCenter"
	$lbl_vCenter.Size = '150, 20'
	$lbl_vCenter.TabIndex = 5
	$lbl_vCenter.Text = "vCenter:"
	$lbl_vCenter.TextAlign = 'MiddleCenter'
	#
	# tb_ESXUser
	#
	$tb_ESXUser.BackColor = 'Black'
	$tb_ESXUser.ForeColor = 'White'
	$tb_ESXUser.Location = '18, 97'
	$tb_ESXUser.Name = "tb_ESXUser"
	$tb_ESXUser.Size = '100, 20'
	$tb_ESXUser.TabIndex = 3
	#
	# btn_connect
	#
	$btn_connect.ForeColor = 'DodgerBlue'
	$btn_connect.Location = '360, 97'
	$btn_connect.Name = "btn_connect"
	$btn_connect.Size = '75, 23'
	$btn_connect.TabIndex = 5
	$btn_connect.Text = "Connect"
	$btn_connect.UseVisualStyleBackColor = $True
	$btn_connect.add_Click($btn_connect_Click)
	#
	# lbl_user
	#
	$lbl_user.BackColor = 'Transparent'
	$lbl_user.ForeColor = 'White'
	$lbl_user.Location = '174, 19'
	$lbl_user.Name = "lbl_user"
	$lbl_user.Size = '150, 20'
	$lbl_user.TabIndex = 6
	$lbl_user.Text = "vCenter User:"
	$lbl_user.TextAlign = 'MiddleCenter'
	#
	# lbl_pass
	#
	$lbl_pass.BackColor = 'Transparent'
	$lbl_pass.ForeColor = 'White'
	$lbl_pass.Location = '330, 19'
	$lbl_pass.Name = "lbl_pass"
	$lbl_pass.Size = '105, 20'
	$lbl_pass.TabIndex = 7
	$lbl_pass.Text = "vCenter Password:"
	$lbl_pass.TextAlign = 'MiddleCenter'
	#
	# buttonDisableSSH
	#
	$buttonDisableSSH.BackColor = 'Transparent'
	$buttonDisableSSH.ForeColor = 'DodgerBlue'
	$buttonDisableSSH.Location = '290, 336'
	$buttonDisableSSH.Name = "buttonDisableSSH"
	$buttonDisableSSH.Size = '81, 23'
	$buttonDisableSSH.TabIndex = 15
	$buttonDisableSSH.Text = "Disable SSH"
	$buttonDisableSSH.UseVisualStyleBackColor = $False
	$buttonDisableSSH.add_Click($buttonDisableSSH_Click)
	#
	# buttonEnableSSH
	#
	$buttonEnableSSH.BackColor = 'Transparent'
	$buttonEnableSSH.ForeColor = 'DodgerBlue'
	$buttonEnableSSH.Location = '290, 307'
	$buttonEnableSSH.Name = "buttonEnableSSH"
	$buttonEnableSSH.Size = '81, 23'
	$buttonEnableSSH.TabIndex = 14
	$buttonEnableSSH.Text = "Enable SSH"
	$buttonEnableSSH.UseVisualStyleBackColor = $False
	$buttonEnableSSH.add_Click($buttonEnableSSH_Click)
	#
	# btn_Select
	#
	$btn_Select.BackColor = 'Transparent'
	$btn_Select.ForeColor = 'DodgerBlue'
	$btn_Select.Location = '225, 377'
	$btn_Select.Name = "btn_Select"
	$btn_Select.Size = '59, 23'
	$btn_Select.TabIndex = 13
	$btn_Select.Text = "Select"
	$btn_Select.UseVisualStyleBackColor = $False
	$btn_Select.add_Click($btn_Select_Click)
	#
	# listview2
	#
	$listview2.BackColor = 'DimGray'
	$listview2.CheckBoxes = $True
	[void]$listview2.Columns.Add($HostInfo)
	[void]$listview2.Columns.Add($SSH_Enabled)
	$listview2.ForeColor = 'White'
	$listview2.FullRowSelect = $True
	$listview2.Location = '13, 154'
	$listview2.Name = "listview2"
	$listview2.Size = '271, 217'
	$listview2.TabIndex = 12
	$listview2.UseCompatibleStateImageBehavior = $False
	$listview2.View = 'Details'
	$listview2.add_ColumnClick($listview2_ColumnClick)
	#
	# buttonExportToCSV
	#
	$buttonExportToCSV.BackColor = 'Black'
	$buttonExportToCSV.FlatAppearance.BorderColor = '255, 255, 128'
	$buttonExportToCSV.FlatAppearance.BorderSize = 6
	$buttonExportToCSV.FlatStyle = 'System'
	$buttonExportToCSV.ForeColor = 'DodgerBlue'
	$buttonExportToCSV.Location = '859, 12'
	$buttonExportToCSV.Name = "buttonExportToCSV"
	$buttonExportToCSV.Size = '122, 23'
	$buttonExportToCSV.TabIndex = 8
	$buttonExportToCSV.Text = "Export to CSV"
	$buttonExportToCSV.UseVisualStyleBackColor = $False
	$buttonExportToCSV.Visible = $False
	$buttonExportToCSV.add_Click($buttonExportToCSV_Click)
	#
	# listview1
	#
	$listview1.BackColor = 'DimGray'
	[void]$listview1.Columns.Add($ESX_Host)
	[void]$listview1.Columns.Add($ESX_Cluster)
	[void]$listview1.Columns.Add($Total_Host_Mem)
	[void]$listview1.Columns.Add($HostMemSaved)
	[void]$listview1.Columns.Add($HostMemSavedZP)
	[void]$listview1.Columns.Add($PotentialHostMemLost)
	[void]$listview1.Columns.Add($HostFreeMem)
	$listview1.ForeColor = 'White'
	$listview1.FullRowSelect = $True
	$listview1.Location = '13, 404'
	$listview1.Name = "listview1"
	$listview1.ShowGroups = $False
	$listview1.Size = '969, 236'
	$listview1.TabIndex = 4
	$listview1.UseCompatibleStateImageBehavior = $False
	$listview1.View = 'Details'
	#
	# Total_Host_Mem
	#
	$Total_Host_Mem.Text = "Total Host Memory (GB)"
	$Total_Host_Mem.Width = 128
	#
	# PotentialHostMemLost
	#
	$PotentialHostMemLost.Text = "Potential Host Mem Savings Lost (GB)"
	$PotentialHostMemLost.Width = 197
	#
	# HostFreeMem
	#
	$HostFreeMem.Text = "Host Free Mem (GB)"
	$HostFreeMem.Width = 120
	#
	# HostInfo
	#
	$HostInfo.Text = "ESX Host"
	$HostInfo.Width = 186
	#
	# SSH_Enabled
	#
	$SSH_Enabled.Text = "SSH Status"
	$SSH_Enabled.Width = 77
	#
	# ESX_Host
	#
	$ESX_Host.Text = "ESX Host"
	$ESX_Host.Width = 134
	#
	# HostMemSaved
	#
	$HostMemSaved.Text = "Host Mem Saved via TPS (GB)"
	$HostMemSaved.Width = 167
	#
	# HostMemSavedZP
	#
	$HostMemSavedZP.Text = "Host Mem Saved via TPS Zero Pages (GB)"
	$HostMemSavedZP.Width = 227
	#
	# ESX_Cluster
	#
	$ESX_Cluster.Text = "Cluster"
	$groupbox1.ResumeLayout($false)
	$formInterIntraTPSHostMem.ResumeLayout($false)
	#endregion Generated Form Code

	#----------------------------------------------

	#Save the initial state of the form
	$InitialFormWindowState = $formInterIntraTPSHostMem.WindowState
	#Init the OnLoad event to correct the initial state of the form
	$formInterIntraTPSHostMem.add_Load($Form_StateCorrection_Load)
	#Clean up the control events
	$formInterIntraTPSHostMem.add_FormClosed($Form_Cleanup_FormClosed)
	#Show the Form
	return $formInterIntraTPSHostMem.ShowDialog()

} #End Function

#Call OnApplicationLoad to initialize
if((OnApplicationLoad) -eq $true)
{
	#Call the form
	Call-Host_Memory_Assessment_Tool_psf | Out-Null
	#Perform cleanup
	OnApplicationExit
}
