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
|
|
|
|
2021-06-16 10:37:57 +03:00
|
|
|
.PARAMETER password
|
|
|
|
|
Password for user
|
|
|
|
|
|
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
|
|
|
|
2021-07-08 23:59:31 +03:00
|
|
|
.PARAMETER image
|
2021-07-14 10:53:22 +03:00
|
|
|
User Image file name and path
|
2021-07-08 23:59:31 +03:00
|
|
|
|
2018-03-17 21:23:11 +00:00
|
|
|
.PARAMETER url
|
2021-08-02 08:14:38 +03:00
|
|
|
Deprecated parameter, please use Connect-SnipeitPS instead. URL of Snipeit system.
|
2018-03-17 21:23:11 +00:00
|
|
|
|
|
|
|
|
.PARAMETER apiKey
|
2021-08-02 08:14:38 +03:00
|
|
|
Deprecated parameter, please use Connect-SnipeitPS instead. User's API Key for Snipeit.
|
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-07-08 23:59:31 +03:00
|
|
|
[ValidateScript({Test-Path $_})]
|
|
|
|
|
[string]$image,
|
|
|
|
|
|
2021-07-31 22:25:13 +03:00
|
|
|
[parameter(mandatory = $false)]
|
2018-03-17 21:23:11 +00:00
|
|
|
[string]$url,
|
|
|
|
|
|
2021-07-31 22:25:13 +03:00
|
|
|
[parameter(mandatory = $false)]
|
2018-03-17 21:23:11 +00:00
|
|
|
[string]$apiKey
|
|
|
|
|
)
|
2021-08-23 18:01:09 +03:00
|
|
|
begin {
|
|
|
|
|
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
|
|
|
|
|
|
|
|
|
|
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
|
|
|
|
|
|
|
|
|
|
if ($password ) {
|
|
|
|
|
$Values['password_confirmation'] = $password
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$Parameters = @{
|
|
|
|
|
Api = "/api/v1/users"
|
|
|
|
|
Method = 'post'
|
|
|
|
|
Body = $Values
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-03 19:44:43 +03:00
|
|
|
if ($PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
2021-08-23 18:01:09 +03:00
|
|
|
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
|
|
|
|
|
Set-SnipeitPSLegacyApiKey -apiKey $apikey
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-03 19:44:43 +03:00
|
|
|
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url) {
|
2021-08-23 18:01:09 +03:00
|
|
|
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
|
|
|
|
|
Set-SnipeitPSLegacyUrl -url $url
|
|
|
|
|
}
|
2021-02-11 15:23:34 +02:00
|
|
|
}
|
2021-05-17 10:07:17 +03:00
|
|
|
|
2021-08-23 18:01:09 +03:00
|
|
|
process {
|
|
|
|
|
if ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
|
|
|
|
|
$result = Invoke-SnipeitMethod @Parameters
|
|
|
|
|
}
|
2018-03-17 21:23:11 +00:00
|
|
|
|
2021-08-23 18:01:09 +03:00
|
|
|
$result
|
2021-08-02 08:14:38 +03:00
|
|
|
}
|
|
|
|
|
|
2021-08-23 18:01:09 +03:00
|
|
|
end {
|
|
|
|
|
# reset legacy sessions
|
2021-09-03 19:44:43 +03:00
|
|
|
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url -or $PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
2021-08-23 18:01:09 +03:00
|
|
|
Reset-SnipeitPSLegacyApi
|
|
|
|
|
}
|
2021-08-23 17:12:29 +03:00
|
|
|
}
|
2018-03-17 21:23:11 +00:00
|
|
|
}
|