#------------------------------------------------------------------------ # Source File Information (DO NOT MODIFY) # Source ID: 8f1c8383-2116-47ba-8050-aa44cfb8d7d5 # Source File: TopProcesses.psf #------------------------------------------------------------------------ <# .NOTES -------------------------------------------------------------------------------- Code generated by: SAPIEN Technologies, Inc., PowerShell Studio 2014 v4.1.62 Generated on: 6/18/2014 3:50 PM Generated by: David Organization: SAPIEN Technologies, Inc. -------------------------------------------------------------------------------- .DESCRIPTION GUI script generated by PowerShell Studio 2014 #> #---------------------------------------------- #region Application Functions #---------------------------------------------- function OnApplicationLoad { #Note: This function runs before the form is created #TODO: Add snapins and custom code to validate the application load return $true #return true for success or false for failure } function OnApplicationExit { #Note: This function runs after the form is closed #TODO: Add custom code to clean up and unload snapins when the application exits } #endregion Application Functions #---------------------------------------------- # Generated Form Function #---------------------------------------------- function Call-TopProcesses_psf { #---------------------------------------------- #region Import the Assemblies #---------------------------------------------- [void][reflection.assembly]::Load('mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089') [void][reflection.assembly]::Load('System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089') [void][reflection.assembly]::Load('System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089') [void][reflection.assembly]::Load('System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089') [void][reflection.assembly]::Load('System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a') [void][reflection.assembly]::Load('System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089') [void][reflection.assembly]::Load('System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a') [void][reflection.assembly]::Load('System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089') [void][reflection.assembly]::Load('System.ServiceProcess, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a') #endregion Import Assemblies #---------------------------------------------- #region Generated Form Objects #---------------------------------------------- [System.Windows.Forms.Application]::EnableVisualStyles() $form1 = New-Object 'System.Windows.Forms.Form' $button1 = New-Object 'System.Windows.Forms.Button' $richTextBox1 = New-Object 'System.Windows.Forms.RichTextBox' $label1 = New-Object 'System.Windows.Forms.Label' $InitialFormWindowState = New-Object 'System.Windows.Forms.FormWindowState' #endregion Generated Form Objects #---------------------------------------------- # User Generated Script #---------------------------------------------- $Close={ $form1.Close() } $BuildReport={ $computername = Read-Host -Prompt "Please enter the computer name (Default: $env:computername)" if(($computername -eq $null) -or ($computername.Length -eq 0)) { $computername = $env:computername } #use WMI to get processes, excluding the System Idle Process $processes=Get-WmiObject Win32_process -computername $computername -filter "Name != 'System Idle Process'" #Sort by WorkingSet size in descending order and select the first 10 #These object are then piped to format-table to create a custom table #which is turned into a string at the end $data = $processes | sort WorkingSetSize -Descending | select -first 10 | Format-Table @{label="ID";Expression={$_.Handle}},Name,@{label="WS(MB)";Expression={("{0:N2}" -f ($_.WorkingSetSize/1MB))}} -autosize | Out-String #populate the RightTextBox control with $data $richTextBox1.text=$data.Trim() $form1.Text = $computername.ToUpper() } # --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 { $button1.remove_Click($Close) $form1.remove_Load($BuildReport) $form1.remove_Load($Form_StateCorrection_Load) $form1.remove_FormClosed($Form_Cleanup_FormClosed) } catch [Exception] { } } #endregion Generated Events #---------------------------------------------- #region Generated Form Code #---------------------------------------------- $form1.SuspendLayout() # # form1 # $form1.Controls.Add($button1) $form1.Controls.Add($richTextBox1) $form1.Controls.Add($label1) $form1.ClientSize = '284, 264' $form1.FormBorderStyle = 'FixedToolWindow' $form1.Name = "form1" $form1.Text = "$computername.ToUpper()" $form1.add_Load($BuildReport) # # button1 # $button1.Location = '109, 229' $button1.Name = "button1" $button1.Size = '75, 23' $button1.TabIndex = 2 $button1.Text = "Close" $button1.UseVisualStyleBackColor = $True $button1.add_Click($Close) # # richTextBox1 # $richTextBox1.BackColor = 'Window' $richTextBox1.Font = "Lucida Console, 8.25pt" $richTextBox1.Location = '12, 27' $richTextBox1.Name = "richTextBox1" $richTextBox1.ReadOnly = $True $richTextBox1.Size = '260, 186' $richTextBox1.TabIndex = 1 $richTextBox1.Text = "data" # # label1 # $label1.Location = '12, 9' $label1.Name = "label1" $label1.Size = '100, 23' $label1.TabIndex = 0 $label1.Text = "Top 10 Processes" $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 OnApplicationLoad to initialize if((OnApplicationLoad) -eq $true) { #Call the form Call-TopProcesses_psf | Out-Null #Perform cleanup OnApplicationExit }