Objective: Develope GUI tool to prepare report View pools
Coding as mentioned below:
# Load Assemblies
[System.Reflection.Assembly]::LoadWithPartialName(“System.Windows.Forms”)
[System.Reflection.Assembly]::LoadWithPartialName(“System.Drawing”)
# Init Form
$Form = New-Object System.Windows.Forms.Form
$Form.width = 750
$Form.height = 400
$Form.Text = “View Pools Usage”
#$Image = [system.drawing.image]::FromFile(“c:\TEMP\test.jpg”)
#$Form.BackgroundImage = $Image
# Init ProgressBar
#$pbrTest = New-Object System.Windows.Forms.ProgressBar
#$pbrTest.Maximum = 100
#$pbrTest.Minimum = 0
#$pbrTest.Location = new-object System.Drawing.Size(10,10)
#$pbrTest.size = new-object System.Drawing.Size(100,50)
#$i = 0
#$Form.Controls.Add($pbrTest)
# Button
$btnConfirm1 = new-object System.Windows.Forms.Button
$btnConfirm1.Location = new-object System.Drawing.Size(120,10)
$btnConfirm1.Size = new-object System.Drawing.Size(100,30)
$btnConfirm1.Text = “January”
$Form.Controls.Add($btnConfirm1)
#Button2
$btnConfirm2 = new-object System.Windows.Forms.Button
$btnConfirm2.Location = new-object System.Drawing.Size(220,10)
$btnConfirm2.Size = new-object System.Drawing.Size(100,30)
$btnConfirm2.Text = “Febraury”
$Form.Controls.Add($btnConfirm2)
#Button3
$btnConfirm3 = new-object System.Windows.Forms.Button
$btnConfirm3.Location = new-object System.Drawing.Size(320,10)
$btnConfirm3.Size = new-object System.Drawing.Size(100,30)
$btnConfirm3.Text = “March”
$Form.Controls.Add($btnConfirm3)
#Button4
$btnConfirm4 = new-object System.Windows.Forms.Button
$btnConfirm4.Location = new-object System.Drawing.Size(420,10)
$btnConfirm4.Size = new-object System.Drawing.Size(100,30)
$btnConfirm4.Text = “APRIL”
$Form.Controls.Add($btnConfirm4)
#Button5
$btnConfirm5 = new-object System.Windows.Forms.Button
$btnConfirm5.Location = new-object System.Drawing.Size(520,10)
$btnConfirm5.Size = new-object System.Drawing.Size(100,30)
$btnConfirm5.Text = “MAY”
$Form.Controls.Add($btnConfirm5)
#Button6
$btnConfirm6 = new-object System.Windows.Forms.Button
$btnConfirm6.Location = new-object System.Drawing.Size(620,10)
$btnConfirm6.Size = new-object System.Drawing.Size(100,30)
$btnConfirm6.Text = “June”
$Form.Controls.Add($btnConfirm6)
#Label1
$label1 = New-Object System.Windows.Forms.Label
$label1.Location = new-object System.Drawing.Size(10,10)
$label1.Size = new-object System.Drawing.Size(100,50)
#$label1.Name = “label1”
#$label1.TabIndex = 1
$label1.Font = ‘Bookman Old Style, 9.75pt, style=Bold’
$label1.ForeColor
$label1.Text = “VIEW POOLS USAGE”
$Form.Controls.Add($label1)
#====================================================
# Button
$btnConfirm11 = new-object System.Windows.Forms.Button
$btnConfirm11.Location = new-object System.Drawing.Size(120,60)
$btnConfirm11.Size = new-object System.Drawing.Size(100,30)
$btnConfirm11.Text = “January”
$Form.Controls.Add($btnConfirm11)
#Button2
$btnConfirm12 = new-object System.Windows.Forms.Button
$btnConfirm12.Location = new-object System.Drawing.Size(220,60)
$btnConfirm12.Size = new-object System.Drawing.Size(100,30)
$btnConfirm12.Text = “Febraury”
$Form.Controls.Add($btnConfirm12)
#Button3
$btnConfirm13 = new-object System.Windows.Forms.Button
$btnConfirm13.Location = new-object System.Drawing.Size(320,60)
$btnConfirm13.Size = new-object System.Drawing.Size(100,30)
$btnConfirm13.Text = “March”
$Form.Controls.Add($btnConfirm13)
#Button4
$btnConfirm14 = new-object System.Windows.Forms.Button
$btnConfirm14.Location = new-object System.Drawing.Size(420,60)
$btnConfirm14.Size = new-object System.Drawing.Size(100,30)
$btnConfirm14.Text = “APRIL”
$Form.Controls.Add($btnConfirm14)
#Button5
$btnConfirm15 = new-object System.Windows.Forms.Button
$btnConfirm15.Location = new-object System.Drawing.Size(520,60)
$btnConfirm15.Size = new-object System.Drawing.Size(100,30)
$btnConfirm15.Text = “MAY”
$Form.Controls.Add($btnConfirm15)
#Button6
$btnConfirm16 = new-object System.Windows.Forms.Button
$btnConfirm16.Location = new-object System.Drawing.Size(620,60)
$btnConfirm16.Size = new-object System.Drawing.Size(100,30)
$btnConfirm16.Text = “June”
$Form.Controls.Add($btnConfirm16)
#Label1
$label1 = New-Object System.Windows.Forms.Label
$label1.Location = new-object System.Drawing.Size(10,60)
$label1.Size = new-object System.Drawing.Size(100,50)
#$label1.Name = “label1”
#$label1.TabIndex = 1
$label1.Font = ‘Bookman Old Style, 9.75pt, style=Bold’
$label1.ForeColor
$label1.Text = “VIEW POOL USERS”
$Form.Controls.Add($label1)
#====================================================
#Button
$btnConfirm111 = new-object System.Windows.Forms.Button
$btnConfirm111.Location = new-object System.Drawing.Size(280,150)
$btnConfirm111.Size = new-object System.Drawing.Size(280,100)
$btnConfirm111.Text = ” ALL VIEW POOLS POOLS USAGE SINCE JAN POOLS NEVER USED SINCE JAN ”
$btnconfirm111.Font = ‘Bookman Old Style, 9.75pt, style=Bold’
$Form.Controls.Add($btnConfirm111)
#Button2
#$btnConfirm112 = new-object System.Windows.Forms.Button
#$btnConfirm112.Location = new-object System.Drawing.Size(420,350)
#$btnConfirm112.Size = new-object System.Drawing.Size(200,50)
#$btnConfirm112.Text = “sss”
#$Form.Controls.Add($btnConfirm112)
#Button3
#$btnConfirm113 = new-object System.Windows.Forms.Button
#$btnConfirm113.Location = new-object System.Drawing.Size(420,150)
#$btnConfirm113.Size = new-object System.Drawing.Size(200,50)
#$btnConfirm113.Text = “POOLS ACCESSED SINCE JAN”
#$Form.Controls.Add($btnConfirm113)
#Button4
#$btnConfirm114 = new-object System.Windows.Forms.Button
#$btnConfirm114.Location = new-object System.Drawing.Size(280,220)
#$btnConfirm114.Size = new-object System.Drawing.Size(200,50)
#$btnConfirm114.Text = “POOLS NOT ACCESSED SINCE JAN”
#$Form.Controls.Add($btnConfirm114)
#Button5
#$btnConfirm115 = new-object System.Windows.Forms.Button
#$btnConfirm115.Location = new-object System.Drawing.Size(520,110)
#$btnConfirm115.Size = new-object System.Drawing.Size(100,30)
#$btnConfirm115.Text = “MAY”
#$Form.Controls.Add($btnConfirm115)
#Button6
#$btnConfirm116 = new-object System.Windows.Forms.Button
#$btnConfirm116.Location = new-object System.Drawing.Size(620,110)
#$btnConfirm116.Size = new-object System.Drawing.Size(100,30)
#$btnConfirm116.Text = “June”
#$Form.Controls.Add($btnConfirm116)
#Label1
$label1 = New-Object System.Windows.Forms.Label
$label1.Location = new-object System.Drawing.Size(375,110)
$label1.Size = new-object System.Drawing.Size(100,100)
#$label1.Name = “label1”
#$label1.TabIndex = 1
$label1.Font = ‘Bookman Old Style, 9.75pt, style=Bold’
$label1.ForeColor
$label1.Text = “SUMMARY”
$Form.Controls.Add($label1)
#=====================================================
$groupbox1 = New-Object System.Windows.Forms.GroupBox
$radiobutton3 = New-Object System.Windows.Forms.RadioButton
$radiobutton2 = New-Object System.Windows.Forms.RadioButton
$radiobutton1 = New-Object System.Windows.Forms.RadioButton
#$InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
$groupbox1.Controls.Add($radiobutton3)
$groupbox1.Controls.Add($radiobutton2)
$groupbox1.Controls.Add($radiobutton1)
#$groupbox1.DataBindings.DefaultDataSourceUpdateMode = [System.Windows.Forms.DataSourceUpdateMode]::OnValidation
#$groupbox1.Location = New-Object System.Drawing.Point(25,100)
$groupbox1.Name = “groupbox1”
$groupbox1.Size = New-Object System.Drawing.Size(50,710)
$groupbox1.TabIndex = 0
$groupbox1.TabStop = $False
$groupbox1.Text = “groupbox1”
$groupbox1.Location = new-object System.Drawing.Size(320,110)
$btnConfirm112.Size = new-object System.Drawing.Size(100,70)
$Form.controls.add($groubbox1)
#====================================================
# Button Click Event to Run ProgressBar
# Button Click Event to Run ProgressBar
$btnConfirm1.Add_Click({
[System.Windows.Forms.MessageBox]::Show(“The report generation started please wait…” , “Status” , 0)
get-eventreport -viewname user_events -startdate(get-date -day 01 -month 01 -year 2014 -hour 0 -minute 0 -second 0) | where-object {$_.eventtype -eq “AGENT_CONNECTED” } | sort desktopid | group-object desktopid | select Name, count | export-csv “c:\temp\reports\XXXX-JAN-USAGECOUNT.csv”
[System.Windows.Forms.MessageBox]::Show(“The report generation Completed c:\temp\reports\XXXX-JAN-USAGECOUNT.csv” , “Status” , 0)
})
$btnConfirm2.Add_Click({
[System.Windows.Forms.MessageBox]::Show(“The report generation started please wait…” , “Status” , 0)
get-eventreport -viewname user_events -startdate(get-date -day 01 -month 02 -year 2014 -hour 0 -minute 0 -second 0) | where-object {$_.eventtype -eq “AGENT_CONNECTED” } | sort desktopid | group-object desktopid | select Name, count | export-csv “c:\temp\reports\XXXX-FEB-USAGECOUNT.csv”
[System.Windows.Forms.MessageBox]::Show(“The report generation Completed c:\temp\reports\XXXX-FEB-USAGECOUNT.csv” , “Status” , 0)
})
$btnConfirm3.Add_Click({
[System.Windows.Forms.MessageBox]::Show(“The report generation started please wait…” , “Status” , 0)
get-eventreport -viewname user_events -startdate(get-date -day 01 -month 03 -year 2014 -hour 0 -minute 0 -second 0) | where-object {$_.eventtype -eq “AGENT_CONNECTED” } | sort desktopid | group-object desktopid | select Name, count | export-csv “c:\temp\reports\XXXX-MAR-USAGECOUT.csv”
[System.Windows.Forms.MessageBox]::Show(“The report generation Completed c:\temp\reports\XXXX-MAR-USAGECOUNT.csv” , “Status” , 0)
})
$btnConfirm4.Add_Click({
[System.Windows.Forms.MessageBox]::Show(“The report generation started please wait…” , “Status” , 0)
get-eventreport -viewname user_events -startdate(get-date -day 01 -month 04 -year 2014 -hour 0 -minute 0 -second 0) | where-object {$_.eventtype -eq “AGENT_CONNECTED” } | sort desktopid | group-object desktopid | select Name, count | export-csv “c:\temp\reports\XXXX-APR-USAGECOUNT.csv”
[System.Windows.Forms.MessageBox]::Show(“The report generation Completed c:\temp\reports\XXXX-APR-USAGECOUNT.csv” , “Status” , 0)
})
$btnConfirm5.Add_Click({
[System.Windows.Forms.MessageBox]::Show(“The report generation started please wait…” , “Status” , 0)
get-eventreport -viewname user_events -startdate(get-date -day 01 -month 05 -year 2014 -hour 0 -minute 0 -second 0) | where-object {$_.eventtype -eq “AGENT_CONNECTED” } | sort desktopid | group-object desktopid | select Name, count | export-csv “c:\temp\reports\XXXX-MAY-USAGECOUNT.csv”
[System.Windows.Forms.MessageBox]::Show(“The report generation Completed c:\temp\reports\XXXX-MAY-USAGECOUNT.csv” , “Status” , 0)
})
$btnConfirm6.Add_Click({
[System.Windows.Forms.MessageBox]::Show(“Not Valid….” , “Status” , 0)
#get-eventreport -viewname user_events -startdate(get-date -day 01 -month 06 -year 2014 -hour 0 -minute 0 -second 0) | where-object {$_.eventtype -eq “AGENT_CONNECTED” } | sort desktopid | group-object desktopid | select Name, count | export-csv “c:\temp\reports\poolusageJAN.csv”
#[System.Windows.Forms.MessageBox]::Show(“The report generation Completed c:\temp\reports\poolusagejan.csv” , “Status” , 0)
})
$btnConfirm11.add_click({
[System.Windows.Forms.MessageBox]::Show(“The report generation started please wait…” , “Status” , 0)
get-eventreport -viewname user_events -startdate(get-date -day 01 -month 01 -year 2014 -hour 0 -minute 0 -second 0) | where-object {$_.eventtype -eq “AGENT_CONNECTED” } | select userdisplayname, desktopid | sort desktopid | export-csv “c:\temp\usersrep\XXXX-JAN-users.csv”
[System.Windows.Forms.MessageBox]::Show(“The report generation Completed: c:\temp\usersrep\XXXX-JAN-users.csv” , “Status” , 0)
})
$btnConfirm12.add_click({
[System.Windows.Forms.MessageBox]::Show(“The report generation started please wait…” , “Status” , 0)
get-eventreport -viewname user_events -startdate(get-date -day 01 -month 02 -year 2014 -hour 0 -minute 0 -second 0) | where-object {$_.eventtype -eq “AGENT_CONNECTED” } | select userdisplayname, desktopid | sort desktopid | export-csv “c:\temp\usersrep\XXXX-FEB-users.csv”
[System.Windows.Forms.MessageBox]::Show(“The report generation Completed c:\temp\usersrep\XXXX-FEB-users.csv” , “Status” , 0)
})
$btnConfirm13.add_click({
[System.Windows.Forms.MessageBox]::Show(“The report generation started please wait…” , “Status” , 0)
get-eventreport -viewname user_events -startdate(get-date -day 01 -month 03 -year 2014 -hour 0 -minute 0 -second 0) | where-object {$_.eventtype -eq “AGENT_CONNECTED” } | select userdisplayname, desktopid | sort desktopid | export-csv “c:\temp\usersrep\XXXX-MAR-users.csv”
[System.Windows.Forms.MessageBox]::Show(“The report generation Completed c:\temp\usersrep\XXXX-MAR-users.csv” , “Status” , 0)
})
$btnConfirm14.add_click({
[System.Windows.Forms.MessageBox]::Show(“The report generation started please wait…” , “Status” , 0)
get-eventreport -viewname user_events -startdate(get-date -day 01 -month 04 -year 2014 -hour 0 -minute 0 -second 0) | where-object {$_.eventtype -eq “AGENT_CONNECTED” } | select userdisplayname, desktopid | sort desktopid | export-csv “c:\temp\usersrep\XXXX-APR-users.csv”
[System.Windows.Forms.MessageBox]::Show(“The report generation Completed c:\temp\usersrep\XXXX-APR-users.csv” , “Status” , 0)
})
$btnConfirm15.add_click({
[System.Windows.Forms.MessageBox]::Show(“The report generation started please wait…” , “Status” , 0)
get-eventreport -viewname user_events -startdate(get-date -day 01 -month 05 -year 2014 -hour 0 -minute 0 -second 0) | where-object {$_.eventtype -eq “AGENT_CONNECTED” } | select userdisplayname, desktopid | sort desktopid | export-csv “c:\temp\usersrep\XXXX-MAY-users.csv”
[System.Windows.Forms.MessageBox]::Show(“The report generation Completed c:\temp\usersrep\XXXX-MAY-users.csv” , “Status” , 0)
})
$btnConfirm16.add_click({
[System.Windows.Forms.MessageBox]::Show(“NOT APPLICABLE…” , “Status” , 0)
#get-eventreport -viewname user_events -startdate(get-date -day 01 -month 01 -year 2014 -hour 0 -minute 0 -second 0) | where-object {$_.eventtype -eq “AGENT_CONNECTED” } | select userdisplayname, desktopid | sort desktopid | export-csv “c:\temp\usersrep\XXXX-JAN-users.csv”
#[System.Windows.Forms.MessageBox]::Show(“The report generation Completed c:\temp\reports\XXXX-JAN-USERS.csv” , “Status” , 0)
})
$btnConfirm111.add_click({
[System.Windows.Forms.MessageBox]::Show(“XXXX-VIEW POOLS AND STATUS REPORT GENERATION STARTED..PLESE BE PATIENCE IT WILL TAKE SOME TIME..” , “Status” , 0)
get-pool | select pool_id, displayname,enabled | sort enabled | export-csv “c:\temp\reports\XXXX-ALLVIEWPOOLS.csv”
[System.Windows.Forms.MessageBox]::Show(“The report generation Completed c:\temp\reports\XXXX-ALLVIEWPOOLS.csv” , “Status” , 0)
[System.Windows.Forms.MessageBox]::Show(“The YEARLY USAGE IN PROGRESS” , “Status” , 0)
$S= Get-EventReport -viewName user_events -startDate (Get-Date -Day 01 -Month 01 -Hour 0 -Minute 0 -Second 0) | where-object{$_.eventtype -eq “AGENT_CONNECTED”}
$S | group-object desktopid | select NAme, count | export-csv “c:\temp\reports\POOLUSAGE-SINCEJAN.csv”
[System.Windows.Forms.MessageBox]::Show(“The report generation Completed ” , “Status” , 0)
})
# Show Form
$Form.Add_Shown({$Form.Activate()})
$Form.ShowDialog()
Leave a Reply