SnipeitPS/SnipeitPS/Public/New-SnipeitUser.ps1

135 lines
2.6 KiB
PowerShell
Raw Normal View History

<#
.SYNOPSIS
2021-05-19 15:51:49 +03:00
Creates a new user
.DESCRIPTION
2021-05-19 15:51:49 +03:00
Creates a new user to Snipe-IT system
.PARAMETER first_name
2021-05-19 15:51:49 +03:00
Users first name
.PARAMETER last_name
2021-05-19 15:51:49 +03:00
Users last name
.PARAMETER username
2021-05-19 15:51:49 +03:00
Username for user
.PARAMETER active
2021-05-19 15:51:49 +03:00
Can user log in to snipe-it?
.PARAMETER notes
2021-05-19 15:51:49 +03:00
User Notes
.PARAMETER jobtitle
2021-05-19 15:51:49 +03:00
Users job tittle
.PARAMETER email
2021-05-19 15:51:49 +03:00
email address
.PARAMETER phone
2021-05-19 15:51:49 +03:00
Phone number
.PARAMETER company_id
2021-05-19 15:51:49 +03:00
ID number of company users belogs to
.PARAMETER location_id
2021-05-19 15:51:49 +03:00
ID number of localtion
.PARAMETER department_id
2021-05-19 15:51:49 +03:00
ID number of department
.PARAMETER manager_id
2021-05-19 15:51:49 +03:00
ID number of manager
.PARAMETER employee_num
2021-05-19 15:51:49 +03:00
Employeenumber
.PARAMETER ldap_import
Mark user as import from ldap
.PARAMETER url
2021-06-08 20:23:32 +03:00
URL of Snipeit system, can be set using Set-SnipeitInfo command
.PARAMETER apiKey
2021-06-08 20:23:32 +03:00
User's API Key for Snipeit, can be set using Set-SnipeitInfo command
.EXAMPLE
2021-06-08 20:23:32 +03:00
New-Snipeituser -fist_name It -lastname Snipe -username snipeit -activated $false -company_id 1 -location_id 1 -department_id 1
2021-05-19 15:51:49 +03:00
Creates new a new user who can't login to system
.NOTES
General notes
2021-05-19 15:51:49 +03:00
#>
2021-06-08 20:23:32 +03:00
function New-SnipeitUser() {
[CmdletBinding(
SupportsShouldProcess = $true,
ConfirmImpact = "Low"
)]
Param(
[parameter(mandatory = $true)]
[string]$first_name,
[parameter(mandatory = $true)]
[string]$last_name,
[parameter(mandatory = $true)]
[string]$username,
2018-06-23 20:10:58 +01:00
[string]$password,
[bool]$activated = $false,
[string]$notes,
[string]$jobtitle,
[string]$email,
[string]$phone,
[int]$company_id,
[int]$location_id,
[int]$department_id,
[int]$manager_id,
[string]$employee_num,
[bool]$ldap_import = $false,
2021-05-17 10:07:17 +03:00
[parameter(mandatory = $true)]
[string]$url,
[parameter(mandatory = $true)]
[string]$apiKey
)
2021-05-17 10:07:17 +03:00
2021-06-08 20:23:32 +03:00
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
2021-05-23 19:23:24 +03:00
2021-06-07 21:27:10 +03:00
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
2021-05-17 10:07:17 +03:00
if ($password ) {
2021-05-17 10:07:17 +03:00
$Values['password_confirmation'] = $password
}
2021-05-17 10:07:17 +03:00
$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
}