A .NET wrapper for the Snipe IT API written (poorly) in C# for C# and PowerShell.
Disregard the prereqs and installation below. You need the .NET Core SDK, version 3 or higher. VS Code tasks are provided for build and testing.
The goal of this project is to give easy access to all endpoints of the Snipe IT API via C# and PowerShell. With that said, this build is currently a rough demo. Most of the endpoints work as expected but plan on things breaking or not working 100%.
This project was built to support my own needs. As such, features are being worked on in the order I personally need them. However, if you want a feature or find a bug please open an issue.
If you see something we've done that should be done differently, we encourage you to let us know.
A Working Install of Snipe IT V4.6.15+
nuget install SnipeSharp
The PowerShell examples include the default prefix "Snipe".
SnipeItApi snipe = new SnipeItApi {
Token = "XXXXXXXX",
Uri = new Uri("http://xxxxx.com/api/v1")
};
PS C:\> Connect-SnipeIT -Token "XXXXXXXX" -Uri "http://xxxxx.com/api/v1"
Each endpoint has its own manager assigned to the SnipeItApi object. Example, SnipeItApi.Assets
Each endpoint has a common set of actions. Additional methods for each endpoint are made available in the relevant subclasses.
Return all objects at this end point
snipe.Assets.GetAll()
PS C:\> Get-SnipeAsset
Or, in a generic form:
snipe.GetEndPoint<T>().GetAll()
Find all objects matching certain filtering criteria
snipe.GetEndPoint<T>().FindAll(ISearchFilter filter)
PS C:\> Find-SnipeAsset @filter
Find first object matching search criteria
snipe.GetEndPoint<T>().FindOne(ISearchFilter filter)
Get object with ID
snipe.GetEndPoint<T>().Get(int Id)
PS C:\> Get-SnipeAsset $Id
Search for object with given name
snipe.GetEndPoint<T>().Get(string name)
Create an object
snipe.GetEndPoint<T>().Create(T item)
PS C:\> New-SnipeAsset @properties
Update an object
snipe.GetEndPoint<T>().Update(T item)
PS C:\> Set-Asset @properties
Delete an object
snipe.GetEndPoint<T>().Delete(int id)
PS C:\> Remove-SnipeAsset $Id
Create a new asset
var asset = new Asset {
Name = "Loaner1",
AssetTag = "12345678",
Model = snipe.Models.Get("Lenovo"),
Status = snipe.StatusLabels.Get("Ready to Deploy"),
Location = snipe.Locations.Get("Maine")
};
snipe.Assets.Create(asset);
PS C:\> New-SnipeAsset -Name "Loaner1" -AssetTag 12345678 -Model Lenovo -Status "Ready to Deploy" -Location Maine
Update an Asset
var asset = snipe.Assets.Get("Loaner1");
asset.Serial = "1i37dpc3k";
snipe.Assets.Update(asset);
PS C:\> Set-SnipeAsset -Name "Loaner1" -NewSerial "1i37dpc3k"
Update an asset with a Custom Field
var asset = snipe.Assets.Get("BurnerPhone-1234");
asset.CustomFields["_snipeit_imei_number_37"] = "01-234567-890123-4"
snipe.Assets.Update(asset);
PS C:\> Set-SnipeAsset -Name "BurnerPhone-1234" -CustomField @{ "_snipeit_imei_number_37" = "01-234567-890123-4" }
Get all assets from made by a certain manufacturer
var filter = new AssetSearchFilter {
Manufacturer = snipe.Manufacturers.Get("Lenovo")
};
var result = snipe.Assets.FindAll(filter);
PS C:\> Find-SnipeAsset -Manufacturer Lenovo
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.
We use SemVer for versioning. For the versions available, see the tags on this repository.
- Matthew 'Barry' Carey - Initial work - BarryCarey
- Christian LaCourt - Rewrite for v2, and PowerShell cofl
See also the list of contributors who participated in this project.
This project is licensed under the MIT License - see the LICENSE.md file for details