This PowerShell script is designed as an agent for the Snipe-IT asset management system. It performs the following tasks:
- Retrieve Computer Information: Gathers detailed information about the computer, such as model, serial number, RAM, CPU, OS version, kernel, storage type, storage capacity, MAC addresses, IP addresses, and more.
- Search and Create Models: Searches for the computer model in Snipe-IT. If it doesn't exist, the script creates a new model.
- Search and Create Assets: Searches for the computer asset in Snipe-IT using the serial number. If it doesn't exist, the script creates a new asset and populates various custom fields with the gathered information.
- Update Existing Assets: Updates the existing asset's name and custom fields if there are any changes.
- Hyper-V VM Information: Checks if Hyper-V is installed and, if so, lists the VMs on the host and updates a custom field with this information.
- Snipe-IT API Token: You need a valid Snipe-IT API token with appropriate permissions to access and modify models and assets.
- PowerShell: The script is written in PowerShell and requires PowerShell to execute.
- Set Custom fields: You need to adjust the function Get-CustomFields to update your custom fields (Retrieve Computer Information function)
- Clone the repository or download the script to your local machine.
- Open the script in a text editor and configure the following variables:
$SnipeItApiUrl: The base URL of your Snipe-IT instance.$SnipeItApiToken: Your Snipe-IT API token.$category_id: The category ID for your models (default: 3 for desktops, 2 for laptops).$fieldset_id: The fieldset ID for your models.
- Update the custom fields in the
Get-CustomFieldsfunction to match the ones in your Snipe-IT installation. (dbfield names : https://snipe-it.readme.io/reference/updating-custom-fields) - To enable the exclusion of specific models and serial numbers, update the
Get-ComputerModelandGet-ComputerSerialNumberfunctions. In these functions, define arrays ($invalidModelsand$invalidSerials) containing the models and serial numbers you want to exclude.
Run the script using PowerShell:
.\snipeit-asset-management.ps1