Public/Set-SnipeitUser.ps1
<# .SYNOPSIS Creates a new user .PARAMETER id ID number of Snipe--It user or array of IDs .DESCRIPTION Creates a new user to Snipe-IT system .PARAMETER first_name Users first name .PARAMETER last_name Users last name .PARAMETER username Username for user .PARAMETER activated Can user log in to snipe-it? .PARAMETER password Password for user .PARAMETER notes User Notes .PARAMETER jobtitle Users job tittle .PARAMETER email email address .PARAMETER phone Phone number .PARAMETER company_id ID number of company users belogs to .PARAMETER location_id ID number of localtion .PARAMETER department_id ID number of department .PARAMETER manager_id ID number of manager .PARAMETER employee_num Employeenumber .PARAMETER ldap_import Mark user as import from ldap .PARAMETER image Image file name and path for item .PARAMETER image_delete Remove current image .PARAMETER RequestType Http request type to send Snipe IT system. Defaults to Patch you could use Put if needed. .PARAMETER url Deprecated parameter, please use Connect-SnipeitPS instead. URL of Snipeit system. .PARAMETER apiKey Deprecated parameter, please use Connect-SnipeitPS instead. User's API Key for Snipeit. .EXAMPLE Update-SnipeitUser -id 3 -fist_name It -lastname Snipe -username snipeit -activated $false -company_id 1 -location_id 1 -department_id 1 Updates user with id 3 .NOTES General notes #> function Set-SnipeitUser() { [CmdletBinding( SupportsShouldProcess = $true, ConfirmImpact = "Medium" )] Param( [parameter(mandatory = $true,ValueFromPipelineByPropertyName)] [int[]]$id, [ValidateLength(1,256)] [string]$first_name, [string]$last_name, [ValidateLength(1,256)] [string]$username, [string]$jobtitle, [string]$email, [string]$phone, [string]$password, [Nullable[System.Int32]]$company_id, [Nullable[System.Int32]]$location_id, [Nullable[System.Int32]]$department_id, [Nullable[System.Int32]]$manager_id, [string]$employee_num, [bool]$activated, [string]$notes, [ValidateScript({Test-Path $_})] [string]$image, [switch]$image_delete=$false, [ValidateSet("Put","Patch")] [string]$RequestType = "Patch", [parameter(mandatory = $false)] [string]$url, [parameter(mandatory = $false)] [string]$apiKey ) 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 } } process{ foreach($user_id in $id) { $Parameters = @{ Api = "/api/v1/users/$user_id" Method = 'PATCH' Body = $Values } if ($PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) { Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." Set-SnipeitPSLegacyApiKey -apiKey $apikey } if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url) { Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." Set-SnipeitPSLegacyUrl -url $url } if ($PSCmdlet.ShouldProcess("ShouldProcess?")) { $result = Invoke-SnipeitMethod @Parameters } $result } } end { # reset legacy sessions if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url -or $PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) { Reset-SnipeitPSLegacyApi } } } |