Advertisement
Cogger

Rules of Acquisition

Jul 27th, 2022
465
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ### Define Title
  2. $host.ui.RawUI.WindowTitle = "Rules of Acquisition"
  3.  
  4. # Vendor information Template
  5. $VendorLine_1 = "For support with $Vendor1 software, contact:"
  6. $VendorLine_2 = "Vendor 1"
  7. $VendorLine_3 = "vendor1@vendor1support.com"
  8. $VendorLine_4 = "vendor website information"
  9. $VendorLine_5 = "1 (800) 342 0652 "
  10.  
  11. # Stage 1 - Gathering
  12. ## Name
  13. $ServerName = "# " + $env:COMPUTERNAME
  14. $FQDN = "$env:COMPUTERNAME" + "." + "$env:USERDNSDOMAIN"
  15.  
  16. ## CPU
  17. $ServerCPU_Core  = (Get-CimInstance -Class CIM_Processor).NumberOfCores
  18. $ServerCPU_Logic = (Get-CimInstance -Class CIM_Processor).NumberOfLogicalProcessors
  19. $ServerCPU_NVM = "$ServerCPU_Core" + ", " + "$ServerCPU_Logic"
  20.  
  21. ## Drives
  22. $allDrives = [system.IO.DriveInfo]::GetDrives()
  23. foreach ($d in $allDrives)  {
  24.     "Drive {0}" -f $d.Name
  25.      "  File type: {0}" -f $d.DriveType
  26.     if ($d.IsReady)  {
  27.          "  Volume label: {0}" -f $d.VolumeLabel
  28.          "  File system: {0}"  -f $d.DriveFormat
  29.          $fs  = $d.AvailableFreeSpace/1gb
  30.          $tfs = $d.TotalFreeSpace/1gb
  31.          $TS  = $d.TotalSize/1gb
  32.          "  Available space to current user:{0, 15:n2} GiB" -f $fs
  33.          "  Total available space:          {0, 15:n2} GiB" -f $tfs
  34.          "  Total size of drive:            {0, 15:n3} GiB" -f $ts
  35.     }
  36.  
  37.         $DriveListing = "Drive {0}" -f $d.Name
  38.         $DriveSize = $TS
  39.         $DriveFree = $tfs
  40.         $DriveA = $d.TotalSize
  41.         $DriveB = $d.TotalFreeSpace
  42.         $DriveCalc1 = ($DriveB/$DriveA).tostring("P")
  43. }
  44.  
  45.  
  46. ## RAM
  47. $ServerRAM_Calc = (Get-CimInstance Win32_PhysicalMemory | Measure-Object -Property capacity -Sum).sum /1gb
  48.  
  49. ## Network and Domain
  50. $Serverv4 = (Get-NetIPAddress -AddressFamily IPv4 -PrefixOrigin Dhcp).IPAddress
  51. $ServerSubnetString = cmd /c ipconfig | findstr /i "Subnet"
  52. $ServerGatewayString = cmd /c ipconfig | findstr /i "Gateway"
  53. $a, $ServerSubnet = $ServerSubnetString.Split("{:}")
  54. $b, $ServerGateway = $ServerGatewayString.Split("{:}")
  55. $ServerMACGet = (Get-WmiObject -ClassName Win32_NetworkAdapterConfiguration -Filter "IPEnabled='True'" -ComputerName $env:COMPUTERNAME | Select-Object -Property MACAddress, Description).MACAddress
  56. $Trust = Test-ComputerSecureChannel
  57.  
  58. switch ($Trust) {
  59.    "True"  {$Trustee = "Secure Channel to $env:USERDNSDOMAIN alive and working."; break}
  60.    "False" {$Trustee = "Secure Channel Connection to $env:USERDNSDOMAIN failed."; break}
  61.    default {$Trustee = "Something else happened. "; break}
  62. }
  63.  
  64. ## Convert variables into ROA Configuration Collection Variables
  65. $ServerOS = "|  OS | " + (Get-ComputerInfo).WindowsProductName + " |"
  66. $ServerCPU = "|  CPU & Core Count | " + $ServerCPU_NVM + " |"
  67. $ServerRAM = "|  RAM | " + $ServerRAM_Calc + " GiB" + " |"
  68. $ServerHDD = "| Hard Drives  | $DriveListing ," + "Total Size: {0, 5:n3} GiB" -f $ts + ", Free Space: $DriveCalc1" + " |"
  69. $ServerFQDN = "|  FQDN | " + $FQDN + " |"
  70. $ServerIP = "|  IP | " + $Serverv4 + " |"
  71. $ServerSunett = "|  Subnet Mask | " + $ServerSubnet + " |"
  72. $ServerDefaultGate = "|  Default Gateway | " + $ServerGateway + " |"
  73. $ServerMAC = "|  MAC Address | " + $ServerMACGet + " |"
  74. $ServerTrust = "|  Trust | " + $Trustee + " |"
  75.  
  76. # Gather System Software
  77. $SoftwareMD = $env:COMPUTERNAME + '_software.md'
  78. $SoftwareMDFile = "C:\Automation\" + $SoftwareMD
  79. Set-Content -Path "C:\Automation\$SoftwareMD" -Value '| Software Name  | Version | Reason |'
  80. $Tables = "|:-------|:-----:|-----|"
  81. Sleep 3
  82. Add-Content -Path "C:\Automation\$SoftwareMD" -Value $Tables
  83.  
  84. foreach ($UKey in 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*','HKLM:\SOFTWARE\Wow6432node\Microsoft\Windows\CurrentVersion\Uninstall\*','HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*','HKCU:\SOFTWARE\Wow6432node\Microsoft\Windows\CurrentVersion\Uninstall\*')
  85. {foreach ($Product in (Get-ItemProperty $UKey -ErrorAction SilentlyContinue)){if($Product.DisplayName -and $Product.SystemComponent -ne 1){$SoftwareDN = $Product.DisplayName ; $SoftwareDV = $Product.DisplayVersion ; $SoftwareDVI = "| " + "$SoftwareDN" + " | " + "$SoftwareDV" + " |  | " ; Add-Content -Path "C:\Automation\$SoftwareMD" -Value $SoftwareDVI }}}
  86.  
  87. # Gather System Services
  88. $NonDefaultServices = @()
  89. $Services = Get-wmiobject win32_service | where { $_.PathName -notmatch "policyhost.exe" -and $_.Name -ne "LSM" -and $_.PathName -notmatch "OSE.EXE" -and $_.PathName -notmatch "OSPPSVC.EXE" -and $_.PathName -notmatch "Microsoft Security Client" -and $_.DisplayName -notmatch "NetSetupSvc" -and $_.Caption -notmatch "Windows" -and $_.PathName -notmatch "Windows"  }
  90. $ServicesMD = $env:COMPUTERNAME + '_services.md'
  91. $ServicesMDFile = "C:\Automation\" + $ServicesMD
  92. Set-Content -Path "C:\Automation\$ServicesMD" -Value '| Display Name  | Description  |
  93. |:-------|---:|'
  94. Foreach ($Service in $Services){
  95.     $NonDefaultServices+= [pscustomobject]@{
  96.         DisplayName = $Service.DisplayName
  97.         Description = $Service.Description
  98.     }
  99.  
  100.     $Total = '| ' + $Service.DisplayName + ' | ' + $Service.Description + ' |'
  101.     Add-Content -Path "C:\Automation\$ServicesMD" -Value $Total
  102.     }
  103. $ServicesFile = "C:\Automation\$ServicesMD"
  104.  
  105. # Configuration Overview
  106. $Table = "|:----|:----|"
  107. $ConfigurationOverviewFile = "C:\Automation\" + $env:COMPUTERNAME + "_Config_Overview.md"
  108. Set-Content -Path "$ConfigurationOverviewFile" -Value '| Component | Information |'
  109. Add-Content -Path "$ConfigurationOverviewFile" -Value $Table
  110.  
  111. #Add-Content -Path "$ConfigurationOverviewFile" -Value
  112.  
  113. Add-Content -Path "$ConfigurationOverviewFile" -Value $ServerOS
  114. Add-Content -Path "$ConfigurationOverviewFile" -Value $ServerCPU
  115. Add-Content -Path "$ConfigurationOverviewFile" -Value $ServerRAM
  116. Add-Content -Path "$ConfigurationOverviewFile" -Value $ServerHDD
  117. Add-Content -Path "$ConfigurationOverviewFile" -Value $ServerFQDN
  118. Add-Content -Path "$ConfigurationOverviewFile" -Value $ServerIP
  119. Add-Content -Path "$ConfigurationOverviewFile" -Value $ServerSunett
  120. Add-Content -Path "$ConfigurationOverviewFile" -Value $ServerDefaultGate
  121. Add-Content -Path "$ConfigurationOverviewFile" -Value $ServerMAC
  122. Add-Content -Path "$ConfigurationOverviewFile" -Value $ServerTrust
  123.  
  124. # Define ROA Documentation Markdown Template Variables
  125. $ExecutiveTitle = "## Executive Summary / Typical Use"
  126. $ExecutiveSummary = "Brief overview of how it's used and what it does for the company. Keep it non IT simple."
  127.  
  128. $ServicesProvidedTitle = "## Services Provided"
  129. $ServicesProcidedSummary = "Services functions protocols etc. Go into more depth here."
  130.  
  131. $ConfigurationOverviewTitle = "## Configuration Overview"
  132. $ConfigurationOverviewSummary = "Describe the hardware and host setup here, OS, CPU, RAM, etc. Purchase Order info."
  133. $ConfigurationOverview = [IO.File]::ReadAllText("$ConfigurationOverviewFile")
  134.  
  135. $SystemSoftwareTitle = "## System Software"
  136. $SystemSoftwareSummary =  "List, in general, the software installed on the server. Operating system updates are omitted. Include anything at all out of the normal install. Include Runtimes such as .net and C++ etc."
  137. $SystemSoftwareOverview = [IO.File]::ReadAllText("$SoftwareMDFile")
  138.  
  139. $ServicesTitle = "### System Services"
  140. $ServicesSummary = "List, in general, the services installed on the server. Include anything that’s a non-standard service."
  141. $ServicesOverview = [IO.File]::ReadAllText("$ServicesFile")
  142.  
  143. $BackupTitle = "### Backup & Recovery Plan"
  144. $BackupSummary = "This is where you list local backups, network backups, tape backups, and put any backup schedules down to paper. Keep this updated. Don't omit RAID drives even if they are not backup this is a place to document it.
  145. And always remember the goal is to recreate the data and services. Not to put stuff on tape. No matter how you recreate the data or service, those resources are your backup."
  146.  
  147. $PerformanceBenchmarksTitle = " ### Performance Benchmarks "
  148. $PerformanceBenchmarksSummary = "You have done performance benchmarks, haven't you? Just to get an idea of network traffic, CPU traffic, and RAM usage during business hours & off hours. Nothing fancy, just write what you know."
  149.  
  150. $InstallationNotesTitle = "## Installation Notes"
  151. $InstallationNotesSummary = "Anything special about the install & the vendors that provide it goes here. Kind of an errata section."
  152.  
  153. $TroubleshootingSequencesTitle = "## Troubleshooting Sequences"
  154. $TroubleshootingSequencesSummary = "General steps for services to reboot or steps needed to be performed to reboot the machine."
  155.  
  156. $SupportContactsTitle = "### Support Contacts"
  157.  
  158.  
  159. $LineBreak = "***"
  160. $ParagraphTool = "<br/><br/>"
  161.  
  162.  
  163. # Write file
  164. sleep 10
  165. $ServerTemplate = $env:COMPUTERNAME + ".md"
  166. $ServerTemplateFile = "C:\Temp\" + $ServerTemplate
  167. New-Item -Path "C:\Temp\" -Name "$ServerTemplate" -ItemType "File"
  168.  
  169. # Add-Content -Path "$ServerTemplateFile" -Value
  170.  
  171. Add-Content -Path "$ServerTemplateFile" -Value $ServerName
  172. Add-Content -Path "$ServerTemplateFile" -Value $ExecutiveTitle
  173. Add-Content -Path "$ServerTemplateFile" -Value $ExecutiveSummary
  174. Add-Content -Path "$ServerTemplateFile" -Value $ParagraphTool
  175.  
  176. Add-Content -Path "$ServerTemplateFile" -Value $ServicesProvidedTitle
  177. Add-Content -Path "$ServerTemplateFile" -Value $ServicesProcidedSummary
  178. Add-Content -Path "$ServerTemplateFile" -Value $ParagraphTool
  179.  
  180. Add-Content -Path "$ServerTemplateFile" -Value $ConfigurationOverviewTitle
  181. Add-Content -Path "$ServerTemplateFile" -Value $ConfigurationOverviewSummary
  182. Add-Content -Path "$ServerTemplateFile" -Value $ConfigurationOverview
  183. Add-Content -Path "$ServerTemplateFile" -Value $ParagraphTool
  184.  
  185. Add-Content -Path "$ServerTemplateFile" -Value $LineBreak
  186. Add-Content -Path "$ServerTemplateFile" -Value $SystemSoftwareTitle
  187. Add-Content -Path "$ServerTemplateFile" -Value $SystemSoftwareSummary
  188. Add-Content -Path "$ServerTemplateFile" -Value $SystemSoftwareOverview
  189.  
  190. Add-Content -Path "$ServerTemplateFile" -Value $ServicesTitle
  191. Add-Content -Path "$ServerTemplateFile" -Value $ServicesSummary
  192. Add-Content -Path "$ServerTemplateFile" -Value $ServicesOverview
  193. Add-Content -Path "$ServerTemplateFile" -Value $LineBreak
  194.  
  195. Add-Content -Path "$ServerTemplateFile" -Value $BackupTitle
  196. Add-Content -Path "$ServerTemplateFile" -Value $BackupSummary
  197. Add-Content -Path "$ServerTemplateFile" -Value $ParagraphTool
  198.  
  199. Add-Content -Path "$ServerTemplateFile" -Value $PerformanceBenchmarksTitle
  200. Add-Content -Path "$ServerTemplateFile" -Value $PerformanceBenchmarksSummary
  201. Add-Content -Path "$ServerTemplateFile" -Value $ParagraphTool
  202.  
  203. Add-Content -Path "$ServerTemplateFile" -Value $InstallationNotesTitle
  204. Add-Content -Path "$ServerTemplateFile" -Value $InstallationNotesSummary
  205. Add-Content -Path "$ServerTemplateFile" -Value $ParagraphTool
  206.  
  207. Add-Content -Path "$ServerTemplateFile" -Value $TroubleshootingSequencesTitle
  208. Add-Content -Path "$ServerTemplateFile" -Value $TroubleshootingSequencesSummary
  209. Add-Content -Path "$ServerTemplateFile" -Value $ParagraphTool
  210.  
  211. Add-Content -Path "$ServerTemplateFile" -Value $SupportContactsTitle
  212. Add-Content -Path "$ServerTemplateFile" -Value $VendorLine_1
  213. Add-Content -Path "$ServerTemplateFile" -Value $VendorLine_2
  214. Add-Content -Path "$ServerTemplateFile" -Value $VendorLine_3
  215. Add-Content -Path "$ServerTemplateFile" -Value $VendorLine_4
  216. Add-Content -Path "$ServerTemplateFile" -Value $VendorLine_5
  217.  
  218. <# For More than one Vendor contact information please use the following templates
  219. $VendorLine_ = "For support with $Vendor1 software, contact:"
  220. $VendorLine_ = "Vendor 1"
  221. $VendorLine_ = "vendor1@vendor1support.com"
  222. $VendorLine_ = "vendor website information"
  223. $VendorLine_ = "1 (800) 342 0652 "
  224.  
  225. #>
  226.  
  227. <# Add this to the write contact:
  228. Add-Content -Path "$ServerTemplateFile" -Value $VendorLine_
  229. Add-Content -Path "$ServerTemplateFile" -Value $VendorLine_
  230. Add-Content -Path "$ServerTemplateFile" -Value $VendorLine_
  231. Add-Content -Path "$ServerTemplateFile" -Value $VendorLine_
  232. Add-Content -Path "$ServerTemplateFile" -Value $VendorLine_
  233.  
  234. #>
  235.  
  236. # Remove files that are no longer needed:
  237. Remove-Item -Path $ConfigurationOverviewFile -Force
  238. Remove-Item -Path $SoftwareMDFile            -Force
  239. Remove-Item -Path $ServicesMDFile            -Force
  240.  
  241.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement