Description

Powershell Diskspace GUI tool.

Script

PowerShell
Edit|Remove
cls 
#Generated Form Function 
function GenerateForm { 
######################################################################## 
# Code Generated By: SAPIEN Technologies PrimalForms (Community Edition) v1.0.9.0 
# Generated On: 4/29/2011 9:19 PM 
# Generated By: tparthib 
######################################################################## 
 
#region Import the Assemblies 
[reflection.assembly]::loadwithpartialname("System.Drawing"| Out-Null 
[reflection.assembly]::loadwithpartialname("System.Windows.Forms"| Out-Null 
#endregion 
 
#region Generated Form Objects 
$form1 = New-Object System.Windows.Forms.Form 
$label2 = New-Object System.Windows.Forms.Label 
$textBox3 = New-Object System.Windows.Forms.TextBox 
$textBox2 = New-Object System.Windows.Forms.TextBox 
$label4 = New-Object System.Windows.Forms.Label 
$label3 = New-Object System.Windows.Forms.Label 
$panel1 = New-Object System.Windows.Forms.Panel 
$dataGridView1 = New-Object System.Windows.Forms.DataGridView 
$textBox1 = New-Object System.Windows.Forms.TextBox 
$label1 = New-Object System.Windows.Forms.Label 
$button1 = New-Object System.Windows.Forms.Button 
$InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState 
#endregion Generated Form Objects 
 
#---------------------------------------------- 
#Generated Event Script Blocks 
#---------------------------------------------- 
#Provide Custom Code for events specified in PrimalForms. 
$handler_dataGridView1_CurrentCellChanged=  
{ 
$graphics =  $form1.createGraphics() 
 #$myBrush = new-object Drawing.SolidBrush red  
 #$graphics.FillEllipse($myBrush, 590, 80, 140, 140) 
 $rectangle = New-Object Drawing.Rectangle 590,80,140,140 
 $greenBrush = New-Object Drawing.SolidBrush Green 
 $redBrush = New-Object Drawing.SolidBrush Red 
 $pen = New-Object Drawing.Pen Black 
 #$pen.Color = "Black" 
 $pen.Width = 4  
 $currentRow = $dataGridView1.CurrentRow.Index 
 [int]$abc = $dataGridView1.rows[$currentRow].Cells[5].value 
 [int]$xyz = 100 - $abc 
 [double]$tt = $abc + $xyz 
 [double]$deg1 = ($abc/$tt* 360 
 [double]$deg2 = ($xyz/$tt* 360  
 $graphics.DrawPie($pen,$rectangle,0,$deg1) 
 $graphics.FillPie($greenBrush,$rectangle,0,$deg1) 
 $graphics.DrawPie($pen,$rectangle,$deg1,$deg2) 
 $graphics.FillPie($redBrush,$rectangle,$deg1,$deg2) 
 
} 
$handler_button1_Click=  
{ 
if ($textBox1.text -eq "") 
            { 
                [System.Windows.Forms.MessageBox]::Show("Type the Computer Name in the Text box and then Click RUN") 
            } 
        else 
            {                 
                if ( Test-Connection $textBox1.text -Quiet -Count 1) 
                { 
                $dataGridView1.ColumnCount = 0 
                $dataGridView1.RowCount=0 
                $dataGridView1.ColumnCount = 6         
                [double]$warningPercent = $textBox2.text 
                [double]$criticalPercent = $textBox3.text                 
                $dataGridView1.Columns[0].Name = "Drive" 
                $dataGridView1.Columns[1].Name = "Label" 
                $dataGridView1.Columns[2].Name = "Total(GB)" 
                $dataGridView1.Columns[3].Name = "Used(GB)" 
                $dataGridView1.Columns[4].Name = "Free(GB)" 
                $dataGridView1.Columns[5].Name = "Free(%)" 
                $disks = Get-WmiObject -Class Win32_LogicalDisk -ComputerName "localhost" | Where {$_.drivetype -eq 3}                             
                foreach($disk in $disks) 
                        { 
                            $totalSize = "{0:N2}" -f ($disk.size/1gb)                             
                            $freeSpace = "{0:N2}" -f ($disk.freespace/1gb)                             
                            $usedSize = "{0:N2}" -f ($totalSize - $freeSpace)                             
                            $freeP = ($freeSpace/$totalSize* 100 
                            $freeP = [math]::round($freeP, 2)                             
                            $dataGridView1.Rows.Add($disk.deviceid,$disk.volumename,$totalSize,$usedSize,$freeSpace,$freeP)                                                                                                             
                        }                         
                    for ($r = 0; $r -lt $disks.count; $r++)  
                    { 
                        $value = $dataGridView1.rows[$r].Cells[5].value                         
                         
                        if ($value -gt $warningPercent) 
                            {                                                     
                                $dataGridView1.Rows[$r].Cells[5].Style.BackColor = [System.Drawing.Color]::FromArgb(0,153,0)     
                            } 
                        elseif ($value -lt $criticalPercent)  
                            { 
                                $dataGridView1.Rows[$r].Cells[5].Style.BackColor = [System.Drawing.Color]::FromArgb(255, 0, 51) 
                            } 
                        else 
                            {                                                         
                                $dataGridView1.Rows[$r].Cells[5].Style.BackColor = [System.Drawing.Color]::FromArgb(255, 227, 3) 
                            }             
                    } 
                     
                } 
                else 
                { 
                    [System.Windows.Forms.MessageBox]::Show("Check Computer is UP and you have rights on the Computer.") 
                }             
                     
                     
            } 
  
} 
 
$OnLoadForm_StateCorrection= 
{#Correct the initial state of the form to prevent the .Net maximized form issue 
    $form1.WindowState = $InitialFormWindowState 
} 
 
#---------------------------------------------- 
#region Generated Form Code 
$form1.AutoScaleMode = 3 
$System_Drawing_Size = New-Object System.Drawing.Size 
$System_Drawing_Size.Height = 237 
$System_Drawing_Size.Width = 765 
$form1.ClientSize = $System_Drawing_Size 
$form1.DataBindings.DefaultDataSourceUpdateMode = 0 
$form1.MaximizeBox = $False 
$form1.Name = "form1" 
$form1.StartPosition = 1 
$form1.Text = "DiskSpace Tool                                                                          [Thiyagu14]" 
 
$label2.DataBindings.DefaultDataSourceUpdateMode = 0 
$label2.Font = New-Object System.Drawing.Font("Tahoma",9.75,5,3,1) 
 
$System_Drawing_Point = New-Object System.Drawing.Point 
$System_Drawing_Point.X = 615 
$System_Drawing_Point.Y = 55 
$label2.Location = $System_Drawing_Point 
$label2.Name = "label2" 
$System_Drawing_Size = New-Object System.Drawing.Size 
$System_Drawing_Size.Height = 23 
$System_Drawing_Size.Width = 100 
$label2.Size = $System_Drawing_Size 
$label2.TabIndex = 1 
$label2.Text = "PIE CHART" 
 
$form1.Controls.Add($label2) 
 
$textBox3.DataBindings.DefaultDataSourceUpdateMode = 0 
$textBox3.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",9.75,1,3,1) 
$System_Drawing_Point = New-Object System.Drawing.Point 
$System_Drawing_Point.X = 498 
$System_Drawing_Point.Y = 26 
$textBox3.Location = $System_Drawing_Point 
$textBox3.Name = "textBox3" 
$System_Drawing_Size = New-Object System.Drawing.Size 
$System_Drawing_Size.Height = 22 
$System_Drawing_Size.Width = 27 
$textBox3.Size = $System_Drawing_Size 
$textBox3.TabIndex = 7 
$textBox3.Text = "10" 
 
$form1.Controls.Add($textBox3) 
 
$textBox2.DataBindings.DefaultDataSourceUpdateMode = 0 
$textBox2.Font = New-Object System.Drawing.Font("Tahoma",9.75,1,3,1) 
$System_Drawing_Point = New-Object System.Drawing.Point 
$System_Drawing_Point.X = 419 
$System_Drawing_Point.Y = 26 
$textBox2.Location = $System_Drawing_Point 
$textBox2.Name = "textBox2" 
$System_Drawing_Size = New-Object System.Drawing.Size 
$System_Drawing_Size.Height = 23 
$System_Drawing_Size.Width = 28 
$textBox2.Size = $System_Drawing_Size 
$textBox2.TabIndex = 6 
$textBox2.Text = "20" 
 
$form1.Controls.Add($textBox2) 
 
$label4.BackColor = [System.Drawing.Color]::FromArgb(255,255,0,0) 
$label4.DataBindings.DefaultDataSourceUpdateMode = 0 
$label4.Font = New-Object System.Drawing.Font("Tahoma",8.25,1,3,1) 
 
$System_Drawing_Point = New-Object System.Drawing.Point 
$System_Drawing_Point.X = 483 
$System_Drawing_Point.Y = 8 
$label4.Location = $System_Drawing_Point 
$label4.Name = "label4" 
$System_Drawing_Size = New-Object System.Drawing.Size 
$System_Drawing_Size.Height = 15 
$System_Drawing_Size.Width = 78 
$label4.Size = $System_Drawing_Size 
$label4.TabIndex = 5 
$label4.Text = "CRITICAL %" 
 
$form1.Controls.Add($label4) 
 
$label3.BackColor = [System.Drawing.Color]::FromArgb(255,255,255,0) 
$label3.DataBindings.DefaultDataSourceUpdateMode = 0 
$label3.Font = New-Object System.Drawing.Font("Tahoma",8.25,1,3,1) 
 
$System_Drawing_Point = New-Object System.Drawing.Point 
$System_Drawing_Point.X = 397 
$System_Drawing_Point.Y = 8 
$label3.Location = $System_Drawing_Point 
$label3.Name = "label3" 
$System_Drawing_Size = New-Object System.Drawing.Size 
$System_Drawing_Size.Height = 15 
$System_Drawing_Size.Width = 79 
$label3.Size = $System_Drawing_Size 
$label3.TabIndex = 4 
$label3.Text = "WARNING %" 
 
$form1.Controls.Add($label3) 
 
 
$panel1.DataBindings.DefaultDataSourceUpdateMode = 0 
$System_Drawing_Point = New-Object System.Drawing.Point 
$System_Drawing_Point.X = 13 
$System_Drawing_Point.Y = 55 
$panel1.Location = $System_Drawing_Point 
$panel1.Name = "panel1" 
$System_Drawing_Size = New-Object System.Drawing.Size 
$System_Drawing_Size.Height = 178 
$System_Drawing_Size.Width = 548 
$panel1.Size = $System_Drawing_Size 
$panel1.TabIndex = 3 
 
$form1.Controls.Add($panel1$dataGridView1.AllowUserToAddRows = $False 
$dataGridView1.AutoSizeColumnsMode = 6 
$dataGridView1.AutoSizeRowsMode = 7 
$System_Windows_Forms_DataGridViewCellStyle_1 = New-Object System.Windows.Forms.DataGridViewCellStyle 
$System_Windows_Forms_DataGridViewCellStyle_1.Alignment = 16 
$System_Windows_Forms_DataGridViewCellStyle_1.BackColor = [System.Drawing.Color]::FromArgb(255,240,240,240) 
$System_Windows_Forms_DataGridViewCellStyle_1.Font = New-Object System.Drawing.Font("Tahoma",8.25,0,3,1) 
$System_Windows_Forms_DataGridViewCellStyle_1.ForeColor = [System.Drawing.Color]::FromArgb(255,0,0,0) 
$System_Windows_Forms_DataGridViewCellStyle_1.SelectionBackColor = [System.Drawing.Color]::FromArgb(255,51,153,255) 
$System_Windows_Forms_DataGridViewCellStyle_1.SelectionForeColor = [System.Drawing.Color]::FromArgb(255,255,255,255) 
$System_Windows_Forms_DataGridViewCellStyle_1.WrapMode = 1 
$dataGridView1.ColumnHeadersDefaultCellStyle = $System_Windows_Forms_DataGridViewCellStyle_1 
$dataGridView1.DataBindings.DefaultDataSourceUpdateMode = 0 
$System_Windows_Forms_DataGridViewCellStyle_2 = New-Object System.Windows.Forms.DataGridViewCellStyle 
$System_Windows_Forms_DataGridViewCellStyle_2.Alignment = 16 
$System_Windows_Forms_DataGridViewCellStyle_2.BackColor = [System.Drawing.Color]::FromArgb(255,255,255,255) 
$System_Windows_Forms_DataGridViewCellStyle_2.Font = New-Object System.Drawing.Font("Tahoma",9.75,0,3,1) 
$System_Windows_Forms_DataGridViewCellStyle_2.ForeColor = [System.Drawing.Color]::FromArgb(255,0,0,0) 
$System_Windows_Forms_DataGridViewCellStyle_2.SelectionBackColor = [System.Drawing.Color]::FromArgb(255,51,153,255) 
$System_Windows_Forms_DataGridViewCellStyle_2.SelectionForeColor = [System.Drawing.Color]::FromArgb(255,255,255,255) 
$System_Windows_Forms_DataGridViewCellStyle_2.WrapMode = 2 
$dataGridView1.DefaultCellStyle = $System_Windows_Forms_DataGridViewCellStyle_2 
$System_Drawing_Point = New-Object System.Drawing.Point 
$System_Drawing_Point.X = 4 
$System_Drawing_Point.Y = 4 
$dataGridView1.Location = $System_Drawing_Point 
$dataGridView1.Name = "dataGridView1" 
$System_Windows_Forms_DataGridViewCellStyle_3 = New-Object System.Windows.Forms.DataGridViewCellStyle 
$System_Windows_Forms_DataGridViewCellStyle_3.Alignment = 16 
$System_Windows_Forms_DataGridViewCellStyle_3.BackColor = [System.Drawing.Color]::FromArgb(255,240,240,240) 
$System_Windows_Forms_DataGridViewCellStyle_3.Font = New-Object System.Drawing.Font("Tahoma",9.75,0,3,1) 
$System_Windows_Forms_DataGridViewCellStyle_3.ForeColor = [System.Drawing.Color]::FromArgb(255,0,0,0) 
$System_Windows_Forms_DataGridViewCellStyle_3.SelectionBackColor = [System.Drawing.Color]::FromArgb(255,51,153,255) 
$System_Windows_Forms_DataGridViewCellStyle_3.SelectionForeColor = [System.Drawing.Color]::FromArgb(255,255,255,255) 
$System_Windows_Forms_DataGridViewCellStyle_3.WrapMode = 1 
$dataGridView1.RowHeadersDefaultCellStyle = $System_Windows_Forms_DataGridViewCellStyle_3 
$System_Drawing_Size = New-Object System.Drawing.Size 
$System_Drawing_Size.Height = 169 
$System_Drawing_Size.Width = 544 
$dataGridView1.Size = $System_Drawing_Size 
$dataGridView1.TabIndex = 0 
$dataGridView1.add_CurrentCellChanged($handler_dataGridView1_CurrentCellChanged$panel1.Controls.Add($dataGridView1) 
 
 
$textBox1.DataBindings.DefaultDataSourceUpdateMode = 0 
$textBox1.Font = New-Object System.Drawing.Font("Tahoma",9.75,0,3,1) 
$textBox1.ForeColor = [System.Drawing.Color]::FromArgb(255,65,105,225) 
$System_Drawing_Point = New-Object System.Drawing.Point 
$System_Drawing_Point.X = 120 
$System_Drawing_Point.Y = 13 
$textBox1.Location = $System_Drawing_Point 
$textBox1.Name = "textBox1" 
$System_Drawing_Size = New-Object System.Drawing.Size 
$System_Drawing_Size.Height = 23 
$System_Drawing_Size.Width = 100 
$textBox1.Size = $System_Drawing_Size 
$textBox1.TabIndex = 2 
 
$form1.Controls.Add($textBox1) 
 
$label1.DataBindings.DefaultDataSourceUpdateMode = 0 
$label1.Font = New-Object System.Drawing.Font("Tahoma",9.75,1,3,1) 
 
$System_Drawing_Point = New-Object System.Drawing.Point 
$System_Drawing_Point.X = 13 
$System_Drawing_Point.Y = 13 
$label1.Location = $System_Drawing_Point 
$label1.Name = "label1" 
$System_Drawing_Size = New-Object System.Drawing.Size 
$System_Drawing_Size.Height = 23 
$System_Drawing_Size.Width = 113 
$label1.Size = $System_Drawing_Size 
$label1.TabIndex = 1 
$label1.Text = "Computer Name : " 
 
$form1.Controls.Add($label1) 
 
 
$button1.DataBindings.DefaultDataSourceUpdateMode = 0 
 
$System_Drawing_Point = New-Object System.Drawing.Point 
$System_Drawing_Point.X = 678 
$System_Drawing_Point.Y = 8 
$button1.Location = $System_Drawing_Point 
$button1.Name = "button1" 
$System_Drawing_Size = New-Object System.Drawing.Size 
$System_Drawing_Size.Height = 23 
$System_Drawing_Size.Width = 75 
$button1.Size = $System_Drawing_Size 
$button1.TabIndex = 0 
$button1.Text = " RUN" 
$button1.UseVisualStyleBackColor = $True 
$button1.add_Click($handler_button1_Click) 
 
$form1.Controls.Add($button1) 
 
#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($OnLoadForm_StateCorrection#Show the Form 
$form1.ShowDialog()| Out-Null 
 
} #End Function 
 
#Call the Function 
GenerateForm