#------------------------------------------------------------------------
# Source File Information (DO NOT MODIFY)
# Source ID: 676f8db7-35c7-452d-b353-a4b40f26243a
# Source File: Form-Template.psf
#------------------------------------------------------------------------
#region File Recovery Data (DO NOT MODIFY)
<#RecoveryData:
RAUAAB+LCAAAAAAABAC9VNtKwzAYvhd8h5Dr2oPd3AZtYXTuxtNwQ72TrP07o2lSknSzPr3p2g1x
QkHGKJSk+Q7/KQ0eIRFrkNWEaILMQlHBQ3xpezg6P0MoeJB0RTlhU8rgnuQQTYXMLxaQF4xosAuV
Bc4BpmEu3yHRSFcFhHheKQ25/Ux5KjbKrkWat4X+OrLQUxtKz3brx0JxyXQpIeRQakmYhWblktHk
BqqF+AAeLgcD0k/6V97I74E7HGHETSghzoyeh1HyRlkqDQ7HgmspmGoSNIHOpChA6qoljEst5glh
MKE58DoIA72ykOcHzg7aRb0TKWBTKq47OTGjwPWcfhnCwDU+/nDYSaqrjKNtap3YBXxqvG3bIfR6
bbxb3K0gaav5Wq8DZ3vaNNNputlsxkpBbooPaqfTfqmiXCVCMro8QgMDZ6/626UZmVN4HH0sux3r
m3gaI0k2lK/+4+X6WT8bZJ6X9l3ik26vl5ydJKdYSDi+0X7bjHzg/PxrRt9OzyrdRAUAAA==#>
#endregion

<#
    .NOTES
    --------------------------------------------------------------------------------
     Code generated by:  SAPIEN Technologies, Inc., PowerShell Studio 2017 v5.4.141
     Generated on:       8/29/2017 11:53 AM
     Generated by:       Haidey2
    --------------------------------------------------------------------------------
    .DESCRIPTION
        GUI script generated by PowerShell Studio 2017
#>


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

#endregion Application Functions

#----------------------------------------------
# Generated Form Function
#----------------------------------------------
function Show-Form-Template_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'
	$InitialFormWindowState = New-Object 'System.Windows.Forms.FormWindowState'


    $Script:Output = New-Object System.Windows.Forms.TextBox
    
    $Script:Output_Left = New-Object System.Windows.Forms.TextBox
    $Script:Output_Right = New-Object System.Windows.Forms.TextBox

    $Script:Collection_DropDownBox = New-Object System.Windows.Forms.ComboBox
    $Script:Deployment_DropDownBox = New-Object System.Windows.Forms.ComboBox
    $Script:Combobox_Tools = New-Object System.Windows.Forms.ComboBox

    $GroupBox = New-Object System.Windows.Forms.GroupBox
    $GroupBox_Info = New-Object System.Windows.Forms.GroupBox

    $Script:RadioButton_Window = New-Object System.Windows.Forms.RadioButton 
    $Script:RadioButton_GridView = New-Object System.Windows.Forms.RadioButton 
    $Script:RadioButton_CSV = New-Object System.Windows.Forms.RadioButton 
    $Button_Go = New-Object System.Windows.Forms.Button 
    $Script:TextBox_CollectionName = New-Object “System.Windows.Forms.TextBox”

    #$PanelEventLogs_Events = New-Object 'System.Windows.Forms.Panel'
    #$PanelEventLogs_Filter = New-Object 'System.Windows.Forms.Panel'


    #$Text_ELogs_ServerName = New-Object 'System.Windows.Forms.TextBox'
    #$Text_ELogs_EventID = New-Object 'System.Windows.Forms.TextBox'
    #$Text_Elogs_DaysBack = New-Object 'System.Windows.Forms.TextBox'
    
    $label_CollectionName = New-Object 'System.Windows.Forms.Label'
    $label_CollectionName_Value = New-Object 'System.Windows.Forms.Label'
    $label_DeploymentName = New-Object 'System.Windows.Forms.Label'
    $label_DeploymentName_Value = New-Object 'System.Windows.Forms.Label'
    $label_DeploymentTime = New-Object 'System.Windows.Forms.Label'
    $label_DeploymentTime_Value = New-Object 'System.Windows.Forms.Label'
    $label_DeviceCount = New-Object 'System.Windows.Forms.Label'
    $label_DeviceCount_Value = New-Object 'System.Windows.Forms.Label'

    $label_ServersResponding = New-Object 'System.Windows.Forms.Label'
    $label_ServersResponding_Value = New-Object 'System.Windows.Forms.Label'
    $label_ServersNOTResponding = New-Object 'System.Windows.Forms.Label'
    $label_ServersNOTResponding_Value = New-Object 'System.Windows.Forms.Label'
    $label_ServersPinging = New-Object 'System.Windows.Forms.Label'
    $label_ServersPinging_Value = New-Object 'System.Windows.Forms.Label'
    
    
    #$Button_ELogs_Connect = New-Object 'System.Windows.Forms.Button'	 

