NN.SnipeIT.psm1
#Region './Private/Get-SnipeAccessToken.ps1' 0 function Get-SnipeAccessToken { param ( [string]$accessTokenPath = "$env:USERPROFILE\.creds\Snipe-IT\snipeitAccessToken.xml" ) if (!(Test-Path $accessTokenPath)) { New-SnipeAccessToken } Import-Clixml $accessTokenPath | ConvertFrom-SecureString -AsPlainText } #EndRegion './Private/Get-SnipeAccessToken.ps1' 12 #Region './Private/Get-SnipeEndpoint.ps1' 0 function Get-SnipeEndpoint { param ( [string]$endpointPath = "$env:USERPROFILE\.creds\Snipe-IT\snipeitEndpoint.xml" ) if (!(Test-Path $endpointPath)) { New-SnipeEndpoint } Import-Clixml $endpointPath } #EndRegion './Private/Get-SnipeEndpoint.ps1' 12 #Region './Private/Invoke-SnipeMethod.ps1' 0 function Invoke-SnipeMethod { param ( [Parameter(Mandatory)][string]$Uri, [Parameter(Mandatory)][ValidateSet("GET","POST","PUT","PATCH","DELETE")][string]$Method ) $splat = @{ "Uri" = $uri "Method" = $Method "Headers" = @{ "Authorization" = "Bearer $(Get-SnipeAccessToken)" "Accept" = "application/json" "Content-Type" = "application/json" } } $result = Invoke-RestMethod @splat if ($result.PSObject.Properties.name -contains "rows") { $result.rows } else { $result } } #EndRegion './Private/Invoke-SnipeMethod.ps1' 24 #Region './Private/Register-Autofill.ps1' 0 $Splat = @{ "CommandName" = "Get-SnipeLocations" "ParameterName" = "name" "ScriptBlock" = { param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters) $AllLocationNames = (Get-SnipeLocations).name | Sort-Object $AllLocationNames.Where({ $_ -like "$wordToComplete*" }).ForEach({ "`"$_`"" }) } } Register-ArgumentCompleter @Splat #EndRegion './Private/Register-Autofill.ps1' 16 #Region './Public/Get-SnipeAccessories.ps1' 0 function Get-SnipeAccessories { [CmdletBinding(DefaultParameterSetName="List accessories")] param ( [Parameter(Position=0,ParameterSetName="List accessories")][string]$search, [Parameter(ParameterSetName="List accessories")][int]$limit, [Parameter(ParameterSetName="List accessories")][int]$offset, [Parameter(ParameterSetName="List accessories")][string]$order_number, [Parameter(ParameterSetName="List accessories")][ValidateSet( "id", "name", "asset_tag", "serial", "model", "model_number", "last_checkout", "category", "manufacturer", "notes", "expected_checkin", "order_number", "companyName", "location", "image", "status_label", "assigned_to", "created_at", "purchase_date", "purchase_cost" )][string]$sort, [Parameter(ParameterSetName="List accessories")][ValidateSet("asc","desc")][string]$order, [Parameter(ParameterSetName="List accessories")][ValidateSet("true","false")][string]$expand, [Parameter(Mandatory,ParameterSetName="Get accessory by id")][int]$id, [Parameter(ParameterSetName="Get accessory by id")][switch]$listCheckedOut ) $uri = "$(Get-SnipeEndpoint)/accessories" switch ($PsCmdlet.ParameterSetName) { "List accessories" { $PSBoundParameters.Keys.ForEach({ $key = $_ $value = $PSBoundParameters.$key if (([array]$PSBoundParameters.Keys)[0] -eq $key) { $delimiter = "?" } else { $delimiter = "&" } $uri = "$uri$delimiter$key=$value" }) } "Get accessory by id" { $uri = "$uri/$id" if ($listCheckedOut) { $uri = "$uri/checkedout" } } } Invoke-SnipeMethod -Method "GET" -Uri $uri } #EndRegion './Public/Get-SnipeAccessories.ps1' 64 #Region './Public/Get-SnipeAssets.ps1' 0 function Get-SnipeAssets { [CmdletBinding(DefaultParameterSetName="List assets")] param ( [Parameter(ParameterSetName="List assets")][int]$limit, [Parameter(ParameterSetName="List assets")][int]$offset, [Parameter(Position=0,ParameterSetName="List assets")][string]$search, [Parameter(ParameterSetName="List assets")][string]$order_number, [Parameter(ParameterSetName="List assets")][ValidateSet( "id", "name", "asset_tag", "serial", "model", "model_number", "last_checkout", "category", "manufacturer", "notes", "expected_checkin", "order_number", "companyName", "location", "image", "status_label", "assigned_to", "created_at", "purchase_date", "purchase_cost" )][string]$sort, [Parameter(ParameterSetName="List assets")][ValidateSet("asc","desc")][string]$order, [Parameter(ParameterSetName="List assets")][int]$model_id, [Parameter(ParameterSetName="List assets")][int]$category_id, [Parameter(ParameterSetName="List assets")][int]$manufacturer_id, [Parameter(ParameterSetName="List assets")][int]$company_id, [Parameter(ParameterSetName="List assets")][int]$location_id, [Parameter(ParameterSetName="List assets")][ValidateSet( "RTD", "Deployed", "Undeployable", "Deleted", "Archived", "Requestable" )][string]$status, [Parameter(ParameterSetName="List assets")][int]$status_id, [Parameter(Mandatory,ParameterSetName="Get asset by id")][int]$id, [Parameter(Mandatory,ParameterSetName="Get asset by asset_tag")][string]$asset_tag, [Parameter(Mandatory,ParameterSetName="Get asset by serial")][string]$serial, [Parameter(ParameterSetName="List assets by audit_due")][switch]$audit_due, [Parameter(ParameterSetName="List assets by audit_overdue")][switch]$audit_overdue ) $uri = "$(Get-SnipeEndpoint)/hardware" switch ($PsCmdlet.ParameterSetName) { "List assets" { $PSBoundParameters.Keys.ForEach({ $key = $_ $value = $PSBoundParameters.$key if (([array]$PSBoundParameters.Keys)[0] -eq $key) { $delimiter = "?" } else { $delimiter = "&" } $uri = "$uri$delimiter$key=$value" }) } "Get asset by id" { $uri = "$uri/$id" } "Get asset by asset_tag" { $uri = "$uri/bytag/$asset_tag" } "Get asset by serial" { $uri = "$uri/byserial/$serial" } "List assets by audit_due" { $uri = "$uri/audit/due" } "List assets by audit_overdue" { $uri = "$uri/audit/overdue" } } Invoke-SnipeMethod -Method "GET" -Uri $uri } #EndRegion './Public/Get-SnipeAssets.ps1' 88 #Region './Public/Get-SnipeCategories.ps1' 0 function Get-SnipeCategories { [CmdletBinding(DefaultParameterSetName="List categories")] param ( [Parameter(Position=0,ParameterSetName="List categories")][string]$name, [Parameter(ParameterSetName="List categories")][int]$limit, [Parameter(ParameterSetName="List categories")][int]$offset, [Parameter(ParameterSetName="List categories")][string]$search, [Parameter(ParameterSetName="List categories")][string]$sort, [Parameter(ParameterSetName="List categories")][ValidateSet("asc","desc")][string]$order, [Parameter(ParameterSetName="List categories")][int]$category_id, [Parameter(ParameterSetName="List categories")][string]$category_type, [Parameter(ParameterSetName="List categories")][ValidateSet("true","false")][string]$use_default_eula, [Parameter(ParameterSetName="List categories")][ValidateSet("true","false")][string]$require_acceptance, [Parameter(ParameterSetName="List categories")][ValidateSet("true","false")][string]$checkin_email, [Parameter(Mandatory,ParameterSetName="Get category by id")][int]$id ) $uri = "$(Get-SnipeEndpoint)/categories" switch ($PsCmdlet.ParameterSetName) { "List categories" { $PSBoundParameters.Keys.ForEach({ $key = $_ $value = $PSBoundParameters.$key if (([array]$PSBoundParameters.Keys)[0] -eq $key) { $delimiter = "?" } else { $delimiter = "&" } $uri = "$uri$delimiter$key=$value" }) } "Get category by id" { $uri = "$uri/$id" } } Invoke-SnipeMethod -Method "GET" -Uri $uri } #EndRegion './Public/Get-SnipeCategories.ps1' 42 #Region './Public/Get-SnipeCompanies.ps1' 0 function Get-SnipeCompanies { [CmdletBinding(DefaultParameterSetName="List companies")] param ( [Parameter(Position=0,ParameterSetName="List companies")][string]$name, [Parameter(Mandatory,ParameterSetName="Get company by id")][int]$id ) $uri = "$(Get-SnipeEndpoint)/companies" switch ($PsCmdlet.ParameterSetName) { "List companies" { $PSBoundParameters.Keys.ForEach({ $key = $_ $value = $PSBoundParameters.$key if (([array]$PSBoundParameters.Keys)[0] -eq $key) { $delimiter = "?" } else { $delimiter = "&" } $uri = "$uri$delimiter$key=$value" }) } "Get company by id" { $uri = "$uri/$id" } } Invoke-SnipeMethod -Method "GET" -Uri $uri } #EndRegion './Public/Get-SnipeCompanies.ps1' 32 #Region './Public/Get-SnipeConsumables.ps1' 0 function Get-SnipeConsumables { [CmdletBinding(DefaultParameterSetName="List consumables")] param ( [Parameter(Position=0,ParameterSetName="List consumables")][string]$name, [Parameter(ParameterSetName="List consumables")][int]$limit, [Parameter(ParameterSetName="List consumables")][int]$offset, [Parameter(ParameterSetName="List consumables")][string]$search, [Parameter(ParameterSetName="List consumables")][string]$order_number, [Parameter(ParameterSetName="List consumables")][ValidateSet( "id", "name", "asset_tag", "serial", "model", "model_number", "last_checkout", "category", "manufacturer", "notes", "expected_checkin", "order_number", "companyName", "location", "image", "status_label", "assigned_to", "created_at", "purchase_date", "purchase_cost" )][string]$sort, [Parameter(ParameterSetName="List consumables")][ValidateSet("asc","desc")][string]$order, [Parameter(ParameterSetName="List consumables")][ValidateSet("true","false")][string]$expand, [Parameter(ParameterSetName="List consumables")][int]$category_id, [Parameter(ParameterSetName="List consumables")][int]$company_id, [Parameter(ParameterSetName="List consumables")][int]$manufacturer_id, [Parameter(Mandatory,ParameterSetName="Get consumable by id")][int]$id ) $uri = "$(Get-SnipeEndpoint)/consumables" switch ($PsCmdlet.ParameterSetName) { "List consumables" { $PSBoundParameters.Keys.ForEach({ $key = $_ $value = $PSBoundParameters.$key if (([array]$PSBoundParameters.Keys)[0] -eq $key) { $delimiter = "?" } else { $delimiter = "&" } $uri = "$uri$delimiter$key=$value" }) } "Get consumable by id" { $uri = "$uri/$id" } } Invoke-SnipeMethod -Method "GET" -Uri $uri } #EndRegion './Public/Get-SnipeConsumables.ps1' 63 #Region './Public/Get-SnipeDepartments.ps1' 0 function Get-SnipeDepartments { [CmdletBinding(DefaultParameterSetName="List departments")] param ( [Parameter(Position=0,ParameterSetName="List departments")][string]$name, [Parameter(ParameterSetName="List departments")][int]$company_id, [Parameter(ParameterSetName="List departments")][int]$manager_id, [Parameter(ParameterSetName="List departments")][int]$location_id, [Parameter(Mandatory,ParameterSetName="Get department by id")][int]$id ) $uri = "$(Get-SnipeEndpoint)/departments" switch ($PsCmdlet.ParameterSetName) { "List departments" { $PSBoundParameters.Keys.ForEach({ $key = $_ $value = $PSBoundParameters.$key if (([array]$PSBoundParameters.Keys)[0] -eq $key) { $delimiter = "?" } else { $delimiter = "&" } $uri = "$uri$delimiter$key=$value" }) } "Get department by id" { $uri = "$uri/$id" } } Invoke-SnipeMethod -Method "GET" -Uri $uri } #EndRegion './Public/Get-SnipeDepartments.ps1' 35 #Region './Public/Get-SnipeFields.ps1' 0 function Get-SnipeFields { [CmdletBinding(DefaultParameterSetName="List fields")] param ( [Parameter(Mandatory,ParameterSetName="Get field by id")][int]$id, [Parameter(ParameterSetName="List fields")][switch]$listField ) $uri = "$(Get-SnipeEndpoint)/fields" switch ($PsCmdlet.ParameterSetName) { "Get field by id" { $uri = "$uri/$id" } } Invoke-SnipeMethod -Method "GET" -Uri $uri } #EndRegion './Public/Get-SnipeFields.ps1' 18 #Region './Public/Get-SnipeFieldsets.ps1' 0 function Get-SnipeFieldsets { [CmdletBinding(DefaultParameterSetName="List fieldsets")] param ( [Parameter(Mandatory,ParameterSetName="Get fieldset by id")][int]$id, [Parameter(ParameterSetName="List fieldsets")][switch]$listfieldsets ) $uri = "$(Get-SnipeEndpoint)/fieldsets" switch ($PsCmdlet.ParameterSetName) { "Get fieldset by id" { $uri = "$uri/$id" } } Invoke-SnipeMethod -Method "GET" -Uri $uri } #EndRegion './Public/Get-SnipeFieldsets.ps1' 18 #Region './Public/Get-SnipeGroups.ps1' 0 function Get-SnipeGroups { [CmdletBinding(DefaultParameterSetName="List groups")] param ( [Parameter(Position=0,ParameterSetName="List groups")][string]$name, [Parameter(Mandatory,ParameterSetName="Get group by id")][int]$id ) $uri = "$(Get-SnipeEndpoint)/groups" switch ($PsCmdlet.ParameterSetName) { "List groups" { $PSBoundParameters.Keys.ForEach({ $key = $_ $value = $PSBoundParameters.$key if (([array]$PSBoundParameters.Keys)[0] -eq $key) { $delimiter = "?" } else { $delimiter = "&" } $uri = "$uri$delimiter$key=$value" }) } "Get group by id" { $uri = "$uri/$id" } } Invoke-SnipeMethod -Method "GET" -Uri $uri } #EndRegion './Public/Get-SnipeGroups.ps1' 32 #Region './Public/Get-SnipeLocations.ps1' 0 function Get-SnipeLocations { <# .SYNOPSIS Gets locations from Snipe-IT .LINK List locations: https://snipe-it.readme.io/reference/locations .LINK Get location by id: https://snipe-it.readme.io/reference/locations-1 .EXAMPLE Get-SnipeLocation Returns all locations from Snipe-IT. .EXAMPLE Get-SnipeLocation -name Home Returns location based on name. .EXAMPLE Get-SnipeLocation -search VGS Returns locations that have a name that matches the string "VGS". Uses wildcards. .EXAMPLE Get-SnipeLocation -id 1 Returns location based on the given id. #> [CmdletBinding(DefaultParameterSetName="List locations")] param ( [Parameter(Position=0,ParameterSetName="List locations")][ValidateScript({ $_ -in (Get-SnipeLocations).name })][string]$name, [Parameter(ParameterSetName="List locations")][int]$limit, [Parameter(ParameterSetName="List locations")][int]$offset, [Parameter(ParameterSetName="List locations")][string]$search, [Parameter(ParameterSetName="List locations")][string]$sort, [Parameter(ParameterSetName="List locations")][ValidateSet("asc","desc")][string]$order, [Parameter(ParameterSetName="List locations")][string]$address, [Parameter(ParameterSetName="List locations")][string]$address2, [Parameter(ParameterSetName="List locations")][string]$city, [Parameter(ParameterSetName="List locations")][string]$zip, [Parameter(ParameterSetName="List locations")][string]$country, [Parameter(Mandatory,ParameterSetName="Get location by id")][int]$id ) $uri = "$(Get-SnipeEndpoint)/locations" switch ($PsCmdlet.ParameterSetName) { "List locations" { $PSBoundParameters.Keys.ForEach({ $key = $_ $value = $PSBoundParameters.$key if (([array]$PSBoundParameters.Keys)[0] -eq $key) { $delimiter = "?" } else { $delimiter = "&" } $uri = "$uri$delimiter$key=$value" }) } "Get location by id" { $uri = "$uri/$id" } } Invoke-SnipeMethod -Method "GET" -Uri $uri } #EndRegion './Public/Get-SnipeLocations.ps1' 67 #Region './Public/Get-SnipeMaintenances.ps1' 0 function Get-SnipeMaintenances { [CmdletBinding(DefaultParameterSetName="List maintenances")] param ( [Parameter(ParameterSetName="List maintenances")][int]$limit, [Parameter(ParameterSetName="List maintenances")][int]$offset, [Parameter(Position=0,ParameterSetName="List maintenances")][string]$search, [Parameter(ParameterSetName="List maintenances")][string]$sort, [Parameter(ParameterSetName="List maintenances")][string]$order, [Parameter(ParameterSetName="List maintenances")][int]$asset_id ) $uri = "$(Get-SnipeEndpoint)/maintenances" switch ($PsCmdlet.ParameterSetName) { "List maintenances" { $PSBoundParameters.Keys.ForEach({ $key = $_ $value = $PSBoundParameters.$key if (([array]$PSBoundParameters.Keys)[0] -eq $key) { $delimiter = "?" } else { $delimiter = "&" } $uri = "$uri$delimiter$key=$value" }) } } Invoke-SnipeMethod -Method "GET" -Uri $uri } #EndRegion './Public/Get-SnipeMaintenances.ps1' 33 #Region './Public/Get-SnipeManufacturers.ps1' 0 function Get-SnipeManufacturers { [CmdletBinding(DefaultParameterSetName="List manufacturers")] param ( [Parameter(Position=0,ParameterSetName="List manufacturers")][string]$name, [Parameter(ParameterSetName="List manufacturers")][string]$url, [Parameter(ParameterSetName="List manufacturers")][string]$support_url, [Parameter(ParameterSetName="List manufacturers")][string]$support_phone, [Parameter(ParameterSetName="List manufacturers")][string]$support_email, [Parameter(Mandatory,ParameterSetName="Get manufacturer by id")][int]$id ) $uri = "$(Get-SnipeEndpoint)/manufacturers" switch ($PsCmdlet.ParameterSetName) { "List manufacturers" { $PSBoundParameters.Keys.ForEach({ $key = $_ $value = $PSBoundParameters.$key if (([array]$PSBoundParameters.Keys)[0] -eq $key) { $delimiter = "?" } else { $delimiter = "&" } $uri = "$uri$delimiter$key=$value" }) } "Get manufacturer by id" { $uri = "$uri/$id" } } Invoke-SnipeMethod -Method "GET" -Uri $uri } #EndRegion './Public/Get-SnipeManufacturers.ps1' 36 #Region './Public/Get-SnipeModels.ps1' 0 function Get-SnipeModels { [CmdletBinding(DefaultParameterSetName="List models")] param ( [Parameter(Position=0,ParameterSetName="List models")][string]$search, [Parameter(ParameterSetName="List models")][int]$limit, [Parameter(ParameterSetName="List models")][int]$offset, [Parameter(ParameterSetName="List models")][string]$sort, [Parameter(ParameterSetName="List models")][ValidateSet("asc","desc")][int]$order, [Parameter(Mandatory,ParameterSetName="Get model by id")][int]$id ) $uri = "$(Get-SnipeEndpoint)/models" switch ($PsCmdlet.ParameterSetName) { "List models" { $PSBoundParameters.Keys.ForEach({ $key = $_ $value = $PSBoundParameters.$key if (([array]$PSBoundParameters.Keys)[0] -eq $key) { $delimiter = "?" } else { $delimiter = "&" } $uri = "$uri$delimiter$key=$value" }) } "Get model by id" { $uri = "$uri/$id" } } Invoke-SnipeMethod -Method "GET" -Uri $uri } #EndRegion './Public/Get-SnipeModels.ps1' 36 #Region './Public/Get-SnipeSuppliers.ps1' 0 function Get-SnipeSuppliers { [CmdletBinding(DefaultParameterSetName="List suppliers")] param ( [Parameter(Position=0,ParameterSetName="List suppliers")][string]$name, [Parameter(ParameterSetName="List suppliers")][string]$address, [Parameter(ParameterSetName="List suppliers")][string]$address2, [Parameter(ParameterSetName="List suppliers")][string]$city, [Parameter(ParameterSetName="List suppliers")][string]$zip, [Parameter(ParameterSetName="List suppliers")][string]$country, [Parameter(ParameterSetName="List suppliers")][string]$fax, [Parameter(ParameterSetName="List suppliers")][string]$email, [Parameter(ParameterSetName="List suppliers")][string]$url, [Parameter(ParameterSetName="List suppliers")][string]$notes, [Parameter(Mandatory,ParameterSetName="Get supplier by id")][int]$id ) $uri = "$(Get-SnipeEndpoint)/suppliers" switch ($PsCmdlet.ParameterSetName) { "List suppliers" { $PSBoundParameters.Keys.ForEach({ $key = $_ $value = $PSBoundParameters.$key if (([array]$PSBoundParameters.Keys)[0] -eq $key) { $delimiter = "?" } else { $delimiter = "&" } $uri = "$uri$delimiter$key=$value" }) } "Get supplier by id" { $uri = "$uri/$id" } } Invoke-SnipeMethod -Method "GET" -Uri $uri } #EndRegion './Public/Get-SnipeSuppliers.ps1' 41 #Region './Public/Get-SnipeUsers.ps1' 0 function Get-SnipeUsers { [CmdletBinding(DefaultParameterSetName="List users")] param ( [Parameter(Position=0,ParameterSetName="List users")][string]$search, [Parameter(ParameterSetName="List users")][int]$limit, [Parameter(ParameterSetName="List users")][int]$offset, [Parameter(ParameterSetName="List users")][string]$sort, [Parameter(ParameterSetName="List users")][ValidateSet("asc","desc")][string]$order, [Parameter(ParameterSetName="List users")][string]$first_name, [Parameter(ParameterSetName="List users")][string]$last_name, [Parameter(ParameterSetName="List users")][string]$username, [Parameter(ParameterSetName="List users")][string]$email, [Parameter(ParameterSetName="List users")][string]$employee_num, [Parameter(ParameterSetName="List users")][string]$state, [Parameter(ParameterSetName="List users")][string]$zip, [Parameter(ParameterSetName="List users")][string]$country, [Parameter(ParameterSetName="List users")][int]$group_id, [Parameter(ParameterSetName="List users")][int]$department_id, [Parameter(ParameterSetName="List users")][int]$company_id, [Parameter(ParameterSetName="List users")][int]$location_id, [Parameter(ParameterSetName="List users")][ValidateSet("true","false")][string]$deleted, [Parameter(ParameterSetName="List users")][ValidateSet("true","false")][string]$all, [Parameter(ParameterSetName="List users")][ValidateSet("0","1")][int]$ldap_import, [Parameter(ParameterSetName="List users")][int]$asset_count, [Parameter(ParameterSetName="List users")][int]$licenses_count, [Parameter(ParameterSetName="List users")][int]$accessories_count, [Parameter(ParameterSetName="List users")][int]$consumables_count, [Parameter(ParameterSetName="List users")][ValidateSet("0","1")][int]$remote, [Parameter(Mandatory,ParameterSetName="Get user by id")][int]$id ) $uri = "$(Get-SnipeEndpoint)/users" switch ($PsCmdlet.ParameterSetName) { "List users" { $PSBoundParameters.Keys.ForEach({ $key = $_ $value = $PSBoundParameters.$key if (([array]$PSBoundParameters.Keys)[0] -eq $key) { $delimiter = "?" } else { $delimiter = "&" } $uri = "$uri$delimiter$key=$value" }) } "Get user by id" { $uri = "$uri/$id" } } Invoke-SnipeMethod -Method "GET" -Uri $uri } #EndRegion './Public/Get-SnipeUsers.ps1' 56 #Region './Public/New-SnipeAccessToken.ps1' 0 function New-SnipeAccessToken { param ( [string]$accessTokenPath = "$env:USERPROFILE\.creds\Snipe-IT\snipeitAccessToken.xml" ) $apiKey = Read-Host "Enter Snipe-IT API key" -AsSecureString #Create parent folders of the access token file $accessTokenDir = $accessTokenPath.Substring(0, $accessTokenPath.lastIndexOf('\')) if (!(Test-Path $accessTokenDir)) { $null = New-Item -ItemType Directory $accessTokenDir } #Create access token file $apiKey | Export-Clixml $accessTokenPath } #EndRegion './Public/New-SnipeAccessToken.ps1' 17 #Region './Public/New-SnipeEndpoint.ps1' 0 function New-SnipeEndpoint { param ( [string]$endpointPath = "$env:USERPROFILE\.creds\Snipe-IT\snipeitEndpoint.xml" ) $snipeUrl = Read-Host "Enter Snipe-IT url" $endpoint = "$snipeUrl/api/v1" #Create parent folders of the access token file $endpointDir = $endpointPath.Substring(0, $endpointPath.lastIndexOf('\')) if (!(Test-Path $endpointDir)) { New-Item -ItemType Directory $endpointDir | Out-Null } #Create access token file $endpoint | Export-Clixml $endpointPath } #EndRegion './Public/New-SnipeEndpoint.ps1' 18 #Region './Public/New-SnipeLocation.ps1' 0 function New-SnipeLocation { param ( [Parameter(Mandatory)][string]$name, [string]$address, [string]$address2, [string]$state, [string]$country, [string]$city, [string]$zip, [string]$ldap_ou, [int]$parent_id, [string]$currency, [int]$manager_id ) $Body = $null $PSBoundParameters.Keys.ForEach({ [string]$Key = $_ $Value = $PSBoundParameters.$key if ($ParameterExclusion -contains $Key) { return } $Body += @{ $Key = $Value } }) $Splat = @{ "Uri" = "$(Get-SnipeEndpoint)/locations" "Method" = "POST" "Headers" = @{ "Accept" = "application/json" "Content-Type" = "application/json" "Authorization" = "Bearer $(Get-SnipeAccessToken)" } "Body" = [System.Text.Encoding]::UTF8.GetBytes(($Body | ConvertTo-Json -Depth 99)) } Invoke-RestMethod @Splat } #EndRegion './Public/New-SnipeLocation.ps1' 42 #Region './Public/Remove-SnipeLocation.ps1' 0 function Remove-SnipeLocation { [CmdletBinding()] param ( [Parameter(Mandatory)][int]$id ) process { $Splat = @{ "Uri" = "$(Get-SnipeEndpoint)/locations/$id" "Method" = "DELETE" "Headers" = @{ "Accept" = "application/json" "Content-Type" = "application/json" "Authorization" = "Bearer $(Get-SnipeAccessToken)" } } Invoke-RestMethod @Splat } } #EndRegion './Public/Remove-SnipeLocation.ps1' 20 #Region './Public/Update-SnipeUser.ps1' 0 function Update-SnipeUser { [CmdletBinding()] param ( [Parameter(Mandatory)][string]$id, [Parameter(Mandatory)][ValidateSet("PATCH","PUT")][string]$method, [string]$first_name, [string]$last_name, [string]$username, [string]$password, [string]$email, [string]$permissions, [bool]$activated, [string]$phone, [string]$jobtitle, [int]$manager_id, [string]$employee_num, [string]$notes, [int]$company_id, [bool]$two_factor_enrolled, [bool]$two_factor_optin, [int]$department_id, [int]$location_id, [bool]$remote, [array]$groups, [int]$vip, [datetime]$start_date, [datetime]$end_date ) $ParameterExclusion = @("method","id") $Body = $null $PSBoundParameters.Keys.ForEach({ [string]$Key = $_ $Value = $PSBoundParameters.$key if ($ParameterExclusion -contains $Key) { return } switch ($Value) { {($_ -is [bool]) -and ($_ -eq $true)} { $Value = 1 } {($_ -is [bool]) -and ($_ -eq $false)} { $Value = 0 } {$_ -is [array]} { [string]$Value = $Value -join "," } } $Body += @{ $Key = $Value } }) $Splat = @{ "Uri" = "$(Get-SnipeEndpoint)/users/$id" "Method" = $method "Headers" = @{ "Accept" = "application/json" "Content-Type" = "application/json" "Authorization" = "Bearer $(Get-SnipeAccessToken)" } "Body" = [System.Text.Encoding]::UTF8.GetBytes(($Body | ConvertTo-Json -Depth 99)) } Invoke-RestMethod @Splat } #EndRegion './Public/Update-SnipeUser.ps1' 69 |