Advertisement
Guest User

Untitled

a guest
Jul 12th, 2014
1,001
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.38 KB | None | 0 0
  1. #Autoinventory script. Gets Computer name, Logged in user, Serial Number, Model, Version of Windows,
  2. #Version of Office, Visual Studio, Visio, Project
  3. #Author Dumplati
  4.  
  5. $hostname = hostname
  6. $user = whoami
  7. $user2 = $user.Replace("\","\\")
  8. $product = wmic product
  9. $file = "Path to "
  10. $tempfile = "Path to Temp"
  11. $windows = systeminfo | findstr /B /C:"OS Name" /C:"OS Version"
  12. $serial = (@(wmic csproduct get identifyingnumber) -join ',')
  13. $serial2 = $serial.Replace("IdentifyingNumber", "")
  14. $serial3 = $serial2.Replace(",", "")
  15. $serial4 = $serial3.Replace(" ", "")
  16. $model = (@(wmic computersystem get model) -join ',')
  17. $model2 = $model.Replace("Model", "")
  18. $model3 = $model2.Replace(",","")
  19. $model4 = $model3.Replace(" ","")
  20. $windows2 = "Windows Version not checked by script."
  21. $Office = "No Office"
  22. $Visio = "No Visio"
  23. $Project = "No Project"
  24. $Visual = "No Visual Studio"
  25. if ($windows -Match "Microsoft Windows 7 Starter") {$windows2 = "Windows 7 Starter"}
  26. if ($windows -Match "Microsoft Windows 7 Home Basic") {$windows2 = "Windows 7 Home Basic"}
  27. if ($windows -Match "Microsoft Windows 7 Home Premium") {$windows2 = "Windows 7 Home Premium"}
  28. if ($windows -Match "Microsoft Windows 7 Professional") {$windows2 = "Windows 7 Professional"}
  29. if ($windows -Match "Microsoft Windows 7 Enterprise") {$windows2 = "Windows 7 Enterprise"}
  30. if ($windows -Match "Microsoft Windows 7 Ultimate") {$windows2 = "Windows 7 Ultimate"}
  31. if ($windows -Match "Microsoft Windows 8 RT") {$windows2 = "Windows 8 RT"}
  32. if ($windows -Match "Microsoft Windows 8 Professional") {$windows2 = "Windows 8 Professional"}
  33. if ($windows -Match "Microsoft Windows 8 Enterprise") {$windows2 = "Windows 8 Enterprise"}
  34. if ($windows -Match "Microsoft Windows 8 Standard") {$windows2 = "Windows 8 Standard"}
  35. if ($windows -Match "Microsoft Windows 8.1 RT") {$windows2 = "Windows 8.1 RT"}
  36. if ($windows -Match "Microsoft Windows 8.1 Pro") {$windows2 = "Windows 8.1 Professional"}
  37. if ($windows -Match "Microsoft Windows 8.1 Ent") {$windows2 = "Windows 8.1 Enterprise"}
  38. if ($windows -Match "Microsoft Windows 8.1 Sta") {$windows2 = "Windows 8.1 Standard"}
  39. if ($windows -Match "Microsoft Windows Server 2012 Standard") {$windows2 = "Windows Server 2012 Standard"}
  40. if ($windows -Match "Microsoft Windows Server 2012 R2 Standard") {$windows2 = "Windows Server 2012 R2 Standard"}
  41. if ($windows -Match "Microsoft Windows Server 2012 Datacenter") {$windows2 = "Windows Server 2012 Datacenter"}
  42. if ($windows -Match "Microsoft Windows Server 2012 R2 Datacenter") {$windows2 = "Windows Server 2012 R2 Datacenter"}
  43. if ($windows -Match "Microsoft Windows Server 2012 Essentials") {$windows2 = "Windows Server 2012 Essentials"}
  44. if ($windows -Match "Microsoft Windows Server 2012 R2 Essentials") {$windows2 = "Windows Server 2012 R2 Essentials"}
  45. if ($windows -Match "Microsoft Windows Server 2012 Foundation") {$windows2 = "Windows Server 2012 Foundation"}
  46. if ($windows -Match "Microsoft Windows Server 2012 R2 Foundation") {$windows2 = "Windows Server 2012 R2 Foundation"}
  47. if ($windows -Match "Microsoft Windows Server 2008 R2 Datacenter") {$windows2 = "Windows Server 2008 R2 Datacenter"}
  48. if ($windows -Match "Microsoft Windows Server 2008 R2 Enterprise") {$windows2 = "Windows Server 2008 R2 Enterprise"}
  49. if ($windows -Match "Microsoft Windows Server 2008 R2 Web Edition") {$windows2 = "Windows Server 2008 R2 Web Edition"}
  50. if ($windows -Match "Microsoft Windows Server 2008 R2 Standard") {$windows2 = "Windows Server 2008 R2 Standard"}
  51. if ($windows -Match "Microsoft Windows Server 2008 Datacenter") {$windows2 = "Windows Server 2008 Datacenter"}
  52. if ($windows -Match "Microsoft Windows Server 2008 Enterprise") {$windows2 = "Windows Server 2008 Enterprise"}
  53. if ($windows -Match "Microsoft Windows Server 2008 Web Edition") {$windows2 = "Windows Server 2008 Web Edition"}
  54. if ($windows -Match "Microsoft Windows Server 2008 Standard") {$windows2 = "Windows Server 2008 Standard"}
  55. if ($product -Match "Microsoft Office Professional Plus 2013") {$Office = "Office Professional Plus 2013"}
  56. if ($product -Match "Microsoft Office Professional 2013") {$Office = "Office Professional 2013"}
  57. if ($product -Match "Microsoft Office Standard 2013") {$Office = "Office Standard 2013"}
  58. if ($product -Match "Microsoft Office Professional Plus 2010") {$Office = "Office Professional Plus 2010"}
  59. if ($product -Match "Microsoft Office Professional 2010") {$Office = "Office Professional 2010"}
  60. if ($product -Match "Microsoft Office Standard 2010") {$Office = "Office Standard 2010"}
  61. if ($product -Match "Microsoft Office Home and Business 2010") {$Office = "Office Home and Business 2010"}
  62. if ($product -Match "Microsoft Office Ultimate 2007") {$Office = "Office Ultimate 2007"}
  63. if ($product -Match "Microsoft Office Professional 2007") {$Office = "Office Professional 2007"}
  64. if ($product -Match "Microsoft Visio Professional 2013") {$Visio = "Visio Professional 2013"}
  65. if ($product -Match "Microsoft Visio Standard 2013") {$Visio = "Visio Standard 2013"}
  66. if ($product -Match "Microsoft Visio Professional 2010") {$Visio = "Visio Professional 2010"}
  67. if ($product -Match "Microsoft Visio Standard 2010") {$Visio = "Visio Standard 2010"}
  68. if ($product -Match "Microsoft Project Professional 2013") {$Project = "Project Professional 2013"}
  69. if ($product -Match "Microsoft Project Standard 2013") {$Project = "Project Standard 2013"}
  70. if ($product -Match "Microsoft Project Professional 2010") {$Project = "Project Professional 2010"}
  71. if ($product -Match "Microsoft Project Standard 2010") {$Project = "Project Standard 2010"}
  72. if ($product -Match "Microsoft Visual Studio Professional 2012") {$Visual = "Visual Studio Professional 2012"}
  73. if ($product -Match "Microsoft Visual Studio Ultimate 2012") {$Visual = "Visual Studio Ultimate 2012"}
  74. if ($product -Match "Microsoft Visual Studio Professional 2010") {$Visual = "Visual Studio Professional 2010"}
  75. if ($product -Match "Microsoft Visual Studio Ultimate 2010") {$Visual = "Visual Studio Ultimate 2010"}
  76. if ($product -Match "Microsoft Visual Studio Professional 2005") {$Visual = "Visual Studio Professional 2005"}
  77. $csv = new-object PSObject
  78. $csv | add-member NoteProperty Hostname $hostname
  79. $csv | add-member NoteProperty User $user
  80. $csv | add-member NoteProperty SerialNumber $serial4
  81. $csv | add-member NoteProperty Model $model4
  82. $csv | add-member NoteProperty WindowsVersion $windows2
  83. $csv | add-member NoteProperty OfficeVersion $Office
  84. $csv | add-member NoteProperty VisioVersion $Visio
  85. $csv | add-member NoteProperty ProjectVersion $Project
  86. $csv | add-member NoteProperty VisualVersion $Visual
  87. $csvimport = @(Import-CSV $file)
  88.  
  89. if ($csvimport -Match $hostname -Match $user2 -Match $serial4 -Match $model4 -Match $windows2 -Match $Office -Match $Visio -Match $Project -Match $Visual){
  90. exit
  91. }
  92.  
  93. if ($csvimport -Match $hostname -Match $user2 -Match $Office) {$oah = "Exists"} else {
  94. $oah = "Does notexist"
  95. Import-Csv $file ` | ? { $hostname -notcontains $_."Hostname" } ` | Export-Csv $tempfile -NoTypeInformation
  96. Import-Csv $tempfile ` | ? { $hostname -notcontains $_."Hostname" } ` | Export-Csv $file -NoTypeInformation
  97. $csvimport = @(Import-CSV $file)
  98. $csvimport + $csv | export-csv "$file" -Force
  99. exit
  100. }
  101.  
  102. if ($csvimport -Match $hostname -Match $user2 -Match $Visio) {$vah = "Exists"} else {
  103. $vah = "Does notexist"
  104. Import-Csv $file ` | ? { $hostname -notcontains $_."Hostname" } ` | Export-Csv $tempfile -NoTypeInformation
  105. Import-Csv $tempfile ` | ? { $hostname -notcontains $_."Hostname" } ` | Export-Csv $file -NoTypeInformation
  106. $csvimport = @(Import-CSV $file)
  107. $csvimport + $csv | export-csv "$file" -Force
  108. exit
  109. }
  110.  
  111. if ($csvimport -Match $hostname -Match $user2 -Match $Project) {$pah = "Exists"} else {
  112. $pah = "Does notexist"
  113. Import-Csv $file ` | ? { $hostname -notcontains $_."Hostname" } ` | Export-Csv $tempfile -NoTypeInformation
  114. Import-Csv $tempfile ` | ? { $hostname -notcontains $_."Hostname" } ` | Export-Csv $file -NoTypeInformation
  115. $csvimport = @(Import-CSV $file)
  116. $csvimport + $csv | export-csv "$file" -Force
  117. exit
  118. }
  119.  
  120. if ($csvimport -Match $hostname -Match $user2 -Match $Visual) {$viah = "Exists"} else {
  121. $viah = "Does notexist"
  122. Import-Csv $file ` | ? { $hostname -notcontains $_."Hostname" } ` | Export-Csv $tempfile -NoTypeInformation
  123. Import-Csv $tempfile ` | ? { $hostname -notcontains $_."Hostname" } ` | Export-Csv $file -NoTypeInformation
  124. $csvimport = @(Import-CSV $file)
  125. $csvimport + $csv | export-csv "$file" -Force
  126. exit
  127. }
  128. Remove-Item $tempfile
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement