Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes on New-SnipeItUser #303

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
73 changes: 73 additions & 0 deletions SnipeitPS/Public/New-SnipeitCustomFieldset.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<#
.SYNOPSIS
Add a new Custom Fieldset to Snipe-it asset system

.DESCRIPTION
Add a new Custom Field Set to Snipe-it asset system

.PARAMETER name
The fieldsets's name

.PARAMETER url
Deprecated parameter, please use Connect-SnipeitPS instead. URL of Snipeit system.

.PARAMETER apiKey
Deprecated parameter, please use Connect-SnipeitPS instead. Users API Key for Snipeit.

.EXAMPLE
New-SnipeitCustomFieldSet -Name "Notebook Fields"
#>

function New-SnipeitCustomFieldSet() {
[CmdletBinding(
SupportsShouldProcess = $true,
ConfirmImpact = "Low"
)]

Param(
[parameter(mandatory = $true)]
[string]$name,

[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

$Parameters = @{
Api = "/api/v1/fieldsets"
Method = 'post'
Body = $Values
}

if ($PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
Set-SnipeitPSLegacyApiKey -apiKey $apikey
}

if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url) {
Set-SnipeitPSLegacyUrl -url $url
}
}

process{
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
}
}
}

10 changes: 9 additions & 1 deletion SnipeitPS/Public/New-SnipeitLicense.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
.PARAMETER purchase_date
Date of license purchase

.PARAMETER purchase_order
Purchase order number of license purchase

.PARAMETER reassignable
Is license reassignable?

Expand Down Expand Up @@ -89,7 +92,6 @@ function New-SnipeitLicense() {

[datetime]$expiration_date,

[ValidateLength(1, 120)]
[mailaddress]$license_email,

[ValidateLength(1, 100)]
Expand All @@ -108,6 +110,8 @@ function New-SnipeitLicense() {

[datetime]$purchase_date,

[string]$purchase_order,

[bool]$reassignable,

[string]$serial,
Expand Down Expand Up @@ -140,6 +144,10 @@ function New-SnipeitLicense() {
$Values['termination_date'] = $Values['termination_date'].ToString("yyyy-MM-dd")
}

if ($Values['license_email']) {
$Values['license_email'] = $Values['license_email'].address
}

$Parameters = @{
Api = "/api/v1/licenses"
Method = 'POST'
Expand Down
2 changes: 1 addition & 1 deletion SnipeitPS/Public/New-SnipeitSupplier.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ function New-SnipeitSupplier() {
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters

$Parameters = @{
Api = "/api/v1/suppilers"
Api = "/api/v1/suppliers"
Method = 'POST'
Body = $Values
}
Expand Down
9 changes: 6 additions & 3 deletions SnipeitPS/Public/New-SnipeitUser.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
.PARAMETER username
Username for user

.PARAMETER active
.PARAMETER activated
Can user log in to snipe-it?

.PARAMETER password
Password for user
Password for user. The password should at least be 8 characters long.

.PARAMETER notes
User Notes
Expand Down Expand Up @@ -63,7 +63,7 @@
Deprecated parameter, please use Connect-SnipeitPS instead. User's API Key for Snipeit.

.EXAMPLE
New-Snipeituser -fist_name It -lastname Snipe -username snipeit -activated $false -company_id 1 -location_id 1 -department_id 1
New-Snipeituser -first_name It -last_name Snipe -username snipeit -activated $false -company_id 1 -location_id 1 -department_id 1
Creates new a new user who can't login to system

.NOTES
Expand All @@ -86,6 +86,8 @@ function New-SnipeitUser() {
[parameter(mandatory = $true)]
[string]$username,

[ValidateScript({$_.Length -ge 8}, ErrorMessage = "Password should be at least 8 characters.")]
[parameter(mandatory = $true)]
[string]$password,

[bool]$activated = $false,
Expand Down Expand Up @@ -122,6 +124,7 @@ function New-SnipeitUser() {
[string]$apiKey
)
begin {

Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name

$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
Expand Down
8 changes: 8 additions & 0 deletions SnipeitPS/Public/Set-SnipeitLicense.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
.PARAMETER purchase_date
Date of license purchase

.PARAMETER purchase_order
Purchase order number of license purchase

.PARAMETER reassignable
Is license reassignable?

Expand Down Expand Up @@ -116,6 +119,8 @@ function Set-SnipeitLicense() {

[datetime]$purchase_date,

[string]$purchase_order,

[bool]$reassignable,

[string]$serial,
Expand Down Expand Up @@ -151,6 +156,9 @@ function Set-SnipeitLicense() {
$Values['termination_date'] = $Values['termination_date'].ToString("yyyy-MM-dd")
}

if ($Values['license_email']) {
$Values['license_email'] = $Values['license_email'].address
}
}

process {
Expand Down
1 change: 1 addition & 0 deletions SnipeitPS/SnipeitPS.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ FunctionsToExport = @(
'New-SnipeitComponent',
'New-SnipeitConsumable',
'New-SnipeitCustomField',
'New-SnipeitCustomFieldSet',
'New-SnipeitDepartment',
'New-SnipeitLicense',
'New-SnipeitLocation',
Expand Down
2 changes: 1 addition & 1 deletion docs/New-SnipeitAsset.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Specifying asset tag when creating asset

### EXAMPLE 3
```
New-SnipeitAsset -status_id 1 -model_id 1 -name "Machine1" -customfields = @{ "_snipeit_os_5" = "Windows 10 Pro" }
New-SnipeitAsset -status_id 1 -model_id 1 -name "Machine1" -customfields @{ "_snipeit_os_5" = "Windows 10 Pro" }
Using customfields when creating asset.
```

Expand Down
2 changes: 1 addition & 1 deletion docs/Set-SnipeitAsset.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Set-SnipeitAsset -id 1 -status_id 1 -model_id 1 -name "Machine1"

### EXAMPLE 2
```
Set-SnipeitAsset -id 1 -name "Machine1" -customfields = @{ "_snipeit_os_5" = "Windows 10 Pro" ; "_snipeit_os_version" = "1909" }
Set-SnipeitAsset -id 1 -name "Machine1" -customfields @{ "_snipeit_os_5" = "Windows 10 Pro" ; "_snipeit_os_version" = "1909" }
```

### EXAMPLE 3
Expand Down