SnipeitPS/SnipeitPS/Public/New-SnipeitUser.ps1

160 lines
3.5 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?
2021-06-16 10:37:57 +03:00
.PARAMETER password
Password for user
.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
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
.PARAMETER url
2021-08-02 08:14:38 +03:00
Deprecated parameter, please use Connect-SnipeitPS instead. URL of Snipeit system.
.PARAMETER apiKey
2021-08-02 08:14:38 +03:00
Deprecated parameter, please use Connect-SnipeitPS instead. User's API Key for Snipeit.
.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-07-08 23:59:31 +03:00
[ValidateScript({Test-Path $_})]
[string]$image,
2021-07-31 22:25:13 +03:00
[parameter(mandatory = $false)]
[string]$url,
2021-07-31 22:25:13 +03:00
[parameter(mandatory = $false)]
[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-05-17 10:07:17 +03:00
2021-08-23 18:01:09 +03:00
process {
if ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
$result = Invoke-SnipeitMethod @Parameters
}
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
}
}
}