PowerShell Script Read Computer Details and Write it to Text File

Powershell Script

Following script is used to read computer details and write it to text file.
Computer Details include computer name, serial number, MacAddress & IPAddress. 
  1. $OutputFilePath = "C:\ComputerDetails.txt"  
  2. $strComputer = (Get - WmiObject Win32_Computersystem).name  
  3. $SerialNumber = gwmi win32_bios | Select– ExpandProperty SerialNumber  
  4.     [System.IO.File]::WriteAllText($OutputFilePath, $file.FullName)  
  5. $file.lastwritetime | Add - Content $OutputFilePath  
  6. $colItems = Get - WmiObject - Class "Win32_NetworkAdapterConfiguration" - ComputerName $strComputer - Filter "IpEnabled = TRUE"  
  7. ForEach($objItem in $colItems)  
  8. {#  
  9.     write - host "IP Address: "  
  10.     $objItem.IpAddress[0]  
  11.     "Mac: "  
  12.     $objItem.MacAddress  
  13.     $MacAddress = $objItem.MacAddress  
  14.     $IPAddress = $objItem.IpAddress[0]  
  15. }  
  16. "Computer Name : " + $ComputerName | Add - Content $OutputFilePath  
  17.     "Serial Number : " + $SerialNumber | Add - Content $OutputFilePath  
  18.     "Mac Address   : " + $MacAddress | Add - Content $OutputFilePath  
  19.     "IP Address   : " + $IPAddress | Add - Content $OutputFilePath