#    $Location = Split-Path $MyInvocation.MyCommand.Path -Parent

    $Script:ALL_Patch_Servers = @()   
    $Script:Responding = @()
    $Script:NotResponding = @()
    $Global:DeviceCollection_ServerNames1 = ""
    
    $Global:Collection_Name = ""
    $Global:Select_Tool
    $Global:Output_Type = ""
    $Global:Deployments = ""

    #endregion Generated Form Objects

	#----------------------------------------------
	# User Generated Script
	#----------------------------------------------
	
	$form1_Load={
		#TODO: Initialize Form Controls here
		
	}

    $Script:Collection_DropDownBox_SelectedIndexChanged={
                
        $Script:Output.Text = $Script:Collection_DropDownBox.Text
	    $T = Get-CMDeviceCollection -Name $Script:Collection_DropDownBox.text | select Name,MemberCount
        
        $Info = $Global:Deployments | ? { $_.applicationname -eq "$($Script:Deployment_DropDownBox.text)" -and $_.collectionname -eq "$($Script:Collection_DropDownBox.text)" } | select applicationname,collectionname,deploymenttime

        $label_DeploymentName_Value.Text = $Info.ApplicationName
        $label_DeploymentTime_Value.Text = $Info.DeploymentTime
        $label_CollectionName_Value.Text = $Script:Collection_DropDownBox.Text #$T.CollectionName

        $label_DeviceCount_Value.Text = $T.MemberCount

    }
    
    $Script:Deployment_DropDownBox_SelectedIndexChanged={
        Reset-Forms -Form_Selection 1
        Deployed-to-Collections
        $Script:Output.Text = $Script:Deployment_DropDownBox.Text
    }

    $Script:Combobox_Tools_SelectedIndexChanged= {
        $Script:Output.Text = $Script:Combobox_Tools.Text

        
    }

    $Button_Go_Click = { 
        temp 
        #SCCM-Module
       #  $Global:Collection_Name = $Script:TextBox_CollectionName.Text #$Script:TextBox_CollectionName.Text                                        
       #  $Global:Select_Tool = $Script:Combobox_Tools.Text
        
        
        #$Output.Text = "$Global:Collection_Name  --- $Global:Select_Tool  " | Out-String 
        #$Output.Text =  | Out-String
        }
  
  
##################################################################################################################  
    Function ConnectTo-SCCM {  
                    
            If(!(Get-PSDrive).Name -ne "CCX") {                                                 
                    #
                    # Press 'F5' to run this script. Running this script will load the ConfigurationManager
                    # module for Windows PowerShell and will connect to the site.
                    #
                    # This script was auto-generated at '2/18/2021 10:12:39 AM'.

                    # Uncomment the line below if running in an environment where script signing is 
                    # required.
                    #Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process

                    # Site configuration
                    $SiteCode = "CCX" # Site code 
                    $ProviderMachineName = "PNCRASCCM001.ccx.carecentrix.com" # SMS Provider machine name

                    # Customizations
                    $initParams = @{}
                    #$initParams.Add("Verbose", $true) # Uncomment this line to enable verbose logging
                    #$initParams.Add("ErrorAction", "Stop") # Uncomment this line to stop the script on any errors

                    # Do not change anything below this line

                    # Import the ConfigurationManager.psd1 module 
                    if((Get-Module ConfigurationManager) -eq $null) {
                        Import-Module "$($ENV:SMS_ADMIN_UI_PATH)\..\ConfigurationManager.psd1" @initParams 
                    }

                    # Connect to the site's drive if it is not already present
                    if((Get-PSDrive -Name $SiteCode -PSProvider CMSite -ErrorAction SilentlyContinue) -eq $null) {
                        New-PSDrive -Name $SiteCode -PSProvider CMSite -Root $ProviderMachineName @initParams
                    }

                    # Set the current location to be the site code.
                    Set-Location "$($SiteCode):\" @initParams

                    #$Script:Output.Text = "inside connectoSCCM function"
         }#endIf
     }#endFunction 
##################################################################################################################
    Function SCCM-Module {
            Write-Host "Inside SCCM function" -ForegroundColor Cyan
            If(!(Get-PSDrive).Name -eq "sccm-drive") { 
            
                Import-Module 'C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin\ConfigurationManager.psd1'
                New-PSDrive -Name SCCM-Drive -PSProvider "AdminUI.PS.Provider\CMSite" -Root "PNCRASCCM001.ccx.carecentrix.com" -Description "SCCM Site"
            }#endIf
            $Script:Output.Text | Get-PSDrive | ft -AutoSize | Out-String
            CD sccm-drive:
         }#endFunction   
##################################################################################################################    
    Function Update-Dropdown1 {
                           # $Collections += $Script:Collection_DropDownBox.text
                            $Collections = @("Collection-Servers","Ping-Collection","Check_Uptime","Test-Service","Remotely Update Policy","Software Update Status","Test-Sccm")
                            $Collections | % {  $Script:Combobox_Tools.Items.Add($_) }
                        }
##################################################################################################################
    Function Reset-Forms {
        Param($Form_Selection)

            Switch ($Form_Selection) {
                1 { $Collection_DropDownBox.Items.Clear(); $Collection_DropDownBox.Text = "--Deployed to Collections--" }
                2 {}

            }

    }
##################################################################################################################
    Function temp {
                        $Script:Output.Clear()
                        $Script:Output_Left.Clear()
                        $Script:Output_Right.Clear()
                        #$Script:Script:Output.text = $Script:Collection_DropDownBox.text | Out-String
                        
                        #$Global:Collection_Name = $Script:TextBox_CollectionName.Text #$Script:TextBox_CollectionName.Text                                        
                        $Global:Collection_Name = $Script:Collection_DropDownBox.Text
                        $Global:Select_Tool = $Script:Combobox_Tools.Text
                       
                        #$Script:Collection_DropDownBox.BackColor
                        If ($Script:RadioButton_Window.Checked -eq $true) { $Global:Output_Type = "Window" <#; $Script:Output.Text = "Window_Radio1 Checked:  $($Script:RadioButton_Window.Checked)" | Out-String #> }
                        ElseIf ($Script:RadioButton_GridView.Checked -eq $true) { $Global:Output_Type = "Gridview" <#; $Script:Output.Text = "Gridview_Radio2 Checked:  $($Script:RadioButton_GridView.Checked)" | Out-String #> }
                        ElseIf ($Script:RadioButton_CSV.Checked -eq $true) { $Global:Output_Type = "Export" <#; $Script:Output.Text = "CSV_Radio3 Checked:  $($Script:RadioButton_CSV.Checked)" | Out-String #> }
                       

                    If($Global:Collection_Name -and $Global:Select_Tool) {
                       
                       $Script:Output.Text = "CollectionName: $Global:Collection_Name ----- SelectTool: $Global:Select_Tool"
                       # If($Script:Collection_DropDownBox.text = "Tool1"){gcc}
                        Run-Tool
                        #$Script:TextBox_CollectionName.clear()
                        $Script:Collection_DropDownBox.text = "----Select Collection----"
                        #Clear-Variables
                    }#endIf
                    Else { #$T = { Write-Host "You must enter Collection Name ............!!" -ForegroundColor Red }
                            $Script:Output.SelectionColor = 'red' 
                            $Script:Output.Text = "You must select 'Tool' and enter Collection Name............!!"
                    }
                    
                    Run-Defaults
                }#endFunction     
##################################################################################################################
    Function Run-Tool {

                Switch($Global:Select_Tool) {
                       Collection-Servers { Collection-Servers; Write-Host "Tool Selected: $Global:Select_Tool" }
                          Ping-Collection { Ping_Collection }
                             Check_Uptime { Check_Uptime }
                             Test-Service { Test-Service }
                                Test-SCCM { SCCM-Module }
                 #"Remotely Update Policy" { $Script:Output.Text = Invoke-Expression $Location\Tool-Remotely-Restart-SCCMSyncCycle.ps1 | ft -AutoSize | Out-String }
                 "Remotely Update Policy" { $Script:Output.Text = Invoke-Expression $Location\Tool-Remotely-Restart-SCCMSyncCycle.ps1 | ft -AutoSize | Out-String }
                 "Software Update Status" { $Script:Output.Text = & "$Location\Tool-Get-SCCMSoftwareUpdateStatus.ps1" -Dep_ID 16778048 | ft -AutoSize | Out-String}
                }#endSwitch
                #Clear-Variables
       }#endFunction
##################################################################################################################
    Function Run-Defaults {  
                        #$Script:TextBox_CollectionName.Text = "Nabil - Test Collection"
                        $Script:RadioButton_Window.Checked = $true
                        
                       <#
                        If(!$Location) {
                            $Location = Split-Path $MyInvocation.MyCommand.Path -Parent
                        }
                        #>
                    }
##################################################################################################################
       Function xClear-Variables {
                    $Global:Collection_Name = ""
                    $Global:Select_Tool = ""
                    $Global:Output_Type = ""
                 
                    $Script:ALL_Patch_Servers = @()
                }
##################################################################################################################
     Function Display-Results {
        #Param($Global:Output_Type,$Final_Result)
        Write-Host "DisplayType: $($Global:Output_Type)"
            Switch ($Global:Output_Type){
                
                  Window { $Script:Output.Text = $Script:ALL_Patch_Servers | Out-String}
                Gridview { $Script:ALL_Patch_Servers | Out-GridView }
                  Export { $Script:ALL_Patch_Servers | Export-Csv -Path $Location\Results.csv -NoTypeInformation; ii $Location\Results.csv }
               
            }#endSwitch
    
    }
#############################################################################################################################################################
    Function Collection-Servers {
        #Param($Coll_Name)
        
                Write-Host "Collection:$Global:Collection_Name"
                $Script:ALL_Patch_Servers = @()

                ConnectTo-SCCM
                NA-Set-Stage -Select_Stage OutputStage2
                #SCCM-Module
                #CD sccm-drive:
                $Script:DeviceCollection_MemberCount = Get-CMDeviceCollection -Name $Global:Collection_Name | select Name,MemberCount
                $Script:DeviceCollection_ServerNames = Collection-Members #Get-CMCollectionMember -CollectionName $Global:Collection_Name | select Name,IsClient #| Export-Csv "E:\SCCM-Files\SCCM-Scripts\Files\$Global:Collection_Name.csv" -NoTypeInformation
                #$ServerName = $DeviceCollection_ServerNames.Name       
                #Set-Location c:
            
                #$Script:Temp = Get-CMCollectionMember -CollectionName $Global:Collection_Name #| select Name,IsClient       
                       
            $Script:DeviceCollection_ServerNames | % {
                $Obj = New-Object -TypeName PSObject
                $Obj | Add-Member -MemberType NoteProperty -Name Server -Value $_.Name
                $Obj | Add-Member -MemberType NoteProperty -Name ClientInstalled -Value $_.IsClient
                $Obj | Add-Member -MemberType NoteProperty -Name CollectionName -Value $Global:Collection_Name
                #$Obj | Add-Member -MemberType NoteProperty -Name CollectionMemberCount -Value {(Get-CMCollectionMember -Name $Global:Collection_Name).MemberCount}
    
                $Obj
                $Script:ALL_Patch_Servers += $Obj
               
            }#end%

                # $Script:Output.Text = $Script:ALL_Patch_Servers | Out-String
                Display-Results #-Final_Result $Script:ALL_Patch_Servers
                Write-Host "$Script:ALL_Patch_Servers"
             #   $Script:ALL_Patch_Servers | Export-Csv $Location\Current-Collection-Servers.csv -NoTypeInformation
            
    }#endFunction
#############################################################################################################################################################
    Function Collection-Members {
        Get-CMCollectionMember -CollectionName $Global:Collection_Name | select Name,IsClient
    
    }

#############################################################################################################################################################
    Function NA-Set-Stage {
        Param($Select_Stage)
            Switch($Select_Stage) {
                OutputStage1 { $Script:Output.Visible = $false
                               $Script:Output_Left.Visible = $True
                               $Script:Output_Right.Visible =  $True 
                               $label_ServersResponding.Visible = $True
                               $label_ServersResponding_Value.Visible = $True                                                             
                               $label_ServersNOTResponding.Visible = $True
                               $label_ServersNOTResponding_Value.Visible = $True
                               $label_ServersPinging.Visible = $True
                               $label_ServersPinging_Value.Visible = $True
                               
                               
                               #Write-Host "output-stage1" -ForegroundColor Yellow
                               }
                OutputStage2 { $Script:Output.Visible = $True
                               $label_ServersResponding.Visible = $false
                               $label_ServersResponding_Value.Visible = $false
                               $label_ServersNOTResponding.Visible = $False
                               $label_ServersNOTResponding_Value.Visible = $false
                               $Script:Output_Left.Visible = $false
                               $Script:Output_Right.Visible =  $false
                               $label_ServersPinging.Visible = $false
                               $label_ServersPinging_Value.Visible = $false
                              }
                    test     { $Script:Output.Text = "inside na set stage function"}
            }#endSwitch
       $Script:Output.Text = "outside switch inside na set stage function - param: $Select_Stage"
    
    
    
    }#endFunction
#############################################################################################################################################################

    Function Ping_Collection {
            
            $Ping_Result = @() 
            $NotResponding = @()
            $Responding = @()
                                                                             
            ConnectTo-SCCM           
            NA-Set-Stage -Select_Stage OutputStage1                                                               

            $Global:DeviceCollection_ServerNames1 = Collection-Members  -CollectionName $Global:Collection_Name | select Name #Get-CMCollectionMember
            #Set-Location c:
            
            Write-Host "Total Server Count: $($Global:DeviceCollection_ServerNames1.count)" -ForegroundColor Green
            Write-Host ""

            If($Script:Collection_DropDownBox.Text -like "-*") {
                    $Script:Collection_DropDownBox.BackColor = 'red'
            }

            Else {
                 $Script:Collection_DropDownBox.BackColor = 'white'
                ############
                  #  $Script:Output.Text = "CollectionName: $($Global:Collection_Name)  ------ hello  "
                ############
                $Global:DeviceCollection_ServerNames1.Name | % { 
                            $Server = $_
                            $label_ServersPinging_Value.Text = $Server
                            $Obj = New-Object -TypeName PSObject
                            $Count = $Global:DeviceCollection_ServerNames1.count
                            #$Script:Output.Text = "Checking: $Server ----- Servers left: $($Count--) Please Wait !!!" | Out-String

                            If (Test-Connection $Server -Count 1 -ErrorAction SilentlyContinue ) { 
                                                                                                
                                $Obj | Add-Member -MemberType NoteProperty -Name Server -Value $Server
                                $Obj | Add-Member -MemberType NoteProperty -Name Responding -Value "Yes"
                                $Ping_Result += $Obj
                                #$Responding += $Server
                                $Responding += $Obj
                               # $Script:Output.text += $Obj | Out-String
                            }#endIf
            
                            Else {                                                              
                                  $Obj | Add-Member -MemberType NoteProperty -Name Server -Value $Server
                                  $Obj | Add-Member -MemberType NoteProperty -Name Responding -Value "No!"
                                  $Ping_Result += $Obj
                                  #$NotResponding += $Server
                                  $NotResponding += $Obj
                                #  $Script:Output.text += $Obj | Out-String 
                                 }            
             
                            $label_ServersResponding_Value.Text = $Responding.Count
                            $label_ServersNOTResponding_Value.Text = $NotResponding.Count
             
                 }#end%
                            #$Script:Output.Text = $Ping_Result | ft -AutoSize | Out-String 
                            $Script:Output_Left.Text = $Responding | Out-String
                            $Script:Output_Right.Text = $NotResponding | Out-String
                        
                            $label_ServersPinging_Value.Text = "Done !"
                        

                            write-host "-------------------------------------------------------"
                            Write-host "$($Responding.count) / $($DeviceCollection_ServerNames1.count) -- Responding" -foregroundcolor Green
                            Write-host "$($NotResponding.count) / $($DeviceCollection_ServerNames1.count) -- NOT Responding" -foregroundcolor Red

            
            }#endElse
      }#endFunction
############################################################################################################################################################# 
      Function Check_Uptime {
        ConnectTo-SCCM
        NA-Set-Stage -Select_Stage OutputStage2
        $Global:DeviceCollection_ServerNames1 = Get-CMCollectionMember -CollectionName $Global:Collection_Name | select Name
        $Script:Output.Text = $Global:DeviceCollection_ServerNames1.name | % { gwmi win32_operatingsystem -ComputerName $_ -ErrorAction SilentlyContinue | select  @{n="Server";e={$_.PSComputername}},@{n="LastReboot";e={$_.Converttodatetime($_.LastBootUpTime)}}} | sort LastBootup -descending | Out-String
              
      }

#############################################################################################################################################################
      Function Deployment-List {
        Param($Deployment_History)
           # SCCM-Module
            $Global:Deployments = Get-CMDeployment | ? { $_.deploymenttime -gt ((Get-Date).AddDays(-"$Deployment_History")) }

           #$T | select ApplicationName,CollectionName,DeploymentTime,AssignmentID,SoftwareName | % {  $Deployment_DropDownBox.Items.Add($_) }
                $i = 0
                $Q = "" #@()

            $Global:Deployments.ApplicationName | % { $Script:Deployment_DropDownBox.Items.Add($_)}
            <#
                foreach ($D in $Deployments) {
                    $Q = $D.ApplicationName + "-------------------------------------------------------" + $D.CollectionName
                    
                    $Deployment_DropDownBox.Items.Add($Q) 
                    $i++
                }
            #>
            
            #$T.ApplicationName | % {  $Deployment_DropDownBox.Items.Add($_) }

      }#endFunction
#############################################################################################################################################################
    Function Deployed-to-Collections {
        $T = $Global:Deployments | ? { $_.ApplicationName -eq "$($Script:Deployment_DropDownBox.text)" } #| Select -ExpandProperty CollectionName
        $Script:Collection_DropDownBox.Items.Clear()
        $T.CollectionName | % { $Script:Collection_DropDownBox.Items.Add("$_")}

         
    }

#############################################################################################################################################################
      Function Test-Service {
        
        $Script:Output.Text = "test-service function"
        #$T = Get-Service
        #$Script:Output.Text = $T | ft -AutoSize | Out-String
      }
##################################################################################################################

##################################################################################################################
	# --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
		{
			$form1.remove_Load($form1_Load)
			$form1.remove_Load($Form_StateCorrection_Load)
			$form1.remove_FormClosed($Form_Cleanup_FormClosed)

            #$PanelEventLogs_Events.remove_Paint($PanelEventLogs_Events_Paint)
            #$PanelEventLogs_Filter.remove_Paint($PanelEventLogs_Filter_Paint)
        
            $Text_Elogs_DaysBack.remove_TextChanged($Text_Elogs_DaysBack_TextChanged)
            $Text_ELogs_ServerName.remove_TextChanged($Text_ELogs_ServerName_TextChanged)
            $Text_ELogs_EventID.remove_TextChanged($Text_ELogs_EventID_TextChanged)

            $Script:Output.remove_TextChanged($Output_TextChanged)
            $Script:Output_Left.remove_TextChanged($Script:Output_Left_TextChanged)
            $Script:Output_Right.remove_TextChanged($Script:Output_Right_TextChanged)

            $Script:Collection_DropDownBox.remove_SelectedIndexChanged($Script:Collection_DropDownBox_SelectedIndexChanged)
            $Script:Deployment_DropDownBox.remove_SelectedIndexChanged($Script:Deployment_DropDownBox_SelectedIndexChanged)
            $Script:Combobox_Tools.remove_SelectedIndexChanged($Script:Combobox_Tools_SelectedIndexChanged)
            $Script:RadioButton_Window.remove_SelectedIndexChanged($Script:RadioButton_Window_SelectedIndexChanged)
            $Script:RadioButton_GridView.remove_SelectedIndexChanged($Script:RadioButton_GridView_SelectedIndexChanged)
            $Script:RadioButton_CSV.remove_SelectedIndexChanged($Script:RadioButton_CSV_SelectedIndexChanged)
            $Button_Go.remove_Click($Button_Go_Click)
            
		}
		catch { Out-Null <# Prevent PSScriptAnalyzer warning #> }
	}


    #$PanelEventLogs_Events_Paint=[System.Windows.Forms.PaintEventHandler]{ <#Event Argument: $_ = [System.Windows.Forms.PaintEventArgs]#> }
    #$PanelEventLogs_Filter_Paint=[System.Windows.Forms.PaintEventHandler]{  }
	
    $Text_ELogs_ServerName_TextChanged={}
    $Text_Elogs_DaysBack_TextChanged={}

    #endregion Generated Events

	#----------------------------------------------
	#region Generated Form Code
	#----------------------------------------------
	#
	# form1
	#
    #$form1.Controls.Add($PanelEventLogs_Events)
    #$form1.Controls.Add($PanelEventLogs_Filter)

    $form1.Controls.Add($Script:Output)
    $form1.Controls.Add($Script:Output_Left)
    $form1.Controls.Add($Script:Output_Right)
    $form1.Controls.Add($Script:Collection_DropDownBox)
    $form1.Controls.Add($Script:Deployment_DropDownBox)
    $form1.Controls.Add($Script:Combobox_Tools)
    $form1.Controls.Add($GroupBox)
    $form1.Controls.Add($GroupBox_Info)
    $form1.controls.Add($Script:RadioButton_Window)
    $form1.controls.Add($Script:RadioButton_GridView)
    $form1.Controls.Add($Script:RadioButton_CSV)
    $form1.Controls.Add($Button_Go)
    $form1.Controls.Add($Script:TextBox_CollectionName)
    $form1.Controls.Add($label_CollectionName)
    $form1.Controls.Add($label_CollectionName_Value)
    $form1.Controls.Add($label_DeploymentName)
    $form1.controls.Add($label_DeploymentName_Value)
    $form1.Controls.Add($label_DeploymentTime)
    $form1.Controls.Add($label_DeploymentTime_Value)
    $form1.Controls.Add($label_DeviceCount)
    $form1.Controls.Add($label_DeviceCount_Value)
    $form1.Controls.Add($label_ServersResponding)
    $form1.Controls.Add($label_ServersResponding_Value)
    $form1.Controls.Add($label_ServersNOTResponding)
    $form1.Controls.Add($label_ServersNOTResponding_Value)
    $form1.Controls.Add($label_ServersPinging)
    $form1.Controls.Add($label_ServersPinging_Value)
    
    

	$form1.AutoScaleDimensions = '6, 13'
	$form1.AutoScaleMode = 'Font'
	$form1.ClientSize = '1000, 800'
	$form1.Name = 'form1'
	$form1.Text = 'Form'
	$form1.add_Load($form1_Load)
	#endregion Generated Form Code

	#----------------------------------------------
<#
    $PanelEventLogs_Events.Controls.Add($Text_ELogs_ServerName)
    $PanelEventLogs_Events.Controls.Add($Button_ELogs_Connect)
    $PanelEventLogs_Events.Controls.Add($Button_ELogs_View)
    $PanelEventLogs_Events.Controls.Add($Combobox_EventLogs_LogsList)
    $PanelEventLogs_Events.Controls.Add($VCenterUserPassword)
    $PanelEventLogs_Events.Controls.Add($CheckBoxUseWindowsLogin)
    $PanelEventLogs_Events.Controls.Add($labelVCenterUserName)
    $PanelEventLogs_Events.Controls.Add($labelVCenterPassword)
    $PanelEventLogs_Events.Controls.Add($Script:Collection_DropDownBox)
    $PanelEventLogs_Events.BackColor = '153,153,153'
	$PanelEventLogs_Events.Location = '6, 6'
	$PanelEventLogs_Events.Name = 'panelEventLogs_Events'
	$PanelEventLogs_Events.Size = '598, 56'
	$PanelEventLogs_Events.TabIndex = 0
	$PanelEventLogs_Events.add_Paint($PanelEventLogs_Events_Paint)

    $PanelEventLogs_Filter.Controls.Add($Combobox_ELogsFilter_Level)
    $PanelEventLogs_Filter.Controls.Add($Text_ELogs_EventID)
    $PanelEventLogs_Filter.Controls.Add($Text_Elogs_DaysBack)
    $PanelEventLogs_Filter.Controls.Add($label_ELogs_Level)
    $PanelEventLogs_Filter.Controls.Add($label_ELogs_EventID)
    $PanelEventLogs_Filter.Controls.Add($label_ELogs_DaysBack)
    $PanelEventLogs_Filter.BackColor = '255,255,212'
	$PanelEventLogs_Filter.Location = '6, 62'
	$PanelEventLogs_Filter.Name = 'PanelEventLogs_Filter'
	$PanelEventLogs_Filter.Size = '598, 56'
    $PanelEventLogs_Filter.BorderStyle = 'FixedSingle' 
	$PanelEventLogs_Filter.TabIndex = 0
	$PanelEventLogs_Filter.add_Paint($PanelEventLogs_Filter_Paint)
#>
    #
    # $Text_ELogs_ServerName
    <#
    $Text_ELogs_ServerName.Location = '8, 26'
    $Text_ELogs_ServerName.Name = '$Text_ELogs_ServerName'
    $Text_ELogs_ServerName.Size = '100, 20'
    $Text_ELogs_ServerName.text = "l2012"
    $Text_ELogs_ServerName.TabIndex = 6
    $Text_ELogs_ServerName.add_TextChanged($Text_ELogs_ServerName_TextChanged)
    #
    #
    # Text_ELogs_EventID
    #
    $Text_ELogs_EventID.Location = '115, 26'
    $Text_ELogs_EventID.Name = 'Text_ELogs_EventID'
    $Text_ELogs_EventID.Size = '40, 20'
    $Text_ELogs_EventID.TabIndex = 7
    $Text_ELogs_EventID.add_TextChanged($Text_ELogs_EventID_TextChanged)
    #
    # Text_Elogs_DaysBack
    #
    $Text_Elogs_DaysBack.Location = '175, 26'
    $Text_Elogs_DaysBack.Name = 'Text_Elogs_DaysBack'
    $Text_Elogs_DaysBack.Size = '40, 20'
    $Text_Elogs_DaysBack.TabIndex = 7
    $Text_Elogs_DaysBack.add_TextChanged($Text_Elogs_DaysBack_TextChanged)
    #>
  	# Output
	#
	$Script:Output.Location = '10, 250'
	$Script:Output.Multiline = $True
	$Script:Output.Name = 'Output'
	$Script:Output.ScrollBars = 'both'
	$Script:Output.Size = '965, 500'
    $Script:Output.Font = 'Consolas, 8.25pt'
    $Script:Output.WordWrap = $False
	$Script:Output.TabIndex = 5
	$Script:Output.add_TextChanged($Output_TextChanged)
    $Script:Output.Visible = $True
	#
    $Script:Output_Left.Location = '20, 250'
	$Script:Output_Left.Multiline = $True
	$Script:Output_Left.Name = 'Output_Left'
	$Script:Output_Left.ScrollBars = 'both'
	$Script:Output_Left.Size = '470, 500'
    $Script:Output_Left.Font = 'Consolas, 8.25pt'
    $Script:Output_Left.WordWrap = $False
    #$Script:Output_Left.TabIndex = 5

	$Script:Output_Left.add_TextChanged($Output_Left_TextChanged)
    #
    $Script:Output_Right.Location = '510, 250'
	$Script:Output_Right.Multiline = $True
	$Script:Output_Right.Name = 'Output_Right'
	$Script:Output_Right.ScrollBars = 'both'
	$Script:Output_Right.Size = '470, 500'
    $Script:Output_Right.Font = 'Consolas, 8.25pt'
    $Script:Output_Right.WordWrap = $False
	#$Script:Output_Right.TabIndex = 5
	$Script:Output_Right.add_TextChanged($Output_Right_TextChanged)
    #   
    # ComboboxServiceStartMode
    #
    $Script:Collection_DropDownBox.FormattingEnabled = $True
	$Script:Collection_DropDownBox.Location = '20, 80'
	$Script:Collection_DropDownBox.Name = 'Script:Collection_DropDownBox'
	$Script:Collection_DropDownBox.Size = '180, 20'
	$Script:Collection_DropDownBox.TabIndex = 2
    $Script:Collection_DropDownBox.Text = '--Deployed to Collections--'
    $Script:Collection_DropDownBox.add_SelectedIndexChanged($Script:Collection_DropDownBox_SelectedIndexChanged)
    #
    $Script:Deployment_DropDownBox.Location = '20,30'
    #$Script:Deployment_DropDownBox.Size = New-Object System.Drawing.Size(580,50) 
    $Script:Deployment_DropDownBox.Size = '500,50'
    #$Script:Deployment_DropDownBox.DropDownHeight = 200 
    $Script:Deployment_DropDownBox.text = "----Select Deployment----"
    #$Script:Deployment_DropDownBox.Visible = $false
    $Script:Deployment_DropDownBox.add_SelectedIndexChanged($Script:Deployment_DropDownBox_SelectedIndexChanged)
    # 
    #$Script:Combobox_Tools.Size = New-Object System.Drawing.Size(180,20) 
    #$Script:Combobox_Tools.DropDownHeight = 200 
    $Script:Combobox_Tools.text = "----Select Tool----!"
    $Script:Combobox_Tools.Location = '20,170'
    $Script:Combobox_Tools.Size = '180,10'
    $Script:Combobox_Tools.add_SelectedIndexChanged($Script:Combobox_Tools_SelectedIndexChanged)
    #
    $groupBox.Location = '270,70'
    $groupBox.size = ('150,90') #New-Object System.Drawing.Size(150,90) 
    $groupBox.text = "Select Output:"   
    $GroupBox.Controls.Add($Script:RadioButton_Window)
    $GroupBox.Controls.Add($Script:RadioButton_GridView)
    $GroupBox.Controls.Add($Script:RadioButton_CSV)
    #
    $GroupBox_Info.Location = '570,25'
    $GroupBox_Info.Size = '410,160'
    $GroupBox_Info.Text = "Deployment Info"
    $GroupBox_Info.Controls.Add($label_CollectionName)
    $GroupBox_Info.Controls.Add($label_CollectionName_Value)
    $GroupBox_Info.Controls.Add($label_DeploymentName)
    $GroupBox_Info.Controls.Add($label_DeploymentName_Value)
    $GroupBox_Info.Controls.Add($label_DeploymentTime)
    $GroupBox_Info.Controls.Add($label_DeploymentTime_Value)
    $GroupBox_Info.Controls.Add($label_DeviceCount)
    $GroupBox_Info.Controls.Add($label_DeviceCount_Value)
    ############
    $label_CollectionName.AutoSize = $True
    $label_CollectionName.Font = 'Microsoft Sans Serif, 9.0pt' #, style=Bold'
    #$label_CollectionName.ForeColor = 'DarkGreen'
    #$label_CollectionName.TextAlign = 'MiddleRight'
	$label_CollectionName.Location = '20,25'
	$label_CollectionName.Name = 'Collection_Name'
	$label_CollectionName.Size = '41, 13'
    #$label_CollectionName.TabIndex = 6
	$label_CollectionName.Text = 'Collection Name:'
	#$label_CollectionName.add_Click($label_CollectionName_Click)
    
    ############ Value ###############   
    $label_CollectionName_Value.AutoSize = $True
    $label_CollectionName_Value.Font = 'Microsoft Sans Serif, 8.50pt, style=Bold'
    $label_CollectionName_Value.ForeColor = 'DarkGreen'
    #$label_CollectionName_Value.TextAlign = 'MiddleRight'
	$label_CollectionName_Value.Location = '140,25'
	$label_CollectionName_Value.Name = 'Collection_Name_Value'
	$label_CollectionName_Value.Size = '41, 13'
    #$label_CollectionName_Value.TabIndex = 6
	$label_CollectionName_Value.Text = '_'
	#$label_CollectionName_Value.add_Click($label_CollectionName_Value_Click)

    ############
    $label_DeploymentName.AutoSize = $True
    $label_DeploymentName.Font = 'Microsoft Sans Serif, 8.50pt, style=Bold'
    $label_DeploymentName.ForeColor = 'DarkGreen'
    #$label_DeploymentName.TextAlign = 'MiddleRight'
	$label_DeploymentName.Location = '20,45'
	$label_DeploymentName.Name = 'Deployment_Name'
	$label_DeploymentName.Size = '41, 13'
    #$label_DeploymentName.TabIndex = 6
	$label_DeploymentName.Text = 'Deployment Name:'
	#$label_DeploymentName.add_Click($label_DeploymentName_Click)
    
    ############ Value ############
    $label_DeploymentName_Value.AutoSize = $True
    $label_DeploymentName_Value.Font = 'Microsoft Sans Serif, 8.50pt, style=Bold'
    $label_DeploymentName_Value.ForeColor = 'DarkGreen'
    #$label_DeploymentName_Value.TextAlign = 'MiddleRight'
	$label_DeploymentName_Value.Location = '140,45'
	$label_DeploymentName_Value.Name = 'Deployment_Name_Value'
	$label_DeploymentName_Value.Size = '41, 13'
    #$label_DeploymentName_Value.TabIndex = 6
	$label_DeploymentName_Value.Text = '_'
	#$label_DeploymentName_Value.add_Click($label_DeploymentName_Value_Click)      

    #############
    $label_DeploymentTime.AutoSize = $True
    $label_DeploymentTime.Font = 'Microsoft Sans Serif, 8.50pt, style=Bold'
    $label_DeploymentTime.ForeColor = 'DarkGreen'
    #$label_DeploymentTime.TextAlign = 'MiddleRight'
	$label_DeploymentTime.Location = '20,65'
	$label_DeploymentTime.Name = 'Deployment_Time'
	$label_DeploymentTime.Size = '41, 13'
    #$label_DeploymentTime.TabIndex = 6
	$label_DeploymentTime.Text = 'Deployment Time:'
	#$label_DeploymentTime.add_Click($label_CollectionName_Click)
    
    ############ Value ############
    $label_DeploymentTime_Value.AutoSize = $True
    $label_DeploymentTime_Value.Font = 'Microsoft Sans Serif, 8.50pt, style=Bold'
    $label_DeploymentTime_Value.ForeColor = 'DarkGreen'
    #$label_DeploymentTime_Value.TextAlign = 'MiddleRight'
	$label_DeploymentTime_Value.Location = '140,65'
	$label_DeploymentTime_Value.Name = 'Deployment_Time_Value'
	$label_DeploymentTime_Value.Size = '41, 13'
    #$label_DeploymentTime_Value.TabIndex = 6
	$label_DeploymentTime_Value.Text = '_'
	#$label_DeploymentTime_Value.add_Click($label_DeploymentTime_Value_Click)

    ###########
    $label_DeviceCount.AutoSize = $True
    $label_DeviceCount.Font = 'Microsoft Sans Serif, 8.50pt, style=Bold'
    $label_DeviceCount.ForeColor = 'DarkGreen'
    #$label_DeviceCount.TextAlign = 'MiddleRight'
	$label_DeviceCount.Location = '20,85'
	$label_DeviceCount.Name = 'Device_Count'
	$label_DeviceCount.Size = '41, 13'
    #$label_DeviceCount.TabIndex = 6
	$label_DeviceCount.Text = 'Device Count:'
	#$label_DeviceCount.add_Click($label_DeviceCount_Click)
    
    ############ Value ############
    $label_DeviceCount_Value.AutoSize = $True
    $label_DeviceCount_Value.Font = 'Microsoft Sans Serif, 8.50pt, style=Bold'
    $label_DeviceCount_Value.ForeColor = 'DarkGreen'
    #$label_DeviceCount_Value.TextAlign = 'MiddleRight'
	$label_DeviceCount_Value.Location = '140,85'
	$label_DeviceCount_Value.Name = 'Device_Count_Value'
	$label_DeviceCount_Value.Size = '41, 13'
    #$label_DeviceCount_Value.TabIndex = 6
	$label_DeviceCount_Value.Text = '_'
	#$label_DeviceCount_Value.add_Click($label_DeviceCount_Value_Click)
############
    $label_ServersResponding.AutoSize = $True
    $label_ServersResponding.Font = 'Microsoft Sans Serif, 8.50pt, style=Bold'
    $label_ServersResponding.ForeColor = 'DarkGreen'
    #$label_ServersResponding.TextAlign = 'MiddleRight'
	$label_ServersResponding.Location = '15,225'
	$label_ServersResponding.Name = 'Servers Responding'
	$label_ServersResponding.Size = '41, 13'
    #$label_ServersResponding.TabIndex = 6
	$label_ServersResponding.Text = 'Servers Responding: '
    $label_ServersResponding.Visible = $False
	#$label_ServersResponding.add_Click($label_ServersResponding_Click)
############
 $label_ServersResponding_Value.AutoSize = $True
    $label_ServersResponding_Value.Font = 'Microsoft Sans Serif, 8.50pt, style=Bold'
    $label_ServersResponding_Value.ForeColor = 'DarkGreen'
    #$label_ServersResponding.TextAlign = 'MiddleRight'
	$label_ServersResponding_Value.Location = '155,225'
	$label_ServersResponding_Value.Name = 'Servers Responding Vlue'
	$label_ServersResponding_Value.Size = '41, 13'
    #$label_ServersResponding_Value.TabIndex = 6
	$label_ServersResponding_Value.Text = '-'
    $label_ServersResponding_Value.Visible = $False
	#$label_ServersResponding_Value.add_Click($label_ServersResponding_Value_Click)
############
$label_ServersNOTResponding.AutoSize = $True
    $label_ServersNOTResponding.Font = 'Microsoft Sans Serif, 8.50pt, style=Bold'
    $label_ServersNOTResponding.ForeColor = 'Red'
    #$label_ServersNOTResponding.TextAlign = 'MiddleRight'
	$label_ServersNOTResponding.Location = '510,225'
	$label_ServersNOTResponding.Name = 'Servers Not Responding'
	$label_ServersNOTResponding.Size = '41, 13'
    #$label_ServersNOTResponding.TabIndex = 6
	$label_ServersNOTResponding.Text = 'Servers NOT Responding: '
    $label_ServersNOTResponding.Visible = $False
	#$label_ServersNOTResponding.add_Click($label_ServersNOTResponding_Click)
############
$label_ServersNOTResponding_Value.AutoSize = $True
    $label_ServersNOTResponding_Value.Font = 'Microsoft Sans Serif, 8.50pt, style=Bold'
    $label_ServersNOTResponding_Value.ForeColor = 'Red'
    #$label_ServersNOTResponding_Value.TextAlign = 'MiddleRight'
	$label_ServersNOTResponding_Value.Location = '670,225'
	$label_ServersNOTResponding_Value.Name = 'Servers Not Responding Value'
	$label_ServersNOTResponding_Value.Size = '41, 13'
    #$label_ServersNOTResponding_Value.TabIndex = 6
	$label_ServersNOTResponding_Value.Text = '- '
    $label_ServersNOTResponding_Value.Visible = $False
	#$label_ServersNOTResponding_Value.add_Click($label_ServersNOTResponding_Value_Click)
############
$label_ServersPinging.AutoSize = $True
    $label_ServersPinging.Font = 'Microsoft Sans Serif, 8.50pt, style=Bold'
    $label_ServersPinging.ForeColor = 'Green'
    #$label_ServersPinging.TextAlign = 'MiddleRight'
	$label_ServersPinging.Location = '15,210'
	$label_ServersPinging.Name = 'Servers Pinging'
	$label_ServersPinging.Size = '41, 13'
    #$label_ServersPinging.TabIndex = 6
	$label_ServersPinging.Text = 'Checking Servers: '
    $label_ServersPinging.Visible = $False
	#$label_ServersPinging.add_Click($label_ServersPinging_Click)
############
$label_ServersPinging_Value.AutoSize = $True
    $label_ServersPinging_Value.Font = 'Microsoft Sans Serif, 8.50pt, style=Bold'
    $label_ServersPinging_Value.ForeColor = 'Green'
    #$label_ServersPinging_Value.TextAlign = 'MiddleRight'
	$label_ServersPinging_Value.Location = '165,210'
	$label_ServersPinging_Value.Name = 'Servers Pinging Value'
	$label_ServersPinging_Value.Size = '41, 13'
    $label_ServersPinging_Value.Text = '- '
    $label_ServersPinging_Value.Visible = $False
	#$label_ServersPinging_Value.add_Click($label_ServersPinging_Value_Click)
############
    $Script:RadioButton_Window.Location = new-object System.Drawing.Point(15,15) 
    $Script:RadioButton_Window.size = New-Object System.Drawing.Size(130,20) 
    $Script:RadioButton_Window.Checked = $true 
    $Script:RadioButton_Window.Text = "Window" 
    #$Script:RadioButton_Window.
    #
    $Script:RadioButton_GridView.Location = new-object System.Drawing.Point(15,35) 
    $Script:RadioButton_GridView.size = New-Object System.Drawing.Size(80,20) 
    $Script:RadioButton_GridView.Checked = $False 
    $Script:RadioButton_GridView.Text = "GridView"
    #
    $Script:RadioButton_CSV.Location = new-object System.Drawing.Point(15,55) 
    $Script:RadioButton_CSV.size = New-Object System.Drawing.Size(80,20) 
    $Script:RadioButton_CSV.Checked = $False 
    $Script:RadioButton_CSV.Text = "CSV"
    #
    $Button_Go.Location = New-Object System.Drawing.Size(450,75) 
    $Button_Go.Size = New-Object System.Drawing.Size(110,80) 
    $Button_Go.Text = "Go" 
    #$Button_Go.Add_Click({temp}) 
    $Button_Go.Add_Click($Button_Go_Click)
    #
    $Script:TextBox_CollectionName.Left = 20;
    $Script:TextBox_CollectionName.Top = 130;
    $Script:TextBox_CollectionName.width = 200;
    $Script:TextBox_CollectionName.Text = "Nabil - Test Collection"
    #
    ############################################################################
    Update-Dropdown1
    ConnectTo-SCCM
    Deployment-List -Deployment_History 5
    $Script:Output.Text = "helloooooooo"
    #cd c:


    ############################################################################
	
#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 the form
Show-Form-Template_psf | Out-Null
