{"id":203,"date":"2018-05-29T10:50:54","date_gmt":"2018-05-29T09:50:54","guid":{"rendered":"http:\/\/brgeek.com.br\/wordpress\/?p=203"},"modified":"2018-05-29T10:50:54","modified_gmt":"2018-05-29T09:50:54","slug":"windows-summary-with-powershell","status":"publish","type":"post","link":"http:\/\/brgeek.com.br\/wordpress\/2018\/05\/29\/windows-summary-with-powershell\/","title":{"rendered":"Windows Summary with Powershell"},"content":{"rendered":"<p><strong>Want to have a nice tool to give summary\/info gathering of your server?<\/strong><\/p>\n<p>Here we go this one was built to give a lot of information about the machine, you can combine with a list of servers also using get-content, also you can modify and format the output to HTML for example and make it nice.<\/p>\n<pre><code class=\"language-powershell\" data-line=\"\">\n# Windows-Summary.ps1\n# General Variables and Functions\n$verScript = &quot;1.6&quot;; $dateNow = Get-Date -format &quot;yyyy-MM-dd&quot;; $dateStr = $dateNow.ToString(); $verobjW2K8 = new-object -typename System.Version 6,0,6001,18000; $currNET = [environment]::version.tostring(); $currPS = ((Get-Host).version).Major;\n# Operating System details\n$hostCS = gwmi Win32_ComputerSystem; $hostOS = gwmi win32_operatingsystem; $hostHW = get-wmiobject win32_bios; $hostOSstat = $hostOS.Name.Split(&quot;|&quot;); $hostOSWinName = $hostOSstat[0]; $hostOSDir = $hostOSstat[1]; $hostOSPart = $hostOSstat[2]; $hostOSFullVersion = [System.Environment]::OSVersion.Version.tostring(); $hostOSVersionObj = New-Object -typename System.Version -argumentlist $hostOSFullVersion; \n[int]$NumRole = $hostCS.domainrole;\nswitch($NumRole)\n{\n  0 { $role = &quot;Standalone Workstation&quot; }\n  1 { $role = &quot;Member Workstation&quot; }\n  2 { $role = &quot;Standalone Server&quot; }\n  3 { $role = &quot;Member Server&quot; } \n  4 { $role = &quot;Backup Domain Controller&quot; }\n  5 { $role = &quot;Primary Domain Controller&quot; }\n} \n\n$CPUs=@((Get-WmiObject -class win32_processor));\n$countCPU=0;\nforeach ($CPU in $CPUs) { $countCPU++ }\n\n$logicalCPUs=@((Get-WmiObject -class win32_processor).NumberOfLogicalProcessors);\n$countlCPU=0;\nforeach ($lCPU in $logicalCPUs) { $countlCPU = $countlCPU + $lCPU }\n\n$coresCPUs=@((Get-WmiObject -class win32_processor).numberOfCores);\n$countCores=0;\nforeach ($core in $coresCPUs) { $countCores= $countCores + $core }\n\nif ($hostOS.OSArchitecture) { $hostOSArchitecture = $hostOS.OSArchitecture; } else { $testWin32 = [IntPtr]::size -eq 4; if ($testWin32) { $hostOSArchitecture = &quot;32-bit&quot; } else { $hostOSArchitecture = &quot;Unknown&quot; } } $hostTotalPhysGBMemory = [math]::round(($hostCS.TotalPhysicalMemory\/1GB),2); if ($hostOS.PAEEnabled) {$hostOSPAEEnabled = $hostOS.PAEEnabled } else { $hostOSPAEEnabled = &quot;False&quot; } $hostSummary = new-object psobject; \n\n$hostSummary | add-member noteproperty &quot;Computer Name&quot; $hostOS.CSName;\n$hostSummary | add-member noteproperty &quot;Cores&quot; $countCores;\n$hostSummary | add-member noteproperty &quot;Description&quot; $hostOSDescription;\n$hostSummary | add-member noteproperty &quot;Domain&quot; $hostCSDomain; \n$hostSummary | add-member noteproperty &quot;GB Memory&quot; $hostTotalPhysGBMemory;\n$hostSummary | add-member noteproperty &quot;OS Architecture&quot; $hostOSArchitecture;\n$hostSummary | add-member noteproperty &quot;OS Build&quot; $hostOS.BuildNumber;\n$hostSummary | add-member noteproperty &quot;OS Directory&quot; $hostOSDir;\n$hostSummary | add-member noteproperty &quot;OS PAE&quot; $hostOSPAEEnabled;\n$hostSummary | add-member noteproperty &quot;OS Service Pack Level&quot; $hostOS.CSDVersion;\n$hostSummary | add-member noteproperty &quot;OS Service Pack&quot; $hostOS.ServicePackMajorVersion;\n$hostSummary | add-member noteproperty &quot;OS Service Pack Minor&quot; $hostOS.ServicePackMinorVersion;\n$hostSummary | add-member noteproperty &quot;OS Sub-Type&quot; $hostOSWinName;\n$hostSummary | add-member noteproperty &quot;OS Version Revision&quot; $hostOSFullVer;\n$hostSummary | add-member noteproperty &quot;OS Version&quot; $hostOS.Version;\n$hostSummary | add-member noteproperty &quot;Last Bootup&quot; $hostOS.ConvertToDateTime($hostOS.LastBootUpTime);\n$hostSummary | add-member noteproperty &quot;Logical Processors&quot; $countlCPU;\n$hostSummary | add-member noteproperty &quot;Manufacturer&quot; $hostCS.Manufacturer;\n$hostSummary | add-member noteproperty &quot;Model&quot; $hostCS.Model;\n$hostSummary | add-member noteproperty &quot;Processors&quot; $countCPU;\n$hostSummary | add-member noteproperty &quot;Role&quot; $role; \n$hostSummary | add-member noteproperty &quot;Serial Number&quot; $hostHW.SerialNumber;\n\n&quot;== $(($hostOS).CSName) CONFIGURATION SUMMARY ==&quot;; &quot;`nGenerated on $dateStr by Windows-Summary ver $verScript&quot;; $hostSummary | fl;\n# Pagefile and Disk Resources\n&quot;`n === PAGE FILE &quot;; $PageFileUse = Get-WmiObject Win32_PageFileUsage; $PageFileUse | select Name, FileSystem, @{Name=&quot;Allocated_GB&quot;;Expression={[math]::round(($_.AllocatedBaseSize\/1000),1)}}, @{Name=&quot;Peak_GB&quot;;Expression={[math]::round(($_.PeakUsage\/1000),1)}} | fl;\n&quot;`n === STORAGE DISKS === `n&quot;; $allDrives = get-wmiobject Win32_Volume | ?{($_.filesystem -ne &quot;&quot;) -and ($_.capacity -gt 0)} | sort driveletter | select @{Name=&quot;Drive&quot;;Expression=&quot;driveLetter&quot;}, Label, FileSystem, @{Name=&quot;Free_GB&quot;;Expression={[math]::round(($_.FreeSpace\/1GB),1)}}, @{Name=&quot;%_Used&quot;;Expression={[math]::round(((($_.Capacity - $_.FreeSpace)\/$_.Capacity)*100),1)}}; $allDrives | ft -auto;\n# Readout .Net environment\n&quot;`n === NET ENVIRONMENT ===  `n&quot;; &quot;NET Framework in Use : $currNET&quot;;\n# Readout Powershell environment\n&quot;`n === POWERSHELL ENVIRONMENT ===  `n&quot;; &quot;Powershell Version: $currPS&quot;; $currPSPolicy = get-executionpolicy; &quot;Execution Policy in Effect : $currPSPolicy&quot;;\n# Membership of (local) Administrators security group\n&quot;`n === ADMINISTRATORS ===  `n&quot;; $groupAdmin = [ADSI](&quot;WinNT:\/\/.\/Administrators,group&quot;); $membersAdmin = $groupAdmin.psbase.invoke(&quot;Members&quot;); $membersAdmin | ForEach-Object {$_.GetType().InvokeMember(&quot;Name&quot;,&#039;GetProperty&#039;, $null, $_, $null) }\n# List installed Windows software\n&quot;`n === SOFTWARE INSTALLED &quot;; if (((Get-Host).version).Major -ge 2) { gwmi -class &#039;win32_Product&#039; | select Name, Version | sort-object Name | ConvertTo-HTML -fragment; } else { gwmi -class &#039;win32_Product&#039; | select Name, Version | sort-object Name | ft -auto; }\n# List all Services\n&quot;`n === SERVICES ===&quot;; if (((Get-Host).version).Major -ge 2) { gwmi win32_service | select Displayname, Name, ProcessID, StartMode, Started, State, Status, StartName | sort-object -Unique Displayname | ConvertTo-HTML -fragment; } else { gwmi win32_service | select Name, StartMode, State, Status, StartName | sort-object -Unique Name | ft -auto; }\n# Windows Scheduler Tasks\n&quot;=== SCHEDULED TASKS ===  `n&quot;; if (((Get-Host).version).Major -ge 2) { schtasks.exe \/query \/fo csv | ConvertFrom-CSV | ?{($_.taskname -notlike &#039;*Microsoft\\Windows*&#039;) -and ($_.taskname -ne &#039;TaskName&#039;)} | ConvertTo-HTML -fragment } else { schtasks.exe \/query \/fo csv | select-string &quot;^(?!.*Taskname)&quot; }\n# networking configs and stats\n&quot;`n === NETWORK ADAPTER CONFIGS &quot;; ipconfig \/all\n&quot;`n === NETWORK STATS ===  `n&quot;; netstat -se\n&quot;`n === STATIC ROUTES ===  `n&quot;; route print\n&quot;`n === OPEN LISTENING PORTS ===  `n&quot;; netstat -an\n&quot;`n === NETBIOS RESOLUTIONS &quot;; nbtstat -r\n# readout entries in hosts and lmhosts\n&quot;`n === HOST DEFINITONS ===  `n&quot;; if (((Get-Host).version).Major -ge 2) { get-content &quot;$($hostOSDir)\\system32\\drivers\\etc\\hosts&quot; | select -skip 18 ; } else { get-content &quot;$($hostOSDir)\\system32\\drivers\\etc\\hosts&quot; ; }\n&quot;`n === LMHOSTS DEFINITIONS ===  `n&quot;; if (test-path &quot;$($hostOSDir)\\system32\\drivers\\etc\\lmhosts&quot;) { get-content &quot;$($hostOSDir)\\system32\\drivers\\etc\\lmhosts&quot; ; } else { &quot;File lmhosts not used on this server.&quot;; }\n# readout windows firewall rules, exceptions\n&quot;`n === FIREWALL RULES ===  `n&quot;; if ($hostOSVersionObj -ge $verobjW2K8) { netsh advfirewall show allprofiles } else { netsh firewall show opmode }\n\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Want to have a nice tool to give summary\/info gathering of your server? Here we go this one was built to give a lot of information about the machine, you can combine with a list of servers also using get-content, also you can modify and format the output to HTML [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":148,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[22,8,12,23,6,11,21,10,20],"class_list":["post-203","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog","tag-info-gathering","tag-michael-goulart","tag-microsoft","tag-netherlands","tag-powershell","tag-script","tag-server","tag-vm-or-physical","tag-windows"],"jetpack_featured_media_url":"http:\/\/brgeek.com.br\/wordpress\/wp-content\/uploads\/2017\/09\/powershell-tips-and-tricks_w_640.png","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"http:\/\/brgeek.com.br\/wordpress\/wp-json\/wp\/v2\/posts\/203","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/brgeek.com.br\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/brgeek.com.br\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/brgeek.com.br\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/brgeek.com.br\/wordpress\/wp-json\/wp\/v2\/comments?post=203"}],"version-history":[{"count":1,"href":"http:\/\/brgeek.com.br\/wordpress\/wp-json\/wp\/v2\/posts\/203\/revisions"}],"predecessor-version":[{"id":204,"href":"http:\/\/brgeek.com.br\/wordpress\/wp-json\/wp\/v2\/posts\/203\/revisions\/204"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/brgeek.com.br\/wordpress\/wp-json\/wp\/v2\/media\/148"}],"wp:attachment":[{"href":"http:\/\/brgeek.com.br\/wordpress\/wp-json\/wp\/v2\/media?parent=203"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/brgeek.com.br\/wordpress\/wp-json\/wp\/v2\/categories?post=203"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/brgeek.com.br\/wordpress\/wp-json\/wp\/v2\/tags?post=203"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}