Advertisement
Guest User

TRMM to ITFlow

a guest
Mar 4th, 2023
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.23 KB | None | 0 0
  1. <#
  2. .SYNOPSIS
  3. Create asset(s) from Tactical RMM to ITFlow.
  4.  
  5. .REQUIREMENTS
  6. - ITFlow API key.
  7. - Global key in TacticalRMM named "ITFlow_API" with your ITFlow API key as the value.
  8. - Global key in TacticalRMM named "ITFlow_url" with your ITFlow URL as the value.
  9. - Client custom field in TacticalRMM named "ITFlow_client_ID".
  10. - Each client in TacticalRMM should have its ITFlow_client_ID populated with the client_id found in ITFlow. (To find the id, check the URL in ITFlow once you select a client)
  11.  
  12. .NOTES
  13. -
  14.  
  15. .SCRIPT_ARGUMENTS
  16. -ITFlow_API {{global.ITFlow_API}}
  17. -ITFlow_url {{global.ITFlow_url}}
  18. -ITFlow_client_ID {{client.ITFlow_client_ID}}
  19. -asset_id {{agent.agent_id}}
  20.  
  21. .EXAMPLE
  22. -
  23.  
  24. .TODO
  25. - Warranty expiration checks
  26.  
  27. .VERSION
  28. - v1.0 Initial Release
  29.  
  30. #>
  31.  
  32.  
  33. param(
  34. [string] $ITFlow_API,
  35. [string] $ITFlow_url,
  36. [string] $ITFlow_client_ID,
  37. [string] $asset_id
  38. )
  39.  
  40. $asset_name = $Env:ComputerName
  41. $agent_make = (Get-WmiObject -Class:Win32_ComputerSystem).Manufacturer
  42. $agent_model = (Get-WmiObject -Class:Win32_ComputerSystem).Model
  43. $agent_serial = (Get-WmiObject -Class:Win32_BIOS).SerialNumber
  44. $asset_os = (Get-WmiObject Win32_OperatingSystem).Caption
  45. $asset_mac = (Get-WmiObject -Class Win32_NetworkAdapterConfiguration | where {$_.DHCPEnabled -ne $null -and $_.DefaultIPGateway -ne $null}).macaddress | Select-Object -First 1
  46. $install = ([DateTime](Get-Item -Force 'C:\System Volume Information\').CreationTime).ToString('yyyy/MM/dd')
  47. $local_ip = (Get-WmiObject -Class Win32_NetworkAdapterConfiguration | where {$_.DHCPEnabled -ne $null -and $_.DefaultIPGateway -ne $null}).IPAddress | Select-Object -First 1
  48.  
  49. function Test-IsLaptop {
  50. $HardwareType = (Get-CimInstance -Class Win32_ComputerSystem -Property PCSystemType).PCSystemType
  51. # https://docs.microsoft.com/en-us/windows/win32/cimwin32prov/win32-computersystem
  52. # Mobile = 2
  53. $HardwareType -eq 2
  54. }
  55.  
  56. function Test-IsServer {
  57. $osInfo = (Get-CimInstance -Class:Win32_OperatingSystem).ProductType
  58. $osInfo -ne 1
  59. }
  60.  
  61. if (Test-IsServer) { $asset_type = "Server" }
  62. if (Test-IsLaptop) { $asset_type = "Laptop" }
  63. else
  64. { $asset_type = "Desktop" }
  65.  
  66.  
  67. # Data
  68. $body = @"
  69. {
  70. "api_key" : "$ITFlow_API",
  71. "asset_name" : "$asset_name",
  72. "asset_type" : "$asset_type",
  73. "asset_make" : "$agent_make",
  74. "asset_model" : "$agent_model",
  75. "asset_serial" : "$agent_serial",
  76. "asset_os" : "$asset_os",
  77. "asset_ip" : "$local_ip",
  78. "asset_mac" : "$asset_mac",
  79. "asset_purchase_date" : "",
  80. "asset_warranty_expire" : "",
  81. "asset_install_date" : "$install",
  82. "asset_notes" : "",
  83. "asset_vendor_id" : "",
  84. "asset_location_id" : "",
  85. "asset_contact_id" : "",
  86. "asset_network_id" : "",
  87. "asset_status" : "Deployed",
  88. "client_id" : "$ITFlow_client_ID",
  89. "asset_id" : "$asset_id"
  90. }
  91. "@
  92.  
  93. # Module / Endpoint
  94. $module = "/api/v1/assets/create.php"
  95.  
  96. # Build URI from defined data
  97. $uri = $ITFlow_url + $module
  98.  
  99. # Request
  100. # Use Invoke-WebRequest instead of Invoke-RestMethod to see more info about the request/response
  101. Invoke-RestMethod -Method Post -Uri $uri -Body $body
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement