iamkilo

computersnipe.ps1

Apr 19th, 2019
7,043
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $apikey = "supersecretapikey"
  2. $url = "snipeurl"
  3.  
  4. $assetTag = (Get-WmiObject win32_bios).SerialNumber
  5.  
  6. $assetExists = Get-Asset -search $assetTag -url $url -apikey $apikey
  7. if(([string]::IsNullOrEmpty($assetExists)))
  8. {
  9.     $computerName = $env:COMPUTERNAME
  10.     $cs = (Get-WmiObject -class Win32_ComputerSystem).TotalPhysicalMemory
  11.     $memoryAmount = [math]::Ceiling($cs / 1024 / 1024 / 1024)
  12.     $modelno = (Get-WmiObject -class Win32_ComputerSystem).Model
  13.  
  14.     $cpu = (Get-WmiObject Win32_Processor).Name
  15.     if ($cpu -like "*i5*"){
  16.         $cpuType = "i5"
  17.     }
  18.     elseif ($cpu -like "*i7*"){
  19.         $cpuType = "i7"
  20.     }
  21.  
  22.     $modelSelection = Get-Model -url $url -apikey $apikey | Where-Object {$_.name -like "*$modelno*" -and $_.name -like "*$memoryAmount*" -and $_.name -like "*$cpuType*"}
  23.  
  24.     New-Asset -Name $computerName -tag $assetTag -Model_id $modelSelection.id -Status "2" -url $url -apikey $apikey
  25. }
  26. else {
  27.     exit
  28. }
Advertisement
Add Comment
Please, Sign In to add comment