Advertisement
Guest User

Inventoryemail

a guest
Mar 29th, 2017
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ##lists Computers on network
  2. echo "Computer Names"  >> Computers.txt  
  3. $objDomain = New-Object System.DirectoryServices.DirectoryEntry
  4. IF($objDomain.exist)
  5. {$strCategory = "computer"
  6.  
  7. $objSearcher = New-Object System.DirectoryServices.DirectorySearcher
  8. $objSearcher.SearchRoot = $objDomain
  9. $objSearcher.Filter = ("(objectCategory=$strCategory)")
  10. $colProplist = "name"
  11. foreach ($i in $colPropList){$objSearcher.PropertiesToLoad.Add($i)}
  12. $colResults = $objSearcher.FindAll()
  13. foreach ($objResult in $colResults)
  14.     {$objResult.Properties.name[0] >> Computers.txt ;Clear-Host} }
  15. else {
  16. Get-WmiObject Win32_ComputerSystem | Foreach-Object {$compname =$_.Name}
  17. $compname >> Computers.txt }
  18.  
  19.  
  20. #gets info from computers on network
  21. $computers = Get-Content .\computers.txt
  22. foreach ($comp in $computers)
  23. {
  24. $cimsession = New-CimSession -ComputerName $comp -ErrorAction SilentlyContinue
  25.  
  26. $computerSystem = Get-CimInstance CIM_ComputerSystem  -CimSession $cimsession
  27. $computerBIOS = Get-CimInstance CIM_BIOSElement -CimSession $cimsession
  28. $computerOS = Get-CimInstance CIM_OperatingSystem -CimSession $cimsession
  29. $computerCPU = Get-CimInstance CIM_Processor -CimSession $cimsession
  30. $computerHDD = Get-CimInstance -ClassName win32_logicaldisk -CimSession $cimsession | Where {$_.drivetype -eq "3" -and $_.deviceid -like "C:" } | Select-Object @{l="Freespace";e={[math]::round($_.freespace/1GB)}}
  31. $outputFile = ".\{0}-{1:yyyyMMddHHmm}.csv" -f $env:COMPUTERNAME,(Get-Date)
  32.  
  33. $inventory = New-Object psobject -property @{
  34.     Name=$computersystem.name;
  35.     Manufacturer=$computersystem.manufacturer;
  36.     SerialNumber = $computerbios.serialnumber;
  37.     Processor=$computerCPU.name;
  38.     OS=$computerOS.caption;
  39.     InstallDate=$computeros.InstallDate;
  40.     FreeSpace=$computerHDD
  41.     }
  42. }
  43.  
  44. $inventory | export-csv $outputFile -Append -NoTypeInformation
  45.  
  46. #attaches and sends network information
  47. function sendMail
  48. {
  49.     #SMTP server name
  50.     $From = ""
  51.     $To = ""
  52.     $Cc =
  53.     $Subject = " $env:COMPUTERNAME"
  54.     $Body = $body
  55.     $Attachment = ".\inventory.cvs"
  56.     $SMTPServer = "smtp.gmail.com"
  57.     $SMTPPort = "587"
  58.     $username = ""
  59.     $password = ""
  60.     $SecurePassword = $Password | ConvertTo-SecureString -AsPlainText -Force
  61.     $Credentials = New-Object System.Management.Automation.PSCredential -ArgumentList $Username, $SecurePassword
  62.    
  63.     #Sending email
  64.     Send-MailMessage -From $From -To $To -Subject $Subject -SmtpServer $SMTPServer -Port 587 -UseSsl -Credential $Credentials -Attachment $Attachment
  65.    
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement