#------------------------------------------------------------------------ # Source File Information (DO NOT MODIFY) # Source ID: 1255d842-0a2b-4de7-a84f-42502a3c4acb # Source File: SystemInformation.psf #------------------------------------------------------------------------ <# .NOTES -------------------------------------------------------------------------------- Code generated by: SAPIEN Technologies, Inc., PowerShell Studio 2014 v4.1.62 Generated on: 6/18/2014 3:53 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 $script:list = Read-Host "Please enter the list file path (Default: c:\computers.txt)" if($script:list -eq $null -or $script:list.Length -eq 0) { $script:list = "c:\computers.txt" } if (!(get-item $global:list -ea "silentlycontinue").exists) { Write-Warning "Failed to find $list" #exit the script return $false } 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-SystemInformation_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' $btnRefresh = New-Object 'System.Windows.Forms.Button' $rtbPerfData = New-Object 'System.Windows.Forms.RichTextBox' $pictureBox1 = New-Object 'System.Windows.Forms.PictureBox' $lblServicePack = New-Object 'System.Windows.Forms.Label' $lblOS = New-Object 'System.Windows.Forms.Label' $statusBar1 = New-Object 'System.Windows.Forms.StatusBar' $btnClose = New-Object 'System.Windows.Forms.Button' $comboServers = New-Object 'System.Windows.Forms.ComboBox' $InitialFormWindowState = New-Object 'System.Windows.Forms.FormWindowState' #endregion Generated Form Objects #---------------------------------------------- # User Generated Script #---------------------------------------------- Function Display-OSPerf { #Displays the key OS Performance counters for a host #Author Thomas Lee - tfl@psp.co.uk Param ($computer = "localhost") #default to local host #Use WMI to get current performance data, and do conversions as needed $perf= Get-WmiObject Win32_PerfFormattedData_PerfOS_System -computer $computer #get perf $uptime=$perf.SystemUpTime/3600 # convert to hours # Now print the data, using normal .NET formatting "Performance stats for: {0}" -f $computer.toUpper() "{0,30}{1,10}" -f "Processes", $perf.Processes "{0,30}{1,10}" -f "Threads", $perf.Threads "{0,30}{1,12}" -f "System Up Time `(hours`)", $uptime.tostring("00.0") "{0,30}{1,12}" -f "Alignment Fixups/sec", $perf.AlignmentFixupsPersec.tostring("###,##0.0") "{0,30}{1,12}" -f "Context Switches/sec", $perf.ContextSwitchesPersec.tostring("###,##0.0") "{0,30}{1,12}" -f "Exception Dispatches/sec", $perf.ExceptionDispatchesPersec.tostring("###,##0.0") "{0,30}{1,12}" -f "File Control Bytes/sec", $perf.FileControlBytesPersec.tostring("###,##0.0") "{0,30}{1,12}" -f "File Control Operations/sec", $perf.FileControlOperationsPersec.tostring("###,##0.0") "{0,30}{1,12}" -f "File Data OperationsPersec", $perf.FileDataOperationsPersec.tostring("###,##0.0") "{0,30}{1,12}" -f "File Read Bytes/sec", $perf.FileReadBytesPersec.tostring("###,##0.0") "{0,30}{1,12}" -f "File Read Operations/sec", $perf.FileReadOperationsPersec.tostring("###,##0.0") "{0,30}{1,12}" -f "File Write Bytes/sec", $perf.FileWriteBytesPersec.tostring("###,##0.0") "{0,30}{1,12}" -f "File Write Operations/sec", $perf.FileWriteOperationsPersec.tostring("###,##0.0") "{0,30}{1,12}" -f "Floating Emulations/rsec", $perf.FloatingEmulationsPersec.tostring("###,##0.0") "{0,30}{1,15}" -f "Percent Registry Quota Used", $($perf.PercentRegistryQuotaInUse/100).tostring("P") "{0,30}{1,10}" -f "Processor Queue Length", $perf.ProcessorQueueLength "{0,30}{1,10}" -f "System Calls Persec", $perf.SystemCallsPersec "" } $Close={ $form1.close() } $PopulateList={ $statusBar1.text="Getting computer names from $list" Get-Content $list | foreach { $comboServers.items.add($_.Trim()) $statusBar1.Text="Ready" } } $GetData={ $statusBar1.text="Getting Operating System information for {0}" -f $comboServers.SelectedItem.toUpper() #clear values $rtbPerfData.text=$Null $lblOS.text=$Null $lblServicePack.Text=$Null $form1.Refresh() #turn off the error pipeline $errorActionPreference="SilentlyContinue" #remove any existing instances of $os if ($os) {Remove-Variable os} $os=Get-WmiObject win32_operatingsystem -computer $comboServers.SelectedItem -ea "SilentlyContinue" if ($os) { #computer exists and can be contacted $lblOS.forecolor="Black" $lblOS.text=$os.Caption $lblServicePack.Text=$os.CSDVersion $statusBar1.text="Getting Operating System Performance Data..please wait" $data=Display-OSPerf $comboServers.SelectedItem | Out-String $rtbPerfData.text=$data.Trim() $lblOS.Visible=$True $lblServicePack.visible=$True $rtbPerfData.Visible=$True $btnRefresh.Enabled=$True } else { #failed to find or connect to specified computer $lblOS.forecolor="RED" $lblOS.text="Failed to find or connect to {0}" -f $comboServers.SelectedItem.toUpper() $lblOS.Visible=$True $lblServicePack.Visible=$false } $errorActionPreference="Continue" $statusBar1.Text="Ready" } # --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 { $btnRefresh.remove_Click($GetData) $btnClose.remove_Click($Close) $comboServers.remove_SelectedIndexChanged($GetData) $form1.remove_Load($PopulateList) $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($btnRefresh) $form1.Controls.Add($rtbPerfData) $form1.Controls.Add($pictureBox1) $form1.Controls.Add($lblServicePack) $form1.Controls.Add($lblOS) $form1.Controls.Add($statusBar1) $form1.Controls.Add($btnClose) $form1.Controls.Add($comboServers) $form1.ClientSize = '390, 387' $form1.FormBorderStyle = 'FixedToolWindow' $form1.Name = "form1" $form1.Text = "System Information" $form1.add_Load($PopulateList) # # btnRefresh # $btnRefresh.Enabled = $False $btnRefresh.Location = '77, 328' $btnRefresh.Name = "btnRefresh" $btnRefresh.Size = '75, 23' $btnRefresh.TabIndex = 7 $btnRefresh.Text = "Refresh" $btnRefresh.UseVisualStyleBackColor = $True $btnRefresh.add_Click($GetData) # # rtbPerfData # $rtbPerfData.BackColor = 'Control' $rtbPerfData.BorderStyle = 'None' $rtbPerfData.Font = "Lucida Console, 8.25pt" $rtbPerfData.Location = '13, 86' $rtbPerfData.Name = "rtbPerfData" $rtbPerfData.Size = '365, 223' $rtbPerfData.TabIndex = 6 $rtbPerfData.Text = "" # # pictureBox1 # $pictureBox1.BorderStyle = 'Fixed3D' $pictureBox1.ImageLocation = "http://www.sapien.com/_images/header_sapien.gif" $pictureBox1.Location = '297, 3' $pictureBox1.Name = "pictureBox1" $pictureBox1.Size = '66, 67' $pictureBox1.TabIndex = 1 $pictureBox1.TabStop = $False # # lblServicePack # $lblServicePack.Font = "Lucida Console, 8.25pt, style=Bold" $lblServicePack.Location = '13, 60' $lblServicePack.Name = "lblServicePack" $lblServicePack.Size = '278, 23' $lblServicePack.TabIndex = 0 $lblServicePack.Text = "ServicePack" $lblServicePack.Visible = $False # # lblOS # $lblOS.Font = "Lucida Console, 8.25pt, style=Bold" $lblOS.Location = '12, 37' $lblOS.Name = "lblOS" $lblOS.Size = '278, 23' $lblOS.TabIndex = 2 $lblOS.Text = "operating system information" $lblOS.Visible = $False # # statusBar1 # $statusBar1.Location = '0, 365' $statusBar1.Name = "statusBar1" $statusBar1.Size = '390, 22' $statusBar1.TabIndex = 5 $statusBar1.Text = "statusBar1" # # btnClose # $btnClose.Location = '245, 328' $btnClose.Name = "btnClose" $btnClose.Size = '75, 23' $btnClose.TabIndex = 3 $btnClose.Text = "Close" $btnClose.UseVisualStyleBackColor = $True $btnClose.add_Click($Close) # # comboServers # $comboServers.FormattingEnabled = $True $comboServers.Location = '13, 13' $comboServers.Name = "comboServers" $comboServers.Size = '176, 21' $comboServers.TabIndex = 0 $comboServers.Text = "Select a server from the list" $comboServers.add_SelectedIndexChanged($GetData) $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-SystemInformation_psf | Out-Null #Perform cleanup OnApplicationExit }