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