#------------------------------------------------------------------------
# Source File Information (DO NOT MODIFY)
# Source ID: b24654a3-c952-4b96-8e01-c56d9800c4a7
# Source File: FirstForm4-tabs.psf
#------------------------------------------------------------------------
#region File Recovery Data (DO NOT MODIFY)
<#RecoveryData:
PxYAAB+LCAAAAAAABADNWNtu2kAQfa/Uf7D8TAEbg4kElhJS1KpJgwpN+xat7YFss/ai9ToJ/fqO
L0QBfCVAIxDyZWbP7JyzMyMGP8DhjyBWl0QSBS8Cyv2hqjc11fr4QVEGN4IuqE/YmDL4TjywxlQE
csyFZ3ySxA6ay2A+aO1YJb72H3CkIldLGKrTVSDBa/6ivsufgma0QvLbULJeNZTbNBij2Y4+DWUU
MhkKGPoQSkFYQ5mENqPON1jN+AP4Q9s0Sdfp9rSzjgHt/pmq+BjKUJ3jepqqOPeUuQLt1BH3peAs
SLaIgU4EX4KQq9ThPJR86hAGl9QDPwoCTXsNResMWmvTMtdr7oJqjRGp1GfEKPhySv+ig6mZDcXo
GaVOUZZVK95aqe0MnmUUi/B2TT8/InZqd8WJm655F10PWvHbtWk5nTNip7k9OqmXX0aTIk53s3DF
HSIRW7U0HbnUd3KRl+QIqoLxFBimB9yvvgvPqtWu4hJz3jvrIOdGFQdMcNHylRiakAUcnR4sDUvE
KTx2xSQZDUXP4iiPpTViJZcJcV3qL1QLM59+K/mlhPW7SJi2e0jrU5Z3WHM0t2v+M4BbGoSETeWK
wQVxHkaccaFaMxFC9grlKrkiNhz/CLMIJdroFAR2npjGErnkFNyYldwNF5aCqKxnayZPaBlhV/RP
4tTaemYrKZNPZY8XASlJhEpuiNi4Yy3UU0cEcMGfT1Lig3gHiFZfGZsk62Ytkjewa9KLW9azz3oR
vdm1bqtDR6kf3RN/Ae5WjHevXm327f2Jvgil5P7RebZjGCTVx3jexHOnj6nv1iJ6A7wW0SY2Ab3+
Ma5abJJjXC+w+s1gS184ijoPW0m5ix8eSlOnKh43oVyGb1JT1Bkq83uNYVJG/Xp9KJFgEmot7fVM
HFn0flWpl80gRVUmia5medl98O5GU/3ko2k1l/8ymlabmpOSVGs3e4ynGfVoDZlbit5ZLyvVVmEX
6xoRhXt0sdwR4pD9q/JkE4ulXmCH7V/5cikpVxu3mzfnQQAeKgGCtW36ZGV5gcMFo/YB1DRovay6
jZLo9xQYBz8j5YjRn5CnARLkCYvsPljtzrw7N+ea5nbbpEPKsX577CR7GnEBhwd6uU0kP2i9/sPY
+gcZbzYwPxYAAA==#>
#endregion


#----------------------------------------------
#region Application Functions
#----------------------------------------------

#endregion Application Functions

#----------------------------------------------
# Generated Form Function
#----------------------------------------------
function Call-FirstForm4-tabs_psf {

	#----------------------------------------------
	#region Import the Assemblies
	#----------------------------------------------
	[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')
	#endregion Import Assemblies

	#----------------------------------------------
	#region Generated Form Objects
	#----------------------------------------------
	[System.Windows.Forms.Application]::EnableVisualStyles()
	$form1 = New-Object 'System.Windows.Forms.Form'
	$DHCP = New-Object 'System.Windows.Forms.TabControl'
	$tabpage1 = New-Object 'System.Windows.Forms.TabPage'
    $flowlayoutControls1 = New-Object 'System.Windows.Forms.FlowLayoutPanel'
	$labelDHCPServerName = New-Object 'System.Windows.Forms.Label'
    $labelVcenterServerName = New-Object 'System.Windows.Forms.Label'
    $labelVCenterUserName = New-Object 'System.Windows.Forms.Label'
    $labelVCenterPassword = New-Object 'System.Windows.Forms.Label'
	$DHCPserverBox = New-Object 'System.Windows.Forms.TextBox'
    $VCenterServerBox = New-Object 'System.Windows.Forms.TextBox'
   # $VCenterUserName = New-Object 'System.Windows.Forms.TextBox'
   # $VCenterUserPassword = New-Object 'System.Windows.Forms.TextBox'
   # $CheckBoxUseWindowsLogin = New-Object 'System.Windows.Forms.CheckBox'
	$buttonConnect = New-Object 'System.Windows.Forms.Button'
    $buttonVMHostInfo = New-Object 'System.Windows.Forms.Button'
    $ButtonScopeStats = New-Object 'System.Windows.Forms.Button'
   # $ButtonScopes1 = New-Object 'System.Windows.Forms.Button'
    $ButtonTest = New-Object 'System.Windows.Forms.Button'
	$Output = New-Object 'System.Windows.Forms.TextBox'
	$tabpage2 = New-Object 'System.Windows.Forms.TabPage'
    $panel1 = New-Object 'System.Windows.Forms.Panel'
	$Connect = New-Object 'System.Windows.Forms.Button'
	$InitialFormWindowState = New-Object 'System.Windows.Forms.FormWindowState'
    $comboboxScopes = New-Object 'System.Windows.Forms.ComboBox'
    $ButtonSelect = New-Object 'System.Windows.Forms.Button'
    $labelScopeSelected = New-Object 'System.Windows.Forms.Label'
    $labelCurrentScope = New-Object 'System.Windows.Forms.Label'
    $labelConnectedDHCPServer = New-Object 'System.Windows.Forms.Label'
    $labelDHCPServerStatus = New-Object 'System.Windows.Forms.Label'
    $radioDisplay = New-Object 'System.Windows.Forms.RadioButton'
    $radioGridview = New-Object 'System.Windows.Forms.RadioButton'
    $radioCSV = New-Object 'System.Windows.Forms.RadioButton'
    $ButtonAvailableIPAddresses = New-Object 'System.Windows.Forms.Button'
    $ButtonExclusionList = New-Object 'System.Windows.Forms.Button'
    $ButtonReservationList = New-Object 'System.Windows.Forms.Button'
	#endregion Generated Form Objects

	#----------------------------------------------
	# User Generated Script
	#----------------------------------------------
	
	$form1_Load={
		#TODO: Initialize Form Controls here
		#$DefaultCompName = $env:COMPUTERNAME
        #$Output.Text = $DefaultCompName
        $Global:DisplayType = "OnScreen"
        NA-VCconn
        #NA-TestOutput   
	}
####################################################################################################################################
    $flowlayoutControls1_Paint=[System.Windows.Forms.PaintEventHandler]{
	#Event Argument: $_ = [System.Windows.Forms.PaintEventArgs]
		#TODO: Place custom script here
		
	}
####################################################################################################################################	
	$Output_TextChanged={
		#TODO: Place custom script here
		
	}
####################################################################################################################################	
	$comboboxScopes_SelectedIndexChanged={
		#TODO: Place custom script here
	
		
	}
####################################################################################################################################
    $labelCurrentScope_Click={
           
    }
####################################################################################################################################
    $labelConnectedDHCPServer_Click={}
####################################################################################################################################
    $labelDHCPServerStatus_Click={}
####################################################################################################################################
	$DHCPserverBox_TextChanged={
		#TODO: Place custom script here
	}
####################################################################################################################################
    $VCenterServerBox_TextChanged={}
####################################################################################################################################	
<#
    $VCenterUserName_TextChanged={
    
    }

    $VCenterUserPassword_TextChanged={
    
    } 

    $CheckBoxUseWindowsLogin_CheckedChanged={
    
        If ($CheckBoxUseWindowsLogin.Checked -eq $true) {
            $Output.Text = "Checkbox Checked"
            }
    }
#>
	$buttonConnect_Click={
		#TODO: Place custom script here
        If (!$DHCPserverBox.Text) {
            $Output.Text = "###### Please enter DHCP server name in the Box ###### "   
        }

        Else {
            $Output.Text = "**** Locating DHCP Server: $($DHCPserverBox.text.ToUpper()) ****"
            $PingDHCPServer = Test-Connection -ComputerName $DHCPserverBox.text -Count 1 -ErrorAction SilentlyContinue
            If (!$PingDHCPServer) { $Output.Text = "#### DHCP Server: $($DHCPserverBox.text.ToUpper()) is not accessible - Please Check the Name!  ####" }
            Else {
		          NA-Server-Connection 1 ($DHCPserverBox.text)
                  NA-GetScopes 
            }
        }
        

	}
	
####################################################################################################################################
    $ButtonAvailableIPAddresses_Click={
        If ($labelScopeSelected.Text -ne $Global:ScopeValue) {   
                If (Get-PSSession) {
                    NA-Get-DHCPinfo -Option AvailableIPAddresses -ScopeSend ($labelScopeSelected.Text) -DisplayOption $Global:DisplayType
                }
                Else { $Output.Text = "###  Not Connected to DHCP Server - Please enter DHCP server name and Connect ###" }
        }
    }
####################################################################################################################################
    $ButtonExclusionList_Click={
        
        #$Output.Text = $Global:DisplayType
        If ($labelScopeSelected.Text -ne $Global:ScopeValue) {    
                If (Get-PSSession) {
                    NA-Get-DHCPinfo -Option ExclusionList -ScopeSend ($labelScopeSelected.Text) -DisplayOption $Global:DisplayType
                }
                Else { $Output.Text = "###  Not Connected to DHCP Server - Please enter DHCP server name and Connect ###" }
        }
        Else { $Output.Text = "###  Scope Not Found! -- Please Select a Scope from the List ###"}
        
    } 
####################################################################################################################################
    $ButtonReservationList_Click={
        
        If ($labelScopeSelected.Text -ne $Global:ScopeValue) {    
                    If (Get-PSSession) {
                        NA-Get-DHCPinfo -Option ReservationList -ScopeSend ($labelScopeSelected.Text) -DisplayOption $Global:DisplayType
                    }
                    Else { $Output.Text = "###  Not Connected to DHCP Server - Please enter DHCP server name and Connect ###" }
            }
            Else { $Output.Text = "###  Scope Not Found! -- Please Select a Scope from the List ###"}
    
    }#end Button
        
#################################################################################################################################### 
    $buttonVMHostInfo_Click={
        
        If ( $Global:VCenterConnectionStatus -eq $False) { $Output.Text = "### Please Connect to VCenter Server First ###" } 

        Else {
            $Output.Text = "Geting VM Host Information ...... Please wait!"
            $VMHostInformation = Get-VMHost | select name,build,model,@{Name="MemoryTotalGB";Expression={"{0:N2}" -f $_.memorytotalgb}},@{Name="MemoryUsageGB";Expression={"{0:N2}" -f $_.memoryusageGb}} | FT -AutoSize | Out-String
            $Output.Text = $VMHostInformation
        }
    }
    

####################################################################################################################################
    $ButtonScopeStats_Click={
        
        If (Get-PSSession) {

            Invoke-Command -Session $Global:Session { $Get_dhcpScopeStats = Get-DhcpServerV4ScopeStatistics }
            $DhcpScopeStats = Invoke-Command -Session $Global:Session { $Get_dhcpScopeStats }
            
            If ($radioGridview.Checked) {
                $Output.Text = $DhcpScopeStats | select ScopeID,Free,InUse,@{n="PercentageInUse";e={[Math]::Round($_.PercentageInUse,2)}},Reserved,Pending,SuperScopeName | Out-GridView #ft -AutoSize | Out-String
            }
            Else {
                $Output.Text = $DhcpScopeStats | select ScopeID,Free,InUse,@{n="PercentageInUse";e={[Math]::Round($_.PercentageInUse,2)}},Reserved,Pending,SuperScopeName | ft -AutoSize | Out-String
            }
        }#end If

        Else {
            $Output.Text = "No Connection to DHCP exists - Cannot proceed!"
        }#end Else

    } 
####################################################################################################################################
   
    $ButtonSelect_Click={
        [Bool]$Yes = $False
        $Global:Scope | % { $IP = $_; $CmboIP = $comboboxScopes.Text; If ($IP -eq $CmboIP) { $Yes = $True }  }        
        
        If ($Yes) {
            $labelScopeSelected.Text = $comboboxScopes.Text
        }
        Else { $Output.Text = "Invalid IP Selection - Try Again!"}
       # NA-GetScopes
    }
####################################################################################################################################

<#
    $ButtonScopes1_Click={
        
        $Output.Text = "Hello"
        #NA-GetScopes
           }
#> 



####################################################################################################################################
        $radioDisplay_SelectedIndexChanged={
            $Global:DisplayType = "OnScreen"
           #$Output.Text = $DisplayType
        }
#################################################################################################################################### 
        $radioGridview_SelectedIndexChanged={
           $Global:DisplayType = "GridView"
         
          #$Output.Text = $DisplayType
        }
####################################################################################################################################
        $radioCSV_SelectedIndexChanged={
           $Global:DisplayType = "CSV"
          #$Output.Text = $DisplayType
        }
####################################################################################################################################
	    $tabpage2_SelectedIndexChanged={
		    #TODO: Place custom script here		
[System.Windows.Forms.MessageBox]::Show("This is Error","Error Window",'OK', 'Error')
	    }
####################################################################################################################################
        $tabpage1_SelectedIndexChanged={            
        
        }
####################################################################################################################################	
	$Connect_Click={
		#TODO: Place custom script here
		#$Output.Text = $VCenterUserName.Text
        
        $Global:VC = $VCenterServerBox.Text
        #$VCuser = $VCenterUserName.Text
        #$VCpwd = $VCenterUserPassword.text

        NA-AddPSsnapin
                
        If (!$VCenterServerBox.text) { $Output.Text = "###### Please Enter VCenter Server Name in the Box ######!!!!"}
                     
        Else {
            $CheckVCenterConnection = Test-Connection -ComputerName $VCenterServerBox.text -Count 1 -ErrorAction SilentlyContinue

            If (!$CheckVCenterConnection) { $Output.Text = "VCenter Server: $VC is not accessible. Please Check Server Name!"}

            Else {
                NA-VCenterConnection -VCenterServer $Global:VC -ConnState Connect
                
            }#end Else
        }#end Else

        
        #$Test = Get-VM Catlbi01 | select *
        #$Output.text = $Test | Out-String
	
    }#End $Connect_Click
####################################################################################################################################
	
	# --End User Generated Script--
	#----------------------------------------------
	#region Generated Events
	#----------------------------------------------
	
	$Form_StateCorrection_Load=
	{
		#Correct the initial state of the form to prevent the .Net maximized form issue
		$form1.WindowState = $InitialFormWindowState
	}
	
	$Form_Cleanup_FormClosed=
	{
		#Remove all event handlers from the controls
		try
		{
			$DHCPserverBox.remove_TextChanged($DHCPserverBox_TextChanged)
            $flowlayoutControls1.remove_Paint($flowlayoutControls1_Paint)
            $VCenterServerBox.remove_TextChanged($VCenterServerBox_TextChanged)
           # $VCenterUserName.remove_TextChanged($VCenterUserName_TextChanged)
           # $VCenterUserPassword.remove_TextChanged($VCenterUserPassword_TextChanged)
           # $CheckBoxUseWindowsLogin.remove_TextChanged($CheckBoxUseWindowsLogin_CheckedChanged)
			$buttonConnect.remove_Click($buttonConnect_Click)
            $ButtonAvailableIPAddresses.remove_Click($ButtonAvailableIPAddresses_Click)
            $ButtonExclusionList.remove_Click($ButtonExclusionList_Click)
            $ButtonReservationList.remove_Click($ButtonReservationList_Click)
            $buttonVMHostInfo.remove_Click($buttonVMHostInfo_Click)
            $ButtonScopeStats.remove_Click($ButtonScopeStats_Click)
            $ButtonSelect.remove_Click($ButtonSelect_Click)
           # $ButtonScopes1.remove_Click($ButtonScopes_Click)
            $Output.remove_TextChanged($Output_TextChanged)
			$Connect.remove_Click($Connect_Click)
			$tabpage2.remove_Click($tabpage2_Click)
            $panel1.remove_Paint($panel1_Paint)
			$form1.remove_Load($form1_Load)
			$form1.remove_Load($Form_StateCorrection_Load)
			$form1.remove_FormClosed($Form_Cleanup_FormClosed)
            $comboboxScopes.remove_SelectedIndexChanged($comboboxScopes_SelectedIndexChanged)
            $radioDisplay.remove_CheckedChanged($radioDisplay_SelectedIndexChanged)
            $radioGridview.remove_CheckedChanged($radioGridview_SelectedIndexChanged)
            $radioCSV.remove_CheckedChanged($radioCSV_SelectedIndexChanged)
            #$Output.Text = "Closing Connection to DHCP Server"
            NA-Server-Connection 0
            NA-VCenterConnection -ConnState Disconnect
            NA-ClearGlobalVariables
            #Write-Host "bye bye"
            # Close VCenter connection
		}
		catch [Exception]
		{ }
	}

	$panel1_Paint=[System.Windows.Forms.PaintEventHandler]{
	#Event Argument: $_ = [System.Windows.Forms.PaintEventArgs]
		#TODO: Place custom script here
		
	}


	#endregion Generated Events

	#----------------------------------------------
	#region Generated Form Code
	#----------------------------------------------
	$form1.SuspendLayout()
	$DHCP.SuspendLayout()
	$tabpage1.SuspendLayout()
	$tabpage2.SuspendLayout()
    $flowlayoutControls1.SuspendLayout()
	#
	# form1
	#
	$form1.Controls.Add($DHCP)
    $form1.Controls.Add($Output)
    $form1.Controls.Add($flowlayoutControls1)
    $form1.AutoScaleDimensions = '6, 13'
	$form1.AutoScaleMode = 'Font'
	$form1.ClientSize = '921, 644'
	$form1.Name = 'form1'
	$form1.Text = 'Form'
	$form1.add_Load($form1_Load)
	#
	# DHCP
	#
	$DHCP.Controls.Add($tabpage1)
	$DHCP.Controls.Add($tabpage2)
	$DHCP.Location = '139, 10'
	$DHCP.Name = 'DHCP'
	$DHCP.SelectedIndex = 0
	$DHCP.Size = '754, 237'
	$DHCP.TabIndex = 0
	#
	# tabpage1
	#
	$tabpage1.Controls.Add($labelDHCPServerName)
    $tabpage1.Controls.Add($labelScopeSelected)
    $tabpage1.Controls.Add($labelCurrentScope)
    $tabpage1.Controls.Add($labelConnectedDHCPServer)
    $tabpage1.Controls.Add($labelDHCPServerStatus)
	$tabpage1.Controls.Add($DHCPserverBox)
    $tabpage1.Controls.Add($buttonConnect)
    $tabpage1.Controls.Add($ButtonScopeStats)
    $tabpage1.Controls.Add($ButtonSelect)
    $tabpage1.Controls.Add($comboboxScopes)
    $tabpage1.Controls.Add($radioDisplay)
    $tabpage1.Controls.Add($radioGridview)
    $tabpage1.Controls.Add($radioCSV)
    $tabpage1.Controls.Add($flowlayoutControls1)
    $tabpage1.Controls.Add($ButtonReservationList)
   # $tabpage1.Controls.Add($ButtonScopes1)
   # $tabpage1.Controls.Add($Output)
	$tabpage1.Location = '4, 22'
	$tabpage1.Name = 'tabpage1'
	$tabpage1.Padding = '3, 3, 3, 3'
	$tabpage1.Size = '754, 237'
	$tabpage1.TabIndex = 0
	$tabpage1.Text = 'DHCP'
	$tabpage1.UseVisualStyleBackColor = $True
	#
  	# flowlayoutpanel1
	#
	$flowlayoutControls1.Controls.Add($ButtonAvailableIPAddresses)
    $flowlayoutControls1.Controls.Add($ButtonExclusionList)
    $flowlayoutControls1.Controls.Add($ButtonReservationList)
	$flowlayoutControls1.BackColor = 'InactiveCaption'
	$flowlayoutControls1.BorderStyle = 'FixedSingle'
	$flowlayoutControls1.Location = '393, 7'
	$flowlayoutControls1.Name = 'flowlayoutpanel1'
	$flowlayoutControls1.Padding = '4, 4, 4, 4'
	$flowlayoutControls1.Size = '200, 190'
	$flowlayoutControls1.TabIndex = 0
	$flowlayoutControls1.add_Paint($flowlayoutControls1_Paint)
    #
    # labelDHCPServerName
	#
	$labelDHCPServerName.AutoSize = $True
	$labelDHCPServerName.Location = '16, 11'
	$labelDHCPServerName.Name = 'labelDHCPServerName'
	$labelDHCPServerName.Size = '102, 13'
	$labelDHCPServerName.TabIndex = 3
	$labelDHCPServerName.Text = 'DHCP Server Name'
	#
    # labelScopeSelected
    #
    $labelScopeSelected.AutoSize = $True
    $labelScopeSelected.Location = '310, 31'
    $labelScopeSelected.Name = 'ScopeSelected'
    $labelScopeSelected.Size = '102, 13'
    $labelScopeSelected.TabIndex = 12
    #$labelScopeSelected.Text = '----'
    $Global:ScopeValue = "----"
    $labelScopeSelected.Text = $Global:ScopeValue
    #
    # labelCurrentScoope
    #
	$labelCurrentScope.AutoSize = $True
    $labelCurrentScope.Location = '230, 31'
    $labelCurrentScope.Name = 'CurrentScope'
    $labelCurrentScope.Size = '102, 13'
    $labelCurrentScope.TabIndex = 13
    $labelCurrentScope.Text = 'Current Scope:'
    $labelCurrentScope.add_Click($labelCurrentScope_Click)
    #
    # labelConnectedDHCPServer
    #
    $labelConnectedDHCPServer.AutoSize = $True
    $labelConnectedDHCPServer.Location = '230, 11'
    $labelConnectedDHCPServer.Name = 'DHCPServer'
    $labelConnectedDHCPServer.Size = '102, 13'
    $labelConnectedDHCPServer.TabIndex = 13
    $labelConnectedDHCPServer.Text = 'DHCP Server:'
    $labelConnectedDHCPServer.add_Click($labelConnectedDHCPServer_Click)
    #
    # labelDHCPServerStatus
    #
    $labelDHCPServerStatus.AutoSize = $True
    $labelDHCPServerStatus.Location = '310, 11'
    $labelDHCPServerStatus.Name = 'DHCPServerStatus'
    $labelDHCPServerStatus.Size = '102, 13'
    $labelDHCPServerStatus.TabIndex = 14
    $labelDHCPServerStatus.Text = '----'
    $labelDHCPServerStatus.add_Click($labelDHCPServerStatus_Click)
    #
    # DHCPserverBox
	#
	$DHCPserverBox.Location = '20, 30'
	$DHCPserverBox.Name = 'DHCPserverBox'
	$DHCPserverBox.Size = '100, 20'
	$DHCPserverBox.TabIndex = 2
	$DHCPserverBox.add_TextChanged($DHCPserverBox_TextChanged)
	#
    # comboboxScopes


    $comboboxScopes.Location = '6, 107'
	#$combobox1.MaxDropDownItems = 20
    $comboboxScopes.Text="----"
	$comboboxScopes.Name = 'combobox1'
	$comboboxScopes.Size = '121, 21'
	$comboboxScopes.TabIndex = 1
	$comboboxScopes.add_SelectedIndexChanged($comboboxScopes_SelectedIndexChanged)
    $comboboxScopes.AllowDrop = $True
	$comboboxScopes.FormattingEnabled = $True
    #
    # $ButtonSelect
    $ButtonSelect.Location = '138, 106'
    $ButtonSelect.Name = 'ButtonSelect'
    $ButtonSelect.Size = '75, 23'
    $ButtonSelect.TabIndex = 13
    $ButtonSelect.Text = 'Select'
    $ButtonSelect.UseVisualStyleBackColor = $True
    $ButtonSelect.add_Click($ButtonSelect_Click)
    #
    # radioDisplay
	#
	$radioDisplay.Location = '6, 135'
    $radioDisplay.Checked = $True
	$radioDisplay.Name = 'Display'
	$radioDisplay.Size = '77, 24'
	$radioDisplay.TabIndex = 14
	$radioDisplay.TabStop = $True
	$radioDisplay.Text = 'OnScreen'
	$radioDisplay.UseVisualStyleBackColor = $True
	$radioDisplay.add_CheckedChanged($radioDisplay_SelectedIndexChanged)
	$form1.ResumeLayout()
    #
    # radioGridview
    #
    $radioGridview.Location = '84, 135'
    $radioGridview.Name = 'Gridview'
    $radioGridview.Size = '77, 24'
    $radioGridview.TabIndex = 15
    $radioGridview.TabStop = $True
    $radioGridview.Text = 'GridView'
    $radioGridview.UseVisualStyleBackColor = $True
    $radioGridview.add_CheckedChanged($radioGridview_SelectedIndexChanged)
    #
    # radioCSV
    #
    $radioCSV.Location = '162, 135'
    $radioCSV.Name = 'CSV'
    $radioCSV.Size = '77, 24'
    $radioCSV.TabIndex = 16
    $radioCSV.TabStop = $True
    $radioCSV.Text = 'CSV'
    $radioCSV.UseVisualStyleBackColor = $True
    $radioCSV.add_CheckedChanged($radioCSV_SelectedIndexChanged)
    #
    # ButtonAvailableIPAddresses
    #
    $ButtonAvailableIPAddresses.Location = '7, 7'
    $ButtonAvailableIPAddresses.Name = 'AvailableIPAddresses'
    $ButtonAvailableIPAddresses.Size = '126, 23'
    $ButtonAvailableIPAddresses.TabIndex = 16
    $ButtonAvailableIPAddresses.Text = "Available IPs"
    $ButtonAvailableIPAddresses.UseVisualStyleBackColor = $True
    $ButtonAvailableIPAddresses.add_Click($ButtonAvailableIPAddresses_Click)
    $flowlayoutControls1.ResumeLayout()
    #
    # ButtonExclusionList
    #
    $ButtonExclusionList.Location = '7, 36'
    $ButtonExclusionList.Name = 'ExclusionList'
    $ButtonExclusionList.Size = '126, 23'
    $ButtonExclusionList.TabIndex = 17
    $ButtonExclusionList.Text = "Exclusion List"
    $ButtonExclusionList.UseVisualStyleBackColor = $True
    $ButtonExclusionList.add_Click($ButtonExclusionList_Click)
    $flowlayoutControls1.ResumeLayout()
    #   
    # ButtonReservationList
    $ButtonReservationList.Location = '7, 66'
    $ButtonReservationList.Name = 'Reservations'
    $ButtonReservationList.Size = '126, 23'
    $ButtonReservationList.TabIndex = 18
    $ButtonReservationList.Text = "Reservations"
    $ButtonReservationList.add_Click($ButtonReservationList_Click)
    $ButtonReservationList.UseVisualStyleBackColor = $True
    $flowlayoutControls1.ResumeLayout()
    #
    #
    # VCenterServerBox
    #
    $VCenterServerBox.Location = '8, 26'
    $VCenterServerBox.Name = 'VCenterServerBox'
    $VCenterServerBox.Size = '100, 20'
    $VCenterServerBox.TabIndex = 6
    $VCenterServerBox.add_TextChanged($VCenterServerBox_TextChanged)
    #
    # VCenterUserName
    <#
    $VCenterUserName.Location = '140, 28'
    $VCenterUserName.Name = 'VCenterUserName'
    $VCenterUserName.Size = '132, 20'
    $VCenterUserName.TabIndex = 7
    $VCenterUserName.add_TextChanged($VCenterUserName_TextChanged)
    #>
    # VCenterUserPassword
    <#
    $VCenterUserPassword.Location = '278, 28'
    $VCenterUserPassword.Name = 'VCenterUserPassword'
    $VCenterUserPassword.Size = '132, 20'
    $VCenterUserPassword.TabIndex = 8
    $VCenterUserPassword.add_TextChanged($VCenterUserPassword_TextChanged)
    #>
    # CheckBoxUseWindowsLogin
    <#
    $CheckBoxUseWindowsLogin.Location = '518, 30'
    $CheckBoxUseWindowsLogin.Name = 'CheckBoxUseWindowsLogin'
    $CheckBoxUseWindowsLogin.Size = '123, 17'
    $CheckBoxUseWindowsLogin.TabIndex = 9
    $CheckBoxUseWindowsLogin.Text = 'Use Windows Login'
    $CheckBoxUseWindowsLogin.add_TextChanged($CheckBoxUseWindowsLogin_CheckedChanged)
	#>
    # buttonConnect
	#
	$buttonConnect.Location = '138, 28'
	$buttonConnect.Name = 'buttonConnect'
	$buttonConnect.Size = '75, 23'
	$buttonConnect.TabIndex = 1
	$buttonConnect.Text = 'Connect'
	$buttonConnect.UseVisualStyleBackColor = $True
	$buttonConnect.add_Click($buttonConnect_Click)
	#
	# ButtonScopeStats
    $ButtonScopeStats.Location = '138, 60'
    $ButtonScopeStats.Name = 'ButtonScopeStats'
    $ButtonScopeStats.Size = '75, 23'
    $ButtonScopeStats.TabIndex = 2
    $ButtonScopeStats.Text = 'Scope Stats'
    $ButtonScopeStats.UseVisualStyleBackColor = $True
    $ButtonScopeStats.add_Click($ButtonScopeStats_Click)
    #

    <# ButtonScopes
    $ButtonScopes1.Location = '138, 92'
    $ButtonScopes1.Name = 'ButtonScopes'
    $ButtonScopes1.Size = '75, 23'
    $ButtonScopes1.TabIndex = 4
    $ButtonScopes1.Text = 'Get-Scopes'
    $ButtonScopes1.UseVisualStyleBackColor = $True
    $ButtonScopes1.add_Click($ButtonScopes1_Click)
    #>



    
    # Output
	#
	$Output.Location = '139, 280'
	$Output.Multiline = $True
	$Output.Name = 'Output'
    $Output.ScrollBars = 'Both'
    $Output.Font = 'Consolas, 8.25pt'
    $Output.WordWrap = $False
	$Output.Size = '754, 335'
	$Output.TabIndex = 0
	$Output.add_TextChanged($Output_TextChanged)
	#
	# tabpage2
	#
	$tabpage2.Controls.Add($Connect)
    $tabpage2.Controls.Add($buttonVMHostInfo)
    $tabpage2.Controls.Add($panel1)
    $tabpage2.Controls.Add($labelVcenterServerName)
    $tabpage2.Controls.Add($VCenterServerBox)
    #$tabpage2.Controls.Add($VCenterUserName)
    #$tabpage2.Controls.Add($VCenterUserPassword)
    #$tabpage2.Controls.Add($CheckBoxUseWindowsLogin)
    $tabpage2.Controls.Add($labelVCenterUserName)
    $tabpage2.Controls.Add($labelVCenterPassword)
    
	$tabpage2.Location = '4, 22'
	$tabpage2.Name = 'tabpage2'
	$tabpage2.Padding = '3, 3, 3, 3'
	$tabpage2.Size = '754, 237'
	$tabpage2.TabIndex = 1
	$tabpage2.Text = 'VCenter'
	$tabpage2.UseVisualStyleBackColor = $True
	$tabpage2.add_Click($tabpage2_Click)
	#
    # labelDHCPServerName
	#
	$labelVcenterServerName.AutoSize = $True
	$labelVcenterServerName.Location = '8, 6'
	$labelVcenterServerName.Name = 'labelVcenterServerName'
	$labelVcenterServerName.Size = '100, 20'
	$labelVcenterServerName.TabIndex = 3
	$labelVcenterServerName.Text = 'VCenter Server:'
	#

    #
    <# labelVCenterUserName
    #
    $labelVCenterUserName.AutoSize = $True
    $labelVCenterUserName.Location = '138, 11'
    $labelVCenterUserName.Name = 'labelVCenterUserName'
    $labelVCenterUserName.Size = '99, 13'
    $labelVCenterUserName.TabIndex = 4
    $labelVCenterUserName.Text = 'Domain\Username:'
    #>
    <# labelVCenterPassword
    #
    $labelVCenterPassword.AutoSize = $True
    $labelVCenterPassword.Location = '275, 11'
    $labelVCenterPassword.Name = 'labelVCenterPassword'
    $labelVCenterPassword.Size = '56, 13'
    $labelVCenterPassword.TabIndex = 5
    $labelVCenterPassword.Text = 'Password:'
    #>
    
	# Connect
	#
	$Connect.Location = '122, 30'
	$Connect.Name = 'Connect'
	$Connect.Size = '75, 23'
	$Connect.TabIndex = 0
	$Connect.Text = 'Connect'
	$Connect.UseVisualStyleBackColor = $True
	$Connect.add_Click($Connect_Click)
	#
    $tabpage2.ResumeLayout()
	$tabpage1.ResumeLayout()
	$DHCP.ResumeLayout()
	$form1.ResumeLayout()
	#endregion Generated Form Code
    #
    # buttonVMHostInfo
    $buttonVMHostInfo.Location = '188, 81'
    $buttonVMHostInfo.Name = 'VMHost_Info'
    $buttonVMHostInfo.Size = '75, 23'
    $buttonVMHostInfo.TabIndex = 9
    $buttonVMHostInfo.Text = 'VMHost Info'
    $buttonVMHostInfo.add_Click($buttonVMHostInfo_Click)

    #
	#----------------------------------------------
	
    # panel1
	#
	$panel1.Controls.Add($labelVcenterServerName)
    $panel1.Controls.Add($VCenterServerBox)
    $panel1.Controls.Add($VCenterUserName)
    $panel1.Controls.Add($VCenterUserPassword)
    $panel1.Controls.Add($CheckBoxUseWindowsLogin)
    $panel1.Controls.Add($labelVCenterUserName)
    $panel1.Controls.Add($labelVCenterPassword)
    $panel1.BackColor = 'LightSteelBlue'
	$panel1.Location = '6, 6'
	$panel1.Name = 'panel1'
	$panel1.Size = '198, 56'
	$panel1.TabIndex = 0
	$panel1.add_Paint($panel1_Paint)
	$tabpage2.ResumeLayout()
	$tabpage1.ResumeLayout()
	$DHCP.ResumeLayout()
	$form1.ResumeLayout()
	#endregion Generated Form Code

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

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

} #End Function Call-FirstForm4-tabs_psf

        ####################################################################################################################################
        Function NA-GetScopes {
    
                Invoke-Command -Session $Global:Session { $Get_Scope =  Get-DhcpServerv4Scope | select -ExpandProperty ScopeID} 
                $Global:Scope = Invoke-Command -Session $Global:Session { $Get_Scope }
                
                $comboboxScopes.Items.Clear()

              #  $Global:Scope = Get-Process | select -ExpandProperty ProcessName

                $Global:Scope | % { $comboboxScopes.Items.Add($_) }
                
        }

        ####################################################################################################################################
        Function NA-AddPSsnapin {
    
            $CheckPsSnapIn = Get-PSSnapin vmw* -ErrorAction SilentlyContinue
    
            If (!($CheckPsSnapIn)) { 
    
                $Output.Text = "Adding PowerCLI Snap-in - Please Wait ...."
                Add-PSSnapin vmw* 
                $CheckPsSnapIn = Get-PSSnapin vmw* -ErrorAction SilentlyContinue 

                If ($CheckPsSnapIn) {
       
                    $Output.Text = "Done!"
                }#end If
            }#end If
    
        }
        ####################################################################################################################################
        Function NA-VCconn {
            $Global:VCenterConnectionStatus = $False
            #$Output.Text = $Global:VCenterConnectionStatus
            $Output.Text = "Welcome"
        }
        ####################################################################################################################################
        Function NA-TestOutput {
            $Output.Text = "This is Working!!!"    
        }
        ####################################################################################################################################
        Function NA-VCenterConnection ($VCenterServer, $ConnState) {
    
            #If (Get-VMHost -ErrorAction SilentlyContinue) { $Output.text = "Checking Status of VCenter Connection.....!" ;$Output.text = "Already Connected to VCenter: $VCenterServer" }
    
            Switch($ConnState) {
                    Connect { $T = $DefaultVIServer | select -ExpandProperty IsConnected 
                              If ($T -eq $True) { $Output.text = "Checking Status of VCenter Connection.....!" ;$Output.text = "Already Connected to VCenter: $VCenterServer"; Break } 

                              Else {
                                $Output.text = "Connecting to VCenter ..... Please Wait!"
                                $Cred = Get-Credential -Credential (Get-WMIObject -class Win32_ComputerSystem | select -ExpandProperty username)

                                Connect-VIServer -Server $VCenterServerBox.Text -Credential $Cred 

                                $T = $DefaultVIServer | select -ExpandProperty IsConnected 

                                If ($T -eq $True) { $Output.text = "Successfully Connected to VCenter: $VCenterServer"
                                    $Global:VCenterConnectionStatus = $True } 
                        
                                Else { $Output.text = "Failed to Connect to VCenter $VCenterServer - Please Try Again!" }
                             }#end Else
                     }
         
                 Disconnect { If ($Global:VCenterConnectionStatus -eq $True) { $Global:VCenterConnectionStatus = $False ;Disconnect-VIServer -Server $Global:VC -Force -Confirm:$false} 
                              Else { Break }
                            }

            }#end Switch
    


        }#end Function
####################################################################################################################################
   Function NA-Get-DHCPinfo ($Option,$ScopeSend,$DisplayOption) {
    
        Begin { }
    
        Process {
            Switch($Option) 
            {
                   ExclusionList { $PickScope = $ScopeSend #$labelScopeSelected.Text #$comboboxScopes.Text
                                  #$Output.Text = $PickScope
                                   Invoke-Command -Session $Global:Session { Param($PickScope) $Get_Exclusion = Get-DhcpServerV4ExclusionRange -ScopeID $PickScope | sort StartRange } -ArgumentList $PickScope
                                   $Exclusion = Invoke-Command -Session $Global:Session { $Get_Exclusion } 

                                       If ($Exclusion) {
                                            
                                            Switch($DisplayOption) {
                                                "OnScreen" { $Output.Text = $Exclusion | select ScopeID,StartRange,EndRange | ft -AutoSize | Out-String  }
                                                "GridView" { $Output.Text = $Exclusion | select ScopeID,StartRange,EndRange | Out-GridView }
                                                     "CSV" { $Output.Text = "This Option is not yet Available!!!!!!!!!!"  }
                                            }#end Switch
                                       
                                       
                                       }#end If
                                   
                                       Else { $Output.Text = "#### No Exclusions Found for the Scope: $PickScope ####" }
                                 
                                 }#end ExclusionList
           
                 ReservationList { $PickScope = $ScopeSend
                                   Invoke-Command -Session $Global:Session { Param($PickScope) $Get_Reservation = Get-DhcpServerV4Reservation -ScopeID $PickScope | Sort IPAddress } -ArgumentList $PickScope
                                   $Res = Invoke-Command -Session $Global:Session { $Get_Reservation }
                                   #
                                         If ($Res) {
                                            
                                            Switch($DisplayOption) {
                                                "OnScreen" { $Output.Text = $Res | Select IPAddress,ClientID,Name,Description | Ft -AutoSize | Out-String  }
                                                "GridView" { $Output.Text = $Res | Select IPAddress,ClientID,Name,Description | Out-GridView }
                                                     "CSV" { $Output.Text = "This Option is not yet Available!!!!!!!!!!"  }
                                            }#end Switch
                                       
                                       
                                       }#end If
                                   
                                       Else { $Output.Text = "#### No Reservations Found for the Scope: $PickScope ####" }






                                  }#end ReservationList


              AddDHCPreservation { $PickScope = $ScopeSend
                                   NA-CollectDHCPReservationInfo
                               
                                   $Res_Name = $Global:SendDHCPreservationInfo[0]
                                   $Res_MAC = $Global:SendDHCPreservationInfo[1]
                                   $Res_IP = $Global:SendDHCPreservationInfo[2]
                                   $Res_Description = $Global:SendDHCPreservationInfo[3]
                               
                                   Invoke-Command -Session $Global:Session { Param($PickScope,$Res_Name,$Res_MAC,$Res_IP,$Res_Description) $ADD_Reservation = Add-DhcpServerv4Reservation -ScopeID $PickScope -IPAddress $Res_IP -ClientID $Res_MAC -Name $Res_Name -Description $Res_Description } -ArgumentList $PickScope,$Res_Name,$Res_MAC,$Res_IP,$Res_Description
                               
                                   Write-Host ""
                                   NA-Verify -VerifyCode VerifyDHCPreservation -DHCPscope $PickScope
                               
                                   NA-ClearGlobalVariables
                                   NA-RunAgain
                                 }

                                 
                      DHCPscopes { NA-Get-CurrentIPv4Scopes
                                   Invoke-Command -Session $Global:Session { Param($PickScope) $Get_Scope = Get-DhcpServerv4Scope -ScopeID $PickScope }
                                   $Global:Scope = Invoke-Command -Session $Global:Session { $Get_Scope }
                                   #Write-Host "Current Scope on DHCP Server:"
                                   $Scope | select scopeid,subnetmask,name,state,startrange,endrange,leaseduration | ft -AutoSize
                                   NA-ClearGlobalVariables
                                   NA-RunAgain
                                 } 

            AvailableIPAddresses { $PickScope = $ScopeSend
                                   Invoke-Command -Session $Global:Session { Param($PickScope) $Get_AvailableIPs = Get-DhcpServerV4FreeIPAddress -ScopeID $PickScope -NumAddress 254 } -ArgumentList $PickScope
                                   $FreeIP = Invoke-Command -Session $Global:Session { $Get_AvailableIPs }
                                   $FreeIPCount = $FreeIP.count
                                   #P
                                   
                                       If ($FreeIP) {
                                            Switch($DisplayOption) {
                                                "OnScreen" { $Output.Text = $FreeIP | ft -AutoSize | Out-String  }
                                                "GridView" { $Output.Text = $FreeIP | Out-GridView }
                                                     "CSV" { $Output.Text = "This Option is not yet Available!!!!!!!!!!"  }
                                            }#end Switch
                                       }
                                       Else { $Output.Text = "#### No Available IP Addresses Found for the Scope: $PickScope ####" }
                                                                                           
                                  } 
                    
                        DhcpLease { NA-Get-CurrentIPv4Scopes
                                    $PickScope = $Global:SendScope
                                    Invoke-Command -Session $Global:Session { Param($PickScope) $Get_dhcpLease = Get-DhcpserverV4Lease -ScopeID $PickScope } -ArgumentList $PickScope
                                    $DhcpLease = Invoke-Command -Session $Global:Session { $Get_dhcpLease }
                                    $DhcpLease | Select IPAddress,ScopeID,ClientID,Hostname,AddressState, LeaseExpiryTime | Ft -Wrap
                                    NA-ClearGlobalVariables
                                    NA-RunAgain
                                  }
                  DhcpScopeStats  { Invoke-Command -Session $Global:Session { $Get_dhcpScopeStats = Get-DhcpServerV4ScopeStatistics }
                                    $DhcpScopeStats = Invoke-Command -Session $Global:Session { $Get_dhcpScopeStats }
                                    $DhcpScopeStats | select ScopeID,Free,InUse,@{n="PercentageInUse";e={[Math]::Round($_.PercentageInUse,2)}},Reserved,Pending,SuperScopeName | Ft -AutoSize
                                    NA-ClearGlobalVariables
                                    NA-RunAgain
                                  }
                  DhcpServerStats { Invoke-Command -Session $Global:Session {$Get_DhcpServerStats = Get-DhcpServerV4Statistics }
                                    $DhcpServerStats = Invoke-Command -Session $Global:Session { $Get_DhcpServerStats }
                                    $DhcpServerStats | Fl
                                    NA-ClearGlobalVariables
                                    NA-RunAgain
                                  }
            
                PingDHCPexclusion { Write-Host "This option is not yet available ....!!" -ForegroundColor Red -BackgroundColor White
                                    #NA-Verify -VerifyCode VerifyDHCPreservation -DHCPscope '172.27.144.0'
                                    NA-Menu
                                  }
            
                             Test { Invoke-Command -Session $Global:Session { $Name = $env:COMPUTERNAME }
                                    $N = Invoke-Command -Session $Global:Session { $Name }     
                             }
                            test2 { $Loc = Get-Location
                                    Set-Location "H:\Documents\Scripts-Nabil\PowerShell\_Forms-Test"
                                    .\temp-form.ps1
                                    Set-Location $Loc
                                    NA-RunAgain}
                     
                       
            }#end Switch
        }#end Process
    }#end Function

##################################################################################################################  
        Function NA-Server-Connection ($SvrConn,$Server) {
            Switch($SvrConn) {
                0 { Write-Debug "Closing Connection"; Get-PSSession | Remove-PSSession 
                    Write-Host "Good Bye !" -ForegroundColor Cyan }

                1 { $Output.text = "Creating Connection to Server: $Server"   | Out-String; $Global:Session = New-PSSession -ComputerName $Server 
                    Invoke-Command -Session $Global:Session { Import-Module dhcpserver }
            
                    If (Get-Pssession) {
                        $Output.Text = "Successfully Connected to Server: $Server"   
                        $labelDHCPServerStatus.Text = $Server 
                    }#end If
          
                  }#end 1
           
            }#end Switch
        }#end Function
###################################################################################################################
        Function NA-ClearGlobalVariables {
            $Global:DisplayType = ""
            $Global:Session = ""
            $Global:Scope = ""
            $Global:VCenterConnectionStatus = ""
            $Global:VC = ""
            $VCuser = ""
            $VCpwd = ""

        }
###################################################################################################################


#Call the form
Call-FirstForm4-tabs_psf | Out-Null
