{"id":2377,"date":"2015-09-17T12:20:59","date_gmt":"2015-09-17T12:20:59","guid":{"rendered":"http:\/\/truelogic.org\/wordpress\/?p=2377"},"modified":"2015-09-17T12:20:59","modified_gmt":"2015-09-17T12:20:59","slug":"capture-send-system-info-by-email-in-windows-powershell","status":"publish","type":"post","link":"https:\/\/truelogic.org\/wordpress\/2015\/09\/17\/capture-send-system-info-by-email-in-windows-powershell\/","title":{"rendered":"Capture &#038; Send System Info by Email in Windows Powershell"},"content":{"rendered":"            <script type=\"text\/javascript\" src=\"https:\/\/truelogic.org\/wordpress\/wp-content\/plugins\/wordpress-code-snippet\/scripts\/shBrushJScript.js\"><\/script>\n<p>Powershell is Microsoft&#8217;s version of shell-scripting in *nix systems. Many years back, VBScript was the only language available to automate various tasks, but it was of limited use. Then they introduced Windows Management Instrumentation (WMI) and that made scripting much more practical and powerful. Powershell continues in that direction and offers powerful features and the ability to do almost any administration or automation task in Windows.<\/p>\n<p>Below is a script which is very useful if you want to get the details of a system and send it off by email . The script works for the local system only but it can be changed to work with a remotely-accessible system . The mailing part will need the relevant mail server, \u00a0port and authentication details.<br \/>\n<pre class=\"brush: js\">function sysinfo {\r\n    $output = &quot;&quot;\r\n\t$machine = &quot;.&quot;\r\n\t$compInfo = Get-wmiobject win32_computersystem -comp $machine\r\n\t$output += &quot;COMPUTER INFO `r`n&quot;\r\n\t$output += &quot;===============`r`n&quot;\r\n\t\r\n\t$output += &quot;Name :&quot; + $compinfo.name + &quot;`r`n&quot;\r\n\t$output += &quot;Domain :&quot; + $compinfo.domain + &quot;`r`n&quot;\r\n\t$output += &quot;Model :&quot; + $compinfo.model + &quot;`r`n&quot;\r\n\t$output += &quot;RAM :&quot; + &quot;{0:n2} GB&quot; -f ($compinfo.TotalPhysicalMemory\/1gb )\r\n\t$output += &quot;`r`n&quot;\r\n\t\r\n\treturn $output\r\n}\r\n\r\nfunction biosinfo {\r\n    $output = &quot;&quot;\r\n\t$machine = &quot;.&quot;\r\n\t$output += &quot;BIOS INFO `r`n&quot;\r\n\t$output += &quot;===============`r`n&quot;\r\n\t$biosInfo = Get-wmiobject win32_bios -comp $machine\r\n\t$output += &quot;Name :&quot; + $biosinfo.Name + &quot;`r`n&quot;\r\n\t$output += &quot;Manufacturer :&quot; + $biosinfo.Manufacturer + &quot;`r`n&quot;\r\n\t$output += &quot;Serial No. :&quot; + $biosinfo.SerialNumber+ &quot;`r`n&quot;\r\n\t\r\n\treturn $output\r\n}\r\n\r\n\r\nfunction osinfo {\r\n\t$output = &quot;&quot;\r\n\t$machine = &quot;.&quot;\r\n\t$output += &quot;OS INFO `r`n&quot;\r\n\t$output += &quot;===============`r`n&quot;\r\n\t\r\n\t$osInfo = get-wmiobject win32_operatingsystem -comp $machine\r\n\t\r\n\t$output += &quot;OS Name:&quot; + $osInfo.Caption + &quot;`r`n&quot;\r\n\t$output += &quot;Service Pack:&quot; + $osInfo.ServicePackMajorVersion + &quot;`r`n&quot;\r\n\t$output += &quot;Windows Serial No.:&quot; + $osInfo.SerialNumber + &quot;`r`n&quot;\r\n\r\n\treturn $output\r\n}\r\n\r\nfunction driveInfo{\r\n    $output = &quot;&quot;\r\n\t$machine = &quot;.&quot;\r\n\t$output += &quot;DISK INFO `r`n&quot;\r\n\t$output += &quot;===============`r`n&quot;\r\n\r\n    $logicalDisk = Get-WmiObject Win32_LogicalDisk -Filter &quot;DriveType=3&quot; -ComputerName $machine\r\n\t\r\n    foreach($disk in $logicalDisk)\r\n    {\r\n        $diskObj = &quot;&quot; | Select-Object Disk,Size,FreeSpace\r\n        $diskObj.Disk = $disk.DeviceID\r\n        $diskObj.Size = &quot;{0:n0} GB&quot; -f (($disk | Measure-Object -Property Size -Sum).sum\/1gb)\r\n        $diskObj.FreeSpace = &quot;{0:n0} GB&quot; -f (($disk | Measure-Object -Property FreeSpace -Sum).sum\/1gb)\r\n\r\n        $text = &quot;{0}  {1}  Free: {2}&quot; -f $diskObj.Disk,$diskObj.size,$diskObj.Freespace\r\n        $output += $text + &quot;`r`n&quot;\r\n    }\r\n    return $output\r\n}\r\n\r\nfunction servicesInfo {\r\n\t$machine = &quot;.&quot;\r\n\t$output = &quot;&quot;\r\n\t$output += &quot;SERVICE LIST `r`n&quot;\r\n\t$output += &quot;===============`r`n&quot;\r\n\t\r\n\tforeach($srv in (get-wmiobject win32_service -computername $machine)) {\r\n\t\t$output += $srv.DisplayName + &quot; - &quot; + $srv.State + &quot;`r`n&quot;\r\n\t}\r\n\t\t\r\n\treturn $output\r\n}\r\n\r\nfunction cpuInfo {\r\n\t$machine = &quot;.&quot;\r\n\t$output = &quot;&quot;\r\n\t$output += &quot;CPU INFO LIST `r`n&quot;\r\n\t$output += &quot;===============`r`n&quot;\r\n\t\r\n\tforeach($cpu in (get-wmiobject win32_processor -computername $machine)) {\r\n\t\t$output += &quot;id:&quot; + $cpu.deviceid+ &quot;, Name:&quot; +  $cpu.name +  &quot;, Manufacturer:&quot; + $cpu.manufacturer +&quot;, Address Width:&quot; + $cpu.AddressWidth +  &quot;`r`n&quot;\r\n\t}\r\n\t\t\r\n\treturn $output\r\n}\r\n\r\n\r\n\r\n$data1 = sysinfo\r\n$data2 = biosInfo\r\n$data3 = osinfo\r\n$data4 = driveInfo\r\n$data5 = servicesInfo\r\n$data6 = cpuInfo\r\n\r\n$finaloutput = $data1 + &quot;`r`n&quot; + $data2  + &quot;`r`n&quot; +  &quot;`r`n&quot; + $data4 +  &quot;`r`n&quot;  + $data5 +  &quot;`r`n&quot; + $data6\r\n\r\nwrite-host $finaloutput\r\n\r\n$EmailTo = &quot;recipient@somedomain.com&quot;\r\n$EmailFrom = &quot;sender@somedomain.com&quot;\r\n$Subject = &quot;System Info&quot;\r\n$Body = $finaloutput \r\n$SMTPServer = &quot;mail.somedomain.com&quot; \r\n$SMTPMessage = New-Object System.Net.Mail.MailMessage($EmailFrom,$EmailTo,$Subject,$Body)\r\n$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 25) \r\n$SMTPClient.EnableSsl = $false\r\n$SMTPClient.Credentials = New-Object System.Net.NetworkCredential(&quot;sender@somedomain.com&quot;,&quot;somepassword&quot;); \r\n$SMTPClient.Send($SMTPMessage)\r\n<\/pre><\/p>\n<p>This is how the data looks when it comes in the mail:<\/p>\n<pre>COMPUTER INFO\r\n===============\r\nName :MADRID109\r\nDomain :CHANGEME\r\nModel :G31M-S2L\r\nRAM :1.99 GB\r\n\r\nBIOS INFO\r\n===============\r\nName :Award Modular BIOS v6.00PG\r\nManufacturer :Award Software International, Inc.\r\nSerial No. :\r\n\r\n\r\nDISK INFO\r\n===============\r\nC:  466 GB  Free: 75 GB\r\n\r\nSERVICE LIST\r\n===============\r\nApplication Experience Lookup Service - Running\r\nAlerter - Running\r\nApplication Layer Gateway Service - Running\r\nApplication Management - Running\r\nRemote Server Manager - Running\r\nASP.NET State Service - Stopped\r\nAT&amp;T Labs Natural Voices Text to Speech 1.4 - Stopped\r\nWindows Audio - Running\r\nBackground Intelligent Transfer Service - Running\r\nComputer Browser - Stopped\r\nIndexing Service - Running\r\nClipBook - Stopped\r\n.NET Runtime Optimization Service v2.0.50727_X86 - Stopped\r\nMicrosoft .NET Framework NGEN v4.0.30319_X86 - Stopped\r\nCOM+ System Application - Stopped\r\nCryptographic Services - Running\r\nDCOM Server Process Launcher - Running\r\nDistributed File System - Stopped\r\nDHCP Client - Running\r\nLogical Disk Manager Administrative Service - Stopped\r\nLogical Disk Manager - Running\r\nDNS Server - Running\r\nDNS Client - Running\r\nWeb Element Manager - Running\r\nError Reporting Service - Running\r\nEvent Log - Running\r\nCOM+ Event System - Running\r\nWindows Presentation Foundation Font Cache 3.0.0.0 - Stopped\r\nHelp and Support - Running\r\nHID Input Service - Running\r\nHTTP SSL - Running\r\nIntel(R) Matrix Storage Event Monitor - Running\r\nWindows CardSpace - Stopped\r\nIIS Admin Service - Running\r\nIMAPI CD-Burning COM Service - Stopped\r\nIntersite Messaging - Stopped\r\nKerberos Key Distribution Center - Stopped\r\nServer - Running\r\nWorkstation - Running\r\nLicense Logging - Stopped\r\nTCP\/IP NetBIOS Helper - Running\r\nIntel(R) Management and Security Application Local Management Service - Running\r\nMessenger - Stopped\r\nNetMeeting Remote Desktop Sharing - Stopped\r\nDistributed Transaction Coordinator - Running\r\nFTP Publishing Service - Stopped\r\nWindows Installer - Stopped\r\nMessage Queuing - Running\r\nMySQL55 - Running\r\nNetwork DDE - Stopped\r\nNetwork DDE DSDM - Stopped\r\nNet Logon - Stopped\r\nNetwork Connections - Running\r\nNet.Tcp Port Sharing Service - Stopped\r\nNetwork Location Awareness (NLA) - Running\r\nFile Replication - Stopped\r\nNT LM Security Support Provider - Running\r\nRemovable Storage - Stopped\r\nPlug and Play - Running\r\nIPSEC Services - Running\r\nMicrosoft POP3 Service - Running\r\nProtected Storage - Running\r\nRemote Access Auto Connection Manager - Stopped\r\nRemote Access Connection Manager - Running\r\nRemote Desktop Help Session Manager - Stopped\r\nRouting and Remote Access - Stopped\r\nRemote Registry - Running\r\nRemote Procedure Call (RPC) Locator - Stopped\r\nRemote Procedure Call (RPC) - Running\r\nResultant Set of Policy Provider - Stopped\r\nSpecial Administration Console Helper - Stopped\r\nSecurity Accounts Manager - Running\r\nSmart Card - Stopped\r\nTask Scheduler - Running\r\nSecondary Logon - Running\r\nSystem Event Notification - Running\r\nWindows Firewall\/Internet Connection Sharing (ICS) - Running\r\nShell Hardware Detection - Running\r\nSimple Mail Transfer Protocol (SMTP) - Running\r\nSNMP Service - Running\r\nSNMP Trap Service - Stopped\r\nPrint Spooler - Running\r\nRemote Administration Service - Running\r\nWindows Image Acquisition (WIA) - Stopped\r\nMicrosoft Software Shadow Copy Provider - Stopped\r\nPerformance Logs and Alerts - Stopped\r\nTelephony - Running\r\nTerminal Services - Running\r\nThemes - Stopped\r\nTelnet - Stopped\r\nDistributed Link Tracking Server - Stopped\r\nDistributed Link Tracking Client - Running\r\nTerminal Services Session Directory - Stopped\r\nWindows User Mode Driver Framework - Stopped\r\nIntel(R) Management and Security Application User Notification Service - Running\r\nUninterruptible Power Supply - Stopped\r\nVirtual Disk Service - Stopped\r\nVolume Shadow Copy - Stopped\r\nWindows Time - Running\r\nWorld Wide Web Publishing Service - Running\r\nWebClient - Stopped\r\nWindows Event Collector - Running\r\nWinHTTP Web Proxy Auto-Discovery Service - Stopped\r\nWindows Management Instrumentation - Running\r\nWindows Remote Management (WS-Management) - Running\r\nPortable Media Serial Number Service - Stopped\r\nWindows Management Instrumentation Driver Extensions - Stopped\r\nWMI Performance Adapter - Stopped\r\nWindows Presentation Foundation Font Cache 4.0.0.0 - Stopped\r\nWindows Search - Running\r\nAutomatic Updates - Running\r\nWireless Configuration - Running\r\nNetwork Provisioning Service - Stopped\r\n\r\nCPU INFO LIST\r\n===============\r\nid:CPU0, Name:Intel(R) Core(TM)2 Quad CPU    Q6600  @ 2.40GHz, Manufacturer:GenuineIntel, Address Width:32\r\nid:CPU1, Name:Intel(R) Core(TM)2 Quad CPU    Q6600  @ 2.40GHz, Manufacturer:GenuineIntel, Address Width:32\r\nid:CPU2, Name:Intel(R) Core(TM)2 Quad CPU    Q6600  @ 2.40GHz, Manufacturer:GenuineIntel, Address Width:32\r\nid:CPU3, Name:Intel(R) Core(TM)2 Quad CPU    Q6600  @ 2.40GHz, Manufacturer:GenuineIntel, Address Width:32\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>Powershell is Microsoft&#8217;s version of shell-scripting in *nix systems. Many years back, VBScript was the only language available to automate various tasks, but it was <a class=\"mh-excerpt-more\" href=\"https:\/\/truelogic.org\/wordpress\/2015\/09\/17\/capture-send-system-info-by-email-in-windows-powershell\/\" title=\"Capture &#038; Send System Info by Email in Windows Powershell\">[&#8230;]<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":2383,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[309,15],"tags":[],"class_list":["post-2377","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powershell","category-windows"],"_links":{"self":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/2377","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/comments?post=2377"}],"version-history":[{"count":6,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/2377\/revisions"}],"predecessor-version":[{"id":2384,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/2377\/revisions\/2384"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/media\/2383"}],"wp:attachment":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/media?parent=2377"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/categories?post=2377"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/tags?post=2377"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}