Guest User

Untitled

a guest
Apr 22nd, 2019
2,005
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. param([string]$computerName)
  2.  
  3. $apikey = "supersecretapikey"
  4. $url = "http://url.snipeit.com"
  5.  
  6. $computerName = (Get-WmiObject -class Win32_ComputerSystem -ComputerName $computerName).name
  7. $assetTag = (Get-WmiObject win32_bios -ComputerName $computerName).SerialNumber
  8. $assetExists = Get-Asset -search $assetTag -url $url -apikey $apikey
  9.  
  10. $cs = (Get-WmiObject -class Win32_ComputerSystem -ComputerName $computerName).TotalPhysicalMemory
  11. $memoryAmount = [math]::Ceiling($cs / 1024 / 1024 / 1024)
  12. $modelno = (Get-WmiObject -class Win32_ComputerSystem -ComputerName $computerName).Model
  13. $manufacturer = (Get-WmiObject -class Win32_ComputerSystem -ComputerName $computerName).Manufacturer
  14. $SystemType = (Get-WmiObject -class Win32_ComputerSystem -ComputerName $computerName).PCSystemType
  15. $OS = (Get-WmiObject  Win32_OperatingSystem -ComputerName $computerName).caption
  16. $OSArch = (Get-WmiObject  Win32_OperatingSystem -ComputerName $computerName).osarchitecture
  17.  
  18. $cpu = (Get-WmiObject Win32_Processor -ComputerName $computerName).Name
  19. if ($cpu -like "*i5*"){
  20.     $cpuType = "i5"
  21. }
  22. elseif ($cpu -like "*i7*"){
  23.     $cpuType = "i7"
  24. }
  25. elseif ($cpu -like "*i3*"){
  26.     $cpuType = "i3"
  27. }
  28.  
  29. $modelSelection = Get-Model -url $url -apikey $apikey | Where-Object {$_.name -like "*$modelno*" -and $_.name -like "*$memoryAmount*" -and $_.name -like "*$cpuType*"}
  30.  
  31. if(([string]::IsNullOrEmpty($modelSelection)))
  32.     $NewModel = "$($modelno) $($cpuType)/$($memoryAmount)GB"
  33.     $Assetmanufacturer = Get-Manufacturer -url $url -apikey $apikey | Where-Object {$_.name -like "*$manufacturer*"}
  34.     $ComputerType = (Get-WmiObject -Class:Win32_ComputerSystem  -ComputerName $computerName).PCSystemTypeEx
  35.     If($ComputerType = 2){$Categoryid = 2}
  36.     If($ComputerType = 1){$Categoryid = 3}
  37.     New-Model $NewModel -category_id $Categoryid -manufacturer_id $Assetmanufacturer.id -fieldset_id 5 -url $url -apikey $apikey
  38.  
  39.     $modelSelection = Get-Model -url $url -apikey $apikey | Where-Object {$_.name -like "*$modelno*" -and $_.name -like "*$memoryAmount*" -and $_.name -like "*$cpuType*"}
  40. }
  41.  
  42. Write-Host $modelno
  43. if(([string]::IsNullOrEmpty($assetExists)))
  44. {
  45.     New-Asset -Name $computerName -tag $assetTag -Model_id $modelSelection.id -Status "2" -url $url -apikey $apikey
  46. }
  47. else {
  48.     Write-Host "Asset Exist $($assetExists.id) : $($computerName) $($assetTag) $($SystemType) $($manufacturer)"
  49.    
  50.     Set-Asset -id $($assetExists.id) -Name $computerName  -Model_id $modelSelection.id  -Status "2"  -url $url -apikey $apikey -CustomValues = @{ OS = "$($OS)" }
  51.    
  52.     exit
  53. }
Advertisement
Add Comment
Please, Sign In to add comment