Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <#
- .SYNOPSIS
- Create asset(s) from Tactical RMM to ITFlow.
- .REQUIREMENTS
- - ITFlow API key.
- - Global key in TacticalRMM named "ITFlow_API" with your ITFlow API key as the value.
- - Global key in TacticalRMM named "ITFlow_url" with your ITFlow URL as the value.
- - Client custom field in TacticalRMM named "ITFlow_client_ID".
- - 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)
- .NOTES
- -
- .SCRIPT_ARGUMENTS
- -ITFlow_API {{global.ITFlow_API}}
- -ITFlow_url {{global.ITFlow_url}}
- -ITFlow_client_ID {{client.ITFlow_client_ID}}
- -asset_id {{agent.agent_id}}
- .EXAMPLE
- -
- .TODO
- - Warranty expiration checks
- .VERSION
- - v1.0 Initial Release
- #>
- param(
- [string] $ITFlow_API,
- [string] $ITFlow_url,
- [string] $ITFlow_client_ID,
- [string] $asset_id
- )
- $asset_name = $Env:ComputerName
- $agent_make = (Get-WmiObject -Class:Win32_ComputerSystem).Manufacturer
- $agent_model = (Get-WmiObject -Class:Win32_ComputerSystem).Model
- $agent_serial = (Get-WmiObject -Class:Win32_BIOS).SerialNumber
- $asset_os = (Get-WmiObject Win32_OperatingSystem).Caption
- $asset_mac = (Get-WmiObject -Class Win32_NetworkAdapterConfiguration | where {$_.DHCPEnabled -ne $null -and $_.DefaultIPGateway -ne $null}).macaddress | Select-Object -First 1
- $install = ([DateTime](Get-Item -Force 'C:\System Volume Information\').CreationTime).ToString('yyyy/MM/dd')
- $local_ip = (Get-WmiObject -Class Win32_NetworkAdapterConfiguration | where {$_.DHCPEnabled -ne $null -and $_.DefaultIPGateway -ne $null}).IPAddress | Select-Object -First 1
- function Test-IsLaptop {
- $HardwareType = (Get-CimInstance -Class Win32_ComputerSystem -Property PCSystemType).PCSystemType
- # https://docs.microsoft.com/en-us/windows/win32/cimwin32prov/win32-computersystem
- # Mobile = 2
- $HardwareType -eq 2
- }
- function Test-IsServer {
- $osInfo = (Get-CimInstance -Class:Win32_OperatingSystem).ProductType
- $osInfo -ne 1
- }
- if (Test-IsServer) { $asset_type = "Server" }
- if (Test-IsLaptop) { $asset_type = "Laptop" }
- else
- { $asset_type = "Desktop" }
- # Data
- $body = @"
- {
- "api_key" : "$ITFlow_API",
- "asset_name" : "$asset_name",
- "asset_type" : "$asset_type",
- "asset_make" : "$agent_make",
- "asset_model" : "$agent_model",
- "asset_serial" : "$agent_serial",
- "asset_os" : "$asset_os",
- "asset_ip" : "$local_ip",
- "asset_mac" : "$asset_mac",
- "asset_purchase_date" : "",
- "asset_warranty_expire" : "",
- "asset_install_date" : "$install",
- "asset_notes" : "",
- "asset_vendor_id" : "",
- "asset_location_id" : "",
- "asset_contact_id" : "",
- "asset_network_id" : "",
- "asset_status" : "Deployed",
- "client_id" : "$ITFlow_client_ID",
- "asset_id" : "$asset_id"
- }
- "@
- # Module / Endpoint
- $module = "/api/v1/assets/create.php"
- # Build URI from defined data
- $uri = $ITFlow_url + $module
- # Request
- # Use Invoke-WebRequest instead of Invoke-RestMethod to see more info about the request/response
- Invoke-RestMethod -Method Post -Uri $uri -Body $body
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement