Added new Ability to create users and update them as well as add new locations

This commit is contained in:
Stephen Maunder 2018-03-17 21:23:11 +00:00
parent eb60cf8824
commit bd9db2d9be
5 changed files with 392 additions and 0 deletions

View file

@ -0,0 +1,38 @@
<#
.SYNOPSIS
# Gets a list of Snipe-it Companies
.PARAMETER url
URL of Snipeit system, can be set using Set-Info command
.PARAMETER apiKey
Users API Key for Snipeit, can be set using Set-Info command
.EXAMPLE
Get-Company -url "https://assets.example.com" -token "token..."
.EXAMPLE
Get-Company -url "https://assets.example.com" -token "token..." | Where-Object {$_.name -eq "Company1" }
#>
function Get-Company()
{
Param(
[parameter(mandatory=$true)]
[string]$url,
[parameter(mandatory=$true)]
[string]$apiKey
)
$Parameters = @{
Uri = "$url/api/v1/companies"
Method = 'Get'
Token = $apiKey
}
$result = Invoke-SnipeitMethod @Parameters
$result
}

View file

@ -0,0 +1,80 @@
<#
.SYNOPSIS
Add a new Model to Snipe-it asset system
.DESCRIPTION
Long description
.PARAMETER name
Name of the Asset Model
.PARAMETER category_id
Category ID that the asset belongs to this can be got using Get-Category
.PARAMETER manufacturer_id
Manufacturer ID that the asset belongs to this can be got using Get-Manufacturer
.PARAMETER fieldset_id
Fieldset ID that the asset uses (Custom fields)
.PARAMETER url
URL of Snipeit system, can be set using Set-Info command
.PARAMETER apiKey
Users API Key for Snipeit, can be set using Set-Info command
.EXAMPLE
New-Model -name "DL380" -manufacturer_id 2 -fieldset_id 2 -category_id 1
#>
function New-Location() {
[CmdletBinding(
SupportsShouldProcess = $true,
ConfirmImpact = "Low"
)]
Param(
[parameter(mandatory = $true)]
[string]$name,
[string]$address,
[string]$address2,
[string]$state,
[string]$country,
[string]$zip,
[parameter(mandatory = $true)]
[string]$url,
[parameter(mandatory = $true)]
[string]$apiKey
)
$Values = @{
name = $name
address = $address
address2 = $address2
state = $state
country = $country
zip = $zip
}
$Body = $Values | ConvertTo-Json;
$Parameters = @{
Uri = "$url/api/v1/locations"
Method = 'post'
Body = $Body
Token = $apiKey
}
If ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
$result = Invoke-SnipeitMethod @Parameters
}
$result
}

View file

@ -0,0 +1,143 @@
<#
.SYNOPSIS
Short description
.DESCRIPTION
Long description
.PARAMETER firstName
Parameter description
.PARAMETER lastName
Parameter description
.PARAMETER userName
Parameter description
.PARAMETER jobTitle
Parameter description
.PARAMETER email
Parameter description
.PARAMETER phone
Parameter description
.PARAMETER company_id
Parameter description
.PARAMETER location_id
Parameter description
.PARAMETER department_id
Parameter description
.PARAMETER manager_id
Parameter description
.PARAMETER employee_num
Parameter description
.PARAMETER ldap_user
Parameter description
.PARAMETER url
Parameter description
.PARAMETER apiKey
Parameter description
.EXAMPLE
An example
.NOTES
General notes
#>
function New-User() {
[CmdletBinding(
SupportsShouldProcess = $true,
ConfirmImpact = "Low"
)]
Param(
[parameter(mandatory = $true)]
[string]$firstName,
[parameter(mandatory = $true)]
[string]$lastName,
[parameter(mandatory = $true)]
[string]$userName,
[string]$jobTitle,
[string]$email,
[string]$phone,
[int]$company_id,
[int]$location_id,
[int]$department_id,
[int]$manager_id,
[string]$employee_num,
[bool]$ldap_user = $false,
[parameter(mandatory = $true)]
[string]$url,
[parameter(mandatory = $true)]
[string]$apiKey
)
$Values = @{
first_name = $firstName
last_name = $lastName
username = $userName
email = $email
phone = $phone
company_id = $company_id
location_id = $location_id
department_id = $department_id
manager_id = $manager_id
jobtitle = $jobTitle
employee_num = $employee_num
notes = "Imported using SnipeitPS Script"
activated = 1
}
if ($ldap_user -eq $false) {
$ldap = @{
password = $password
ldap_import = 0
}
$Values += $ldap
}
else {
$ldap = @{
ldap_import = 1
}
$Values += $ldap
}
$Body = $Values | ConvertTo-Json;
$Parameters = @{
Uri = "$url/api/v1/users"
Method = 'post'
Body = $Body
Token = $apiKey
}
If ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
$result = Invoke-SnipeitMethod @Parameters
}
$result
}

View file

@ -0,0 +1,131 @@
<#
.SYNOPSIS
Short description
.DESCRIPTION
Long description
.PARAMETER id
Parameter description
.PARAMETER first_name
Parameter description
.PARAMETER last_name
Parameter description
.PARAMETER userName
Parameter description
.PARAMETER jobTitle
Parameter description
.PARAMETER email
Parameter description
.PARAMETER phone
Parameter description
.PARAMETER company_id
Parameter description
.PARAMETER location_id
Parameter description
.PARAMETER department_id
Parameter description
.PARAMETER manager_id
Parameter description
.PARAMETER employee_num
Parameter description
.PARAMETER activated
Parameter description
.PARAMETER notes
Parameter description
.PARAMETER url
Parameter description
.PARAMETER apiKey
Parameter description
.EXAMPLE
An example
.NOTES
General notes
#>
function Set-User() {
[CmdletBinding(
SupportsShouldProcess = $true,
ConfirmImpact = "Medium"
)]
Param(
[parameter(mandatory = $true)]
[int]$id,
[string]$first_name,
[string]$last_name,
[string]$userName,
[string]$jobTitle,
[string]$email,
[string]$phone,
[int]$company_id,
[int]$location_id,
[int]$department_id,
[int]$manager_id,
[string]$employee_num,
[bool]$activated,
[string]$notes,
[parameter(mandatory = $true)]
[string]$url,
[parameter(mandatory = $true)]
[string]$apiKey
)
$Values = @{}
$exclude = @('id', 'url', 'apiKey')
$excludeRegex = [string]::Join('|', $exclude) # create the regex
foreach ($psbp in $PSBoundParameters.GetEnumerator()) {
if ($psbp.Key -notmatch $excludeRegex) {
$Values.Add($psbp.Key, $psbp.Value)
}
}
$Body = $Values | ConvertTo-Json;
$Parameters = @{
Uri = "$url/api/v1/users/$id"
Method = 'PATCH'
Body = $Body
Token = $apiKey
}
If ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
$result = Invoke-SnipeitMethod @Parameters
}
$result
}

Binary file not shown.