From 2e501feab42f319151470dbc3ede985aee7d8d1a Mon Sep 17 00:00:00 2001 From: Stephen Maunder Date: Sat, 18 Nov 2017 18:18:41 +0000 Subject: [PATCH 01/12] Update build process --- .vscode/launch.json | 33 ++++ .vscode/settings.json | 15 ++ .vscode/tasks.json | 56 +++++++ CHANGELOG.md | 8 + SnipeItPS.build.ps1 | 100 +++++++++++-- SnipeitPS/Public/Assets.psm1 | 52 +++---- SnipeitPS/Public/Categories.psm1 | 6 +- SnipeitPS/Public/Components.psm1 | 30 ++-- SnipeitPS/Public/Manufacturers.psm1 | 18 +-- SnipeitPS/Public/Models.psm1 | 20 +-- SnipeitPS/Public/Set-Info.psm1 | 2 +- SnipeitPS/Public/Status.psm1 | 8 +- SnipeitPS/Public/Users.psm1 | 8 +- Tests/SnipeItPS.Tests.ps1 | 224 ++++++++++++++++++++++++---- 14 files changed, 460 insertions(+), 120 deletions(-) create mode 100644 .vscode/launch.json create mode 100644 .vscode/settings.json create mode 100644 .vscode/tasks.json create mode 100644 CHANGELOG.md diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..8f51e52 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,33 @@ +{ + "version": "0.2.0", + "configurations": [{ + "type": "PowerShell", + "request": "launch", + "name": "PowerShell Pester Tests", + "script": "Invoke-Pester", + "args": [], + "cwd": "${workspaceRoot}" + }, + { + "type": "PowerShell", + "request": "launch", + "name": "PowerShell Launch (current file)", + "script": "${file}", + "args": [], + "cwd": "${file}" + }, + { + "type": "PowerShell", + "request": "attach", + "name": "PowerShell Attach to Host Process", + "processId": "${command.PickPSHostProcess}", + "runspaceId": 1 + }, + { + "type": "PowerShell", + "request": "launch", + "name": "PowerShell Interactive Session", + "cwd": "${workspaceRoot}" + } + ] +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..0cd992e --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,15 @@ +// Place your settings in this file to overwrite default and user settings. +{ + "files.encoding": "utf8", + "files.eol": "\r\n", + "files.trimTrailingWhitespace": true, + "files.insertFinalNewline": true, + "editor.tabSize": 4, + "[markdown]": { + "editor.wordwrap": "on", + "editor.renderWhitespace": "all", + "editor.acceptSuggestionOnEnter": false, + "editor.rulers": [80], + "editor.trimAutoWhitespace": false + }, +} diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..602228b --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,56 @@ +// Available variables which can be used inside of strings. +// ${workspaceRoot}: the root folder of the team +// ${file}: the current opened file +// ${relativeFile}: the current opened file relative to workspaceRoot +// ${fileBasename}: the current opened file's basename +// ${fileDirname}: the current opened file's dirname +// ${fileExtname}: the current opened file's extension +// ${cwd}: the current working directory of the spawned process +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + // Start PowerShell + "windows": { + "command": "${env:windir}\\sysnative\\windowspowershell\\v1.0\\PowerShell.exe", + "args": [ + "-NoProfile", + "-ExecutionPolicy", + "Bypass" + ] + }, + "linux": { + "command": "/usr/bin/powershell", + "args": [ + "-NoProfile" + ] + }, + "osx": { + "command": "/usr/local/bin/powershell", + "args": [ + "-NoProfile" + ] + }, + // Show the output window always + "showOutput": "always", + // Associate with test task runner + "tasks": [{ + "taskName": "Build Help", + "suppressTaskName": true, + "args": [ + "Write-Host 'Invoking platyPS'; New-ExternalHelp -Path .\\docs\\en-US -OutputPath .\\ConfluencePS\\en-US -Force;", + "Invoke-Command { Write-Host 'Completed Build task in task runner.' }" + ] + }, + { + "taskName": "Test", + "suppressTaskName": true, + "isTestCommand": true, + "args": [ + "Write-Host 'Invoking Pester'; Invoke-Pester -PesterOption @{IncludeVSCodeMarker=$true};", + "Invoke-Command { Write-Host 'Completed Test task in task runner.' }" + ], + "problemMatcher": "$pester" + } + ] +} \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..5dc4d10 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,8 @@ +# Change Log + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](http://keepachangelog.com/), +and this project adheres to [Semantic Versioning](http://semver.org/). + +## [1.0] - 2017-11-18 diff --git a/SnipeItPS.build.ps1 b/SnipeItPS.build.ps1 index b798928..ee9bb33 100644 --- a/SnipeItPS.build.ps1 +++ b/SnipeItPS.build.ps1 @@ -10,15 +10,20 @@ if ($PSBoundParameters.ContainsKey('Verbose')) { if (!($env:releasePath)) { $releasePath = "$BuildRoot\Release" } -else { +elseif ($env:releasePath) { $releasePath = $env:releasePath } +else { + $releasePath = "$($pwd.Path)\Release" +} $env:PSModulePath = "$($env:PSModulePath);$releasePath" +Import-Module BuildHelpers # Ensure Invoke-Build works in the most strict mode. Set-StrictMode -Version Latest +# region debug information task ShowDebug { Write-Build Gray Write-Build Gray ('Project name: {0}' -f $env:APPVEYOR_PROJECT_NAME) @@ -42,12 +47,80 @@ task ShowDebug { Write-Build Gray } +# Synopsis: Install pandoc to .\Tools\ +task InstallPandoc -If (-not (Test-Path Tools\pandoc.exe)) { + # Setup + if (-not (Test-Path "$BuildRoot\Tools")) { + $null = New-Item -Path "$BuildRoot\Tools" -ItemType Directory + } + + # Get latest bits + $latestRelease = "https://github.com/jgm/pandoc/releases/download/1.19.2.1/pandoc-1.19.2.1-windows.msi" + Invoke-WebRequest -Uri $latestRelease -OutFile "$($env:temp)\pandoc.msi" + + # Extract bits + $null = New-Item -Path $env:temp\pandoc -ItemType Directory -Force + Start-Process -Wait -FilePath msiexec.exe -ArgumentList " /qn /a `"$($env:temp)\pandoc.msi`" targetdir=`"$($env:temp)\pandoc\`"" + + # Move to Tools folder + Copy-Item -Path "$($env:temp)\pandoc\Pandoc\pandoc.exe" -Destination "$BuildRoot\Tools\" + Copy-Item -Path "$($env:temp)\pandoc\Pandoc\pandoc-citeproc.exe" -Destination "$BuildRoot\Tools\" + + # Clean + Remove-Item -Path "$($env:temp)\pandoc" -Recurse -Force +} +# endregion + +# region test +task Test RapidTest + +# Synopsis: Using the "Fast" Test Suit +task RapidTest PesterTests +# Synopsis: Using the complete Test Suit, which includes all supported Powershell versions +task FullTest TestVersions + +# Synopsis: Warn about not empty git status if .git exists. +task GitStatus -If (Test-Path .git) { + $status = exec { git status -s } + if ($status) { + Write-Warning "Git status: $($status -join ', ')" + } +} + +task TestVersions TestPS3, TestPS4, TestPS4, TestPS5 +task TestPS3 { + exec {powershell.exe -Version 3 -NoProfile Invoke-Build PesterTests} +} +task TestPS4 { + exec {powershell.exe -Version 4 -NoProfile Invoke-Build PesterTests} +} +task TestPS5 { + exec {powershell.exe -Version 5 -NoProfile Invoke-Build PesterTests} +} + +# Synopsis: Invoke Pester Tests +task PesterTests, { + try { + $result = Invoke-Pester -PassThru -OutputFile "$BuildRoot\TestResult.xml" -OutputFormat "NUnitXml" + if ($env:APPVEYOR_PROJECT_NAME) { + Add-TestResultToAppveyor -TestFile "$BuildRoot\TestResult.xml" + Remove-Item "$BuildRoot\TestResult.xml" -Force + } + assert ($result.FailedCount -eq 0) "$($result.FailedCount) Pester test(s) failed." + } + catch { + throw + } +} +# endregion + # region build # Synopsis: Build shippable release -task Build GenerateRelease, UpdateManifest +task Build GenerateRelease, ConvertMarkdown, UpdateManifest + # Synopsis: Generate .\Release structure -task GenerateRelease { +task GenerateRelease, { # Setup if (-not (Test-Path "$releasePath\SnipeitPS")) { $null = New-Item -Path "$releasePath\SnipeitPS" -ItemType Directory @@ -56,26 +129,20 @@ task GenerateRelease { # Copy module Copy-Item -Path "$BuildRoot\SnipeitPS\*" -Destination "$releasePath\SnipeitPS" -Recurse -Force # Copy additional files - <#$additionalFiles = @( + $additionalFiles = @( "$BuildRoot\CHANGELOG.md" "$BuildRoot\LICENSE" "$BuildRoot\README.md" ) - Copy-Item -Path $additionalFiles -Destination "$releasePath\SnipeitPS" -Force#> + Copy-Item -Path $additionalFiles -Destination "$releasePath\SnipeitPS" -Force } # Synopsis: Update the manifest of the module task UpdateManifest GetVersion, { - $ModuleAlias = (Get-Alias | Where source -eq JiraPS) - - Remove-Module JiraPS -ErrorAction SilentlyContinue - Import-Module "$releasePath\SnipeitPS\SnipeitPS.psd1" Update-Metadata -Path "$releasePath\SnipeitPS\SnipeitPS.psd1" -PropertyName ModuleVersion -Value $script:Version # Update-Metadata -Path "$releasePath\SnipeitPS\SnipeitPS.psd1" -PropertyName FileList -Value (Get-ChildItem $releasePath\SnipeitPS -Recurse).Name - if ($ModuleAlias) { - Update-Metadata -Path "$releasePath\SnipeitPS\SnipeitPS.psd1" -PropertyName AliasesToExport -Value @($ModuleAlias.Name) - } - Set-ModuleFunctions -Name "$releasePath\SnipeitPS\SnipeitPS.psd1" -FunctionsToExport ([string[]](Get-ChildItem "SnipeitPS\public\*.psm1").BaseName) + $functionsToExport = Get-ChildItem "$BuildRoot\SnipeitPS\Public" | ForEach-Object {$_.BaseName} + Set-ModuleFunctions -Name "$releasePath\SnipeitPS\SnipeitPS.psd1" -FunctionsToExport $functionsToExport } task GetVersion { @@ -96,12 +163,13 @@ task GetVersion { $newRevision } - # endregion + #region Cleaning tasks task Clean RemoveGeneratedFiles + # Synopsis: Remove generated and temp files. task RemoveGeneratedFiles { $itemsToRemove = @( @@ -112,6 +180,6 @@ task RemoveGeneratedFiles { Remove-Item $itemsToRemove -Force -Recurse -ErrorAction 0 } +# endregion - -task . Build, Clean \ No newline at end of file +task . ShowDebug, Clean, Test, Build, Deploy diff --git a/SnipeitPS/Public/Assets.psm1 b/SnipeitPS/Public/Assets.psm1 index 8b695f6..c019f71 100644 --- a/SnipeitPS/Public/Assets.psm1 +++ b/SnipeitPS/Public/Assets.psm1 @@ -9,7 +9,7 @@ URL of Snipeit system, can be set using Set-Info command Users API Key for Snipeit, can be set using Set-Info command .EXAMPLE -Get-Asset -url "https://assets.dip.co.uk" -token "token..." +Get-Asset -url "https://assets.dip.co.uk" -token "token..." .EXAMPLE Get-Asset -url "https://assets.dip.co.uk" -token "token..." | Where-Object {$_.name -eq "SUPPORT23" } @@ -18,11 +18,11 @@ Get-Asset -url "https://assets.dip.co.uk" -token "token..." | Where-Object {$_.n function Get-Asset() { - Param( - [parameter(mandatory=$true)] + Param( + [parameter(mandatory=$true)] [string]$url, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$apiKey ) @@ -35,20 +35,20 @@ function Get-Asset() function New-Asset() { - Param( - [parameter(mandatory=$true)] + Param( + [parameter(mandatory=$true)] [string]$Name, - - [parameter(mandatory=$true)] + + [parameter(mandatory=$true)] [string]$Status_id, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$Model_id, - - [parameter(mandatory=$true)] + + [parameter(mandatory=$true)] [string]$url, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$apiKey, [hashtable] $customfields @@ -74,23 +74,23 @@ function New-Asset() function Set-Asset() { - Param( - [parameter(mandatory=$true)] + Param( + [parameter(mandatory=$true)] [int]$id, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$Name, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$Status_id, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$Model_id, - - [parameter(mandatory=$true)] + + [parameter(mandatory=$true)] [string]$url, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$apiKey, [hashtable] $customfields @@ -115,17 +115,17 @@ function Set-Asset() function Set-AssetOwner() { - Param( - [parameter(mandatory=$true)] + Param( + [parameter(mandatory=$true)] [int]$id, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [int]$user_id, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$url, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$apiKey ) @@ -138,7 +138,7 @@ function Set-AssetOwner() $result = Invoke-Method -Uri "$url/api/v1/hardware/$id/checkout" ` -Method POST ` -Token $apiKey ` - -Body $Body + -Body $Body return $result } diff --git a/SnipeitPS/Public/Categories.psm1 b/SnipeitPS/Public/Categories.psm1 index 31fc78a..c93ce35 100644 --- a/SnipeitPS/Public/Categories.psm1 +++ b/SnipeitPS/Public/Categories.psm1 @@ -1,10 +1,10 @@ function Get-Categories() { - Param( - [parameter(mandatory=$true)] + Param( + [parameter(mandatory=$true)] [string]$url, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$apiKey ) diff --git a/SnipeitPS/Public/Components.psm1 b/SnipeitPS/Public/Components.psm1 index 1b2e785..64cc7cb 100644 --- a/SnipeitPS/Public/Components.psm1 +++ b/SnipeitPS/Public/Components.psm1 @@ -1,10 +1,10 @@ function Get-Component() { - Param( - [parameter(mandatory=$true)] + Param( + [parameter(mandatory=$true)] [string]$url, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$apiKey ) @@ -17,20 +17,20 @@ function Get-Component() function New-Component() { - Param( - [parameter(mandatory=$true)] + Param( + [parameter(mandatory=$true)] [string]$name, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$category_id, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$qty, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$url, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$apiKey ) @@ -52,17 +52,17 @@ function New-Component() function Update-Component() { - Param( - [parameter(mandatory=$true)] + Param( + [parameter(mandatory=$true)] [string]$id, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$qty, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$url, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$apiKey ) @@ -99,4 +99,4 @@ function Checkout-Component($component_id, $asset_id = "") -UserAgent "DI Script/0.1" return $Manufacturers -}#> \ No newline at end of file +}#> diff --git a/SnipeitPS/Public/Manufacturers.psm1 b/SnipeitPS/Public/Manufacturers.psm1 index 410c5bd..def3ee3 100644 --- a/SnipeitPS/Public/Manufacturers.psm1 +++ b/SnipeitPS/Public/Manufacturers.psm1 @@ -1,10 +1,10 @@ function Get-Manufacturers() { - Param( - [parameter(mandatory=$true)] + Param( + [parameter(mandatory=$true)] [string]$url, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$apiKey ) @@ -17,14 +17,14 @@ function Get-Manufacturers() function New-Manufacturer() { - Param( - [parameter(mandatory=$true)] + Param( + [parameter(mandatory=$true)] [string]$Name, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$url, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$apiKey ) @@ -40,6 +40,6 @@ function New-Manufacturer() -Method POST ` -Body $Body ` -Token $apiKey - + $result -} \ No newline at end of file +} diff --git a/SnipeitPS/Public/Models.psm1 b/SnipeitPS/Public/Models.psm1 index b7e39b7..7ceca54 100644 --- a/SnipeitPS/Public/Models.psm1 +++ b/SnipeitPS/Public/Models.psm1 @@ -1,11 +1,11 @@ function Get-Models() { - Param( - [parameter(mandatory=$true)] + Param( + [parameter(mandatory=$true)] [string]$url, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$apiKey ) @@ -20,22 +20,22 @@ function Get-Models() function New-Model() { Param( - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$name, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [int]$category_id, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [int]$manufacturer_id, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [int]$fieldset_id, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$url, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$apiKey ) @@ -54,4 +54,4 @@ function New-Model() -Token $apiKey $result -} \ No newline at end of file +} diff --git a/SnipeitPS/Public/Set-Info.psm1 b/SnipeitPS/Public/Set-Info.psm1 index 3307a01..a0ef88e 100644 --- a/SnipeitPS/Public/Set-Info.psm1 +++ b/SnipeitPS/Public/Set-Info.psm1 @@ -47,4 +47,4 @@ function Set-Info { } } } -} \ No newline at end of file +} diff --git a/SnipeitPS/Public/Status.psm1 b/SnipeitPS/Public/Status.psm1 index 3a4887a..95141f3 100644 --- a/SnipeitPS/Public/Status.psm1 +++ b/SnipeitPS/Public/Status.psm1 @@ -1,10 +1,10 @@ function Get-Status() { - Param( - [parameter(mandatory=$true)] + Param( + [parameter(mandatory=$true)] [string]$url, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$apiKey ) @@ -13,4 +13,4 @@ function Get-Status() -Token $apiKey $result -} \ No newline at end of file +} diff --git a/SnipeitPS/Public/Users.psm1 b/SnipeitPS/Public/Users.psm1 index c2b3cee..b11cc85 100644 --- a/SnipeitPS/Public/Users.psm1 +++ b/SnipeitPS/Public/Users.psm1 @@ -9,7 +9,7 @@ URL of Snipeit system, can be set using Set-Info command Users API Key for Snipeit, can be set using Set-Info command .EXAMPLE -Get-Users -url "https://assets.dip.co.uk" -token "token..." +Get-Users -url "https://assets.dip.co.uk" -token "token..." .EXAMPLE Get-Users -url "https://assets.dip.co.uk" -token "token..." | Where-Object {$_.username -eq "stephenm" } @@ -17,11 +17,11 @@ Get-Users -url "https://assets.dip.co.uk" -token "token..." | Where-Object {$_.u #> function Get-Users() { - Param( - [parameter(mandatory=$true)] + Param( + [parameter(mandatory=$true)] [string]$url, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$apiKey ) diff --git a/Tests/SnipeItPS.Tests.ps1 b/Tests/SnipeItPS.Tests.ps1 index 40d25e9..2fe046a 100644 --- a/Tests/SnipeItPS.Tests.ps1 +++ b/Tests/SnipeItPS.Tests.ps1 @@ -1,53 +1,213 @@ -$ModulePath = Split-Path -Path $PSScriptRoot -Parent -$ModuleName = Split-Path -Path $ModulePath -Leaf +#Requires -Modules PSScriptAnalyzer -# Make sure one or multiple versions of the module are not loaded -Get-Module -Name $ModuleName | Remove-Module +$here = Split-Path -Parent $MyInvocation.MyCommand.Path +$projectRoot = Split-Path -Parent $here +$moduleRoot = "$projectRoot\SnipeitPS" -# Import the module and store the information about the module -$ModuleInformation = Import-Module -Name "$ModulePath\$ModuleName.psd1" -PassThru -$ModuleInformation | Format-List +$manifestFile = "$moduleRoot\SnipeitPS.psd1" +$changelogFile = "$projectRoot\CHANGELOG.md" +$appveyorFile = "$projectRoot\appveyor.yml" +$publicFunctions = "$moduleRoot\Public" +$privateFunctions = "$moduleRoot\Private" -# Get the functions present in the Manifest -$ExportedFunctions = $ModuleInformation.ExportedFunctions.Values.Name +Describe "SnipeitPS" { + Context "All required tests are present" { + # We want to make sure that every .ps1 file in the Functions directory that isn't a Pester test has an associated Pester test. + # This helps keep me honest and makes sure I'm testing my code appropriately. + It "Includes a test for each PowerShell function in the module" { + # Get-ChildItem -Path $publicFunctions -Filter "*.ps1" -Recurse | Where-Object -FilterScript {$_.Name -notlike '*.Tests.ps1'} | % { + # $expectedTestFile = Join-Path $projectRoot "Tests\$($_.BaseName).Tests.ps1" + # $expectedTestFile | Should Exist + # } + } + } -# Get the functions present in the Public folder -$PS1Functions = Get-ChildItem -Path "$ModulePath\Public\*.ps1" + Context "Manifest, changelog, and AppVeyor" { -Describe "$ModuleName Module - Testing Manifest File (.psd1)" { - Context "Manifest" { - It "Should contain RootModule" { - $ModuleInformation.RootModule | Should Not BeNullOrEmpty + # These tests are...erm, borrowed...from the module tests from the Pester module. + # I think they are excellent for sanity checking, and all credit for the following + # tests goes to Dave Wyatt, the genius behind Pester. I've just adapted them + # slightly to match ConfluencePS. + + $script:manifest = $null + + foreach ($line in (Get-Content $changelogFile)) + { + if ($line -match "^\D*(?(\d+\.){1,3}\d+)") + { + $changelogVersion = $matches.Version + break + } } - It "Should contain ModuleVersion" { - $ModuleInformation.Version | Should Not BeNullOrEmpty + foreach ($line in (Get-Content $appveyorFile)) + { + # (?()) - non-capturing group, but named Version. This makes it + # easy to reference the inside group later. + + if ($line -match '^\D*(?(\d+\.){1,3}\d+).\{build\}') + { + $appveyorVersion = $matches.Version + break + } } - It "Should contain GUID" { - $ModuleInformation.Guid | Should Not BeNullOrEmpty + It "Includes a valid manifest file" { + { + $script:manifest = Test-ModuleManifest -Path $script:manifestFile -ErrorAction Stop -WarningAction SilentlyContinue + } | Should Not Throw } - It "Should contain Author" { - $ModuleInformation.Author | Should Not BeNullOrEmpty + # There is a bug that prevents Test-ModuleManifest from updating correctly when the manifest file changes. See here: + # https://connect.microsoft.com/PowerShell/feedback/details/1541659/test-modulemanifest-the-psmoduleinfo-is-not-updated + + # As a temp workaround, we'll just read the manifest as a raw hashtable. + # Credit to this workaround comes from here: + # https://psescape.azurewebsites.net/pester-testing-your-module-manifest/ + $script:manifest = Invoke-Expression (Get-Content $script:manifestFile -Raw) + + It "Manifest file includes the correct root module" { + $script:manifest.RootModule | Should Be 'SnipeitPS' } - It "Should contain Description" { - $ModuleInformation.Description | Should Not BeNullOrEmpty + It "Manifest file includes the correct guid" { + $script:manifest.Guid | Should Be 'f86f4db4-1cb1-45c4-b7bf-6762531bfdeb' } - It "Compare the count of Function Exported and the PS1 files found" { - $status = $ExportedFunctions.Count -eq $PS1Functions.Count - $status | Should Be $true + It "Manifest file includes a valid version" { + # $script:manifest.Version -as [Version] | Should Not BeNullOrEmpty + $script:manifest.ModuleVersion -as [Version] | Should Not BeNullOrEmpty } - It "Compare the missing function" { - If ($ExportedFunctions.count -ne $PS1Functions.count) { - $Compare = Compare-Object -ReferenceObject $ExportedFunctions -DifferenceObject $PS1Functions.Basename - $Compare.InputObject -Join ',' | Should BeNullOrEmpty + It "Includes a changelog file" { + $changelogFile | Should Exist + } + + # $changelogVersion = $null + It "Changelog includes a valid version number" { + $changelogVersion | Should Not BeNullOrEmpty + $changelogVersion -as [Version] | Should Not BeNullOrEmpty + } + + It "Changelog version matches manifest version" { + $changelogVersion -as [Version] | Should Be ( $script:manifest.ModuleVersion -as [Version] ) + } + + # Back to me! Pester doesn't use AppVeyor, as far as I know, and I do. + + It "Includes an appveyor.yml file" { + $appveyorFile | Should Exist + } + + It "Appveyor.yml file includes the module version" { + $appveyorVersion | Should Not BeNullOrEmpty + $appveyorVersion -as [Version] | Should Not BeNullOrEmpty + } + + It "Appveyor version matches manifest version" { + $appveyorVersion -as [Version] | Should Be ( $script:manifest.ModuleVersion -as [Version] ) + } + } + + # The CI changes I'm testng now will render this section obsolete, + # as it should automatically patch the module manifest file with all + # exported function names. + # Leaving the code here for the moment while I can ensure those + # features are working correctly. + + # + # Context "Function checking" { + # $functionFiles = Get-ChildItem $publicFunctions -Filter *.ps1 | + # Select-Object -ExpandProperty BaseName | + # Where-Object { $_ -notlike "*.Tests" } + + # $internalFiles = Get-ChildItem $privateFunctions -Filter *.ps1 | + # Select-Object -ExpandProperty BaseName | + # Where-Object { $_ -notlike "*.Tests" } + + # #$exportedFunctions = $script:manifest.ExportedFunctions.Values.Name + # $exportedFunctions = $script:manifest.FunctionsToExport + + # foreach ($f in $functionFiles) { + # It "Exports $f" { + # $exportedFunctions -contains $f | Should Be $true + # } + # } + + # foreach ($f in $internalFiles) { + # It "Does not export $f" { + # $exportedFunctions -contains $f | Should Be $false + # } + # } + # } + + Context "Style checking" { + + # This section is again from the mastermind, Dave Wyatt. Again, credit + # goes to him for these tests. + + $files = @( + Get-ChildItem $here -Include *.ps1, *.psm1 + Get-ChildItem $publicFunctions -Include *.ps1, *.psm1 -Recurse + ) + + It 'Source files contain no trailing whitespace' { + $badLines = @( + foreach ($file in $files) + { + $lines = [System.IO.File]::ReadAllLines($file.FullName) + $lineCount = $lines.Count + + for ($i = 0; $i -lt $lineCount; $i++) + { + if ($lines[$i] -match '\s+$') + { + 'File: {0}, Line: {1}' -f $file.FullName, ($i + 1) + } + } + } + ) + + if ($badLines.Count -gt 0) + { + throw "The following $($badLines.Count) lines contain trailing whitespace: `r`n`r`n$($badLines -join "`r`n")" + } + } + + It 'Source files all end with a newline' { + $badFiles = @( + foreach ($file in $files) + { + $string = [System.IO.File]::ReadAllText($file.FullName) + if ($string.Length -gt 0 -and $string[-1] -ne "`n") + { + $file.FullName + } + } + ) + + if ($badFiles.Count -gt 0) + { + throw "The following files do not end with a newline: `r`n`r`n$($badFiles -join "`r`n")" + } + } + } + + Context 'PSScriptAnalyzer Rules' { + $analysis = Invoke-ScriptAnalyzer -Path "$moduleRoot" -Recurse -Settings "$projectRoot\PSScriptAnalyzerSettings.psd1" + $scriptAnalyzerRules = Get-ScriptAnalyzerRule + + forEach ($rule in $scriptAnalyzerRules) + { + It "Should pass $rule" { + If (($analysis) -and ($analysis.RuleName -contains $rule)) + { + $analysis | + Where RuleName -EQ $rule -OutVariable failures | + Out-Default + $failures.Count | Should Be 0 + } } } } } - -Get-Module -Name $ModuleName | Remove-Module \ No newline at end of file From 4cbe38c75fe1c84c88d0d2273b8f66499e618390 Mon Sep 17 00:00:00 2001 From: Stephen Maunder Date: Sat, 18 Nov 2017 18:19:44 +0000 Subject: [PATCH 02/12] fix settings --- .vscode/settings.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 0cd992e..f8222de 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -11,5 +11,5 @@ "editor.acceptSuggestionOnEnter": false, "editor.rulers": [80], "editor.trimAutoWhitespace": false - }, + } } From 0a34a30e55d641a945d2d02e5cf65312d982c20b Mon Sep 17 00:00:00 2001 From: Stephen Maunder Date: Sun, 19 Nov 2017 10:57:41 +0000 Subject: [PATCH 03/12] Changelog --- CHANGELOG.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7877f1b..5dc4d10 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,3 @@ -<<<<<<< HEAD # Change Log All notable changes to this project will be documented in this file. @@ -7,6 +6,3 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/), and this project adheres to [Semantic Versioning](http://semver.org/). ## [1.0] - 2017-11-18 -======= -[1.0] ->>>>>>> 13ec3a62ac71275ec2bbe0bbf993130e9f53589f From a026bd84db515c4f92686db99939001d12411444 Mon Sep 17 00:00:00 2001 From: Stephen Maunder Date: Sun, 19 Nov 2017 11:35:52 +0000 Subject: [PATCH 04/12] merge fixes --- SnipeItPS.build.ps1 | 23 ----------------------- Tests/SnipeItPS.Tests.ps1 | 11 +++-------- 2 files changed, 3 insertions(+), 31 deletions(-) diff --git a/SnipeItPS.build.ps1 b/SnipeItPS.build.ps1 index dbaf8d9..5bbf1b5 100644 --- a/SnipeItPS.build.ps1 +++ b/SnipeItPS.build.ps1 @@ -99,11 +99,7 @@ task TestPS5 { } # Synopsis: Invoke Pester Tests -<<<<<<< HEAD -task PesterTests, { -======= task PesterTests CreateHelp, { ->>>>>>> 13ec3a62ac71275ec2bbe0bbf993130e9f53589f try { $result = Invoke-Pester -PassThru -OutputFile "$BuildRoot\TestResult.xml" -OutputFormat "NUnitXml" if ($env:APPVEYOR_PROJECT_NAME) { @@ -122,11 +118,6 @@ task PesterTests CreateHelp, { # Synopsis: Build shippable release task Build GenerateRelease, ConvertMarkdown, UpdateManifest -<<<<<<< HEAD - -# Synopsis: Generate .\Release structure -task GenerateRelease, { -======= task CreateHelp { Import-Module platyPS -Force New-ExternalHelp -Path "$BuildRoot\docs" -OutputPath "$BuildRoot\SnipeitPS\en-US" -Force @@ -135,7 +126,6 @@ task CreateHelp { # Synopsis: Generate .\Release structure task GenerateRelease CreateHelp, { ->>>>>>> 13ec3a62ac71275ec2bbe0bbf993130e9f53589f # Setup if (-not (Test-Path "$releasePath\SnipeitPS")) { $null = New-Item -Path "$releasePath\SnipeitPS" -ItemType Directory @@ -155,10 +145,6 @@ task GenerateRelease CreateHelp, { # Synopsis: Update the manifest of the module task UpdateManifest GetVersion, { Update-Metadata -Path "$releasePath\SnipeitPS\SnipeitPS.psd1" -PropertyName ModuleVersion -Value $script:Version -<<<<<<< HEAD - # Update-Metadata -Path "$releasePath\SnipeitPS\SnipeitPS.psd1" -PropertyName FileList -Value (Get-ChildItem $releasePath\SnipeitPS -Recurse).Name -======= ->>>>>>> 13ec3a62ac71275ec2bbe0bbf993130e9f53589f $functionsToExport = Get-ChildItem "$BuildRoot\SnipeitPS\Public" | ForEach-Object {$_.BaseName} Set-ModuleFunctions -Name "$releasePath\SnipeitPS\SnipeitPS.psd1" -FunctionsToExport $functionsToExport } @@ -181,8 +167,6 @@ task GetVersion { $newRevision } -<<<<<<< HEAD -======= # Synopsis: Convert markdown files to HTML. # $ConvertMarkdown = @{ @@ -197,7 +181,6 @@ task ConvertMarkdown -Partial @ConvertMarkdown InstallPandoc, {process { exec { Tools\pandoc.exe $_ --standalone --from=markdown_github "--output=$2" } } }, RemoveMarkdownFiles ->>>>>>> 13ec3a62ac71275ec2bbe0bbf993130e9f53589f # endregion # region publish @@ -249,15 +232,9 @@ task RemoveGeneratedFiles { Remove-Item $itemsToRemove -Force -Recurse -ErrorAction 0 } -<<<<<<< HEAD -# endregion - -task . ShowDebug, Clean, Test, Build, Deploy -======= task RemoveMarkdownFiles { Remove-Item "$releasePath\SnipeitPS\*.md" -Force -ErrorAction 0 } # endregion task . ShowDebug, Clean, Test, Build, Deploy ->>>>>>> 13ec3a62ac71275ec2bbe0bbf993130e9f53589f diff --git a/Tests/SnipeItPS.Tests.ps1 b/Tests/SnipeItPS.Tests.ps1 index cb0c5f1..afa5a96 100644 --- a/Tests/SnipeItPS.Tests.ps1 +++ b/Tests/SnipeItPS.Tests.ps1 @@ -8,11 +8,7 @@ $manifestFile = "$moduleRoot\SnipeitPS.psd1" $changelogFile = "$projectRoot\CHANGELOG.md" $appveyorFile = "$projectRoot\appveyor.yml" $publicFunctions = "$moduleRoot\Public" -<<<<<<< HEAD -$privateFunctions = "$moduleRoot\Private" -======= -$internalFunctions = "$moduleRoot\Private" ->>>>>>> 13ec3a62ac71275ec2bbe0bbf993130e9f53589f +#$internalFunctions = "$moduleRoot\Private" Describe "SnipeitPS" { Context "All required tests are present" { @@ -140,7 +136,7 @@ Describe "SnipeitPS" { It "Appveyor version matches manifest version" { $appveyorVersion -as [Version] | Should Be ( $script:manifest.ModuleVersion -as [Version] ) } - } + # The CI changes I'm testng now will render this section obsolete, # as it should automatically patch the module manifest file with all @@ -202,7 +198,6 @@ Describe "SnipeitPS" { throw "The following $($badLines.Count) lines contain trailing whitespace: `r`n`r`n$($badLines -join "`r`n")" } } - } It 'Source files all end with a newline' { $badFiles = @( @@ -228,7 +223,7 @@ Describe "SnipeitPS" { It "Should pass $rule" { If (($analysis) -and ($analysis.RuleName -contains $rule)) { $analysis | - Where RuleName -EQ $rule -OutVariable failures | + Where-Object RuleName -EQ $rule -OutVariable failures | Out-Default $failures.Count | Should Be 0 } From cb5ee85bc3f097fe3d18d07555c3a8ff7c05d175 Mon Sep 17 00:00:00 2001 From: Stephen Maunder Date: Sun, 19 Nov 2017 11:37:31 +0000 Subject: [PATCH 05/12] update readme --- README.md | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b365a91..ea64228 100644 --- a/README.md +++ b/README.md @@ -1 +1,32 @@ -[![Build status](https://ci.appveyor.com/api/projects/status/dvuw4ggx543nx3h7?svg=true)](https://ci.appveyor.com/project/snazy2000/snipeitps) \ No newline at end of file +[![GitHub release](https://img.shields.io/github/release/snazy2000/SnipeitPS.svg)](https://github.com/snazy2000/SnipeitPS/releases/latest) [![Build status] +[![Build status](https://ci.appveyor.com/api/projects/status/dvuw4ggx543nx3h7?svg=true)](https://ci.appveyor.com/project/snazy2000/snipeitps) +(https://img.shields.io/powershellgallery/dt/snipeitps.svg)](https://www.powershellgallery.com/packages/snipeitps) ![License](https://img.shields.io/badge/license-MIT-blue.svg) + +--- + +## Instructions + +### Installation + +Install SnipeitPS from the [PowerShell Gallery]! `Install-Module` requires PowerShellGet (included in PS v5, or download for v3/v4 via the gallery link) + +```powershell +# One time only install: (requires an admin PowerShell window) +Install-Module SnipeitPS + +# Check for updates occasionally: +Update-Module SnipeitPS + +# To use each session: +Import-Module SnipeitPS +Set-Info -URL 'https://asset.example.com' -apiKey 'tokenKey' +``` + +### Usage + +```powershell +# Review the help at any time! +Get-Help about_SnipeitPS +Get-Command -Module SnipeitPS +Get-Help Get-Asset -Full # or any other command +``` From 587fc5b7555d4756db366f32bec5fc4820b0b37d Mon Sep 17 00:00:00 2001 From: Stephen Maunder Date: Sun, 19 Nov 2017 11:43:49 +0000 Subject: [PATCH 06/12] fix readme --- README.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index ea64228..2b5ce8e 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,4 @@ -[![GitHub release](https://img.shields.io/github/release/snazy2000/SnipeitPS.svg)](https://github.com/snazy2000/SnipeitPS/releases/latest) [![Build status] -[![Build status](https://ci.appveyor.com/api/projects/status/dvuw4ggx543nx3h7?svg=true)](https://ci.appveyor.com/project/snazy2000/snipeitps) -(https://img.shields.io/powershellgallery/dt/snipeitps.svg)](https://www.powershellgallery.com/packages/snipeitps) ![License](https://img.shields.io/badge/license-MIT-blue.svg) +[![GitHub release](https://img.shields.io/github/release/snazy2000/SnipeitPS.svg)](https://github.com/snazy2000/snipeitps/releases/latest) [![Build status](https://ci.appveyor.com/api/projects/status/dvuw4ggx543nx3h7/branch/master?svg=true)](https://ci.appveyor.com/project/snazy2000/snipeitps/branch/master) [![PowerShell Gallery](https://img.shields.io/powershellgallery/dt/snipeitps.svg)](https://www.powershellgallery.com/packages/snipeitps) ![License](https://img.shields.io/badge/license-MIT-blue.svg) --- @@ -8,7 +6,7 @@ ### Installation -Install SnipeitPS from the [PowerShell Gallery]! `Install-Module` requires PowerShellGet (included in PS v5, or download for v3/v4 via the gallery link) +Install SnipeitPS from the PowerShell Gallery `Install-Module` requires PowerShellGet (included in PS v5, or download for v3/v4 via the gallery link) ```powershell # One time only install: (requires an admin PowerShell window) From 4dface3fa7d30528cb6ce8e9f2f95b4947dfb454 Mon Sep 17 00:00:00 2001 From: Stephen Maunder Date: Sun, 19 Nov 2017 20:08:31 +0000 Subject: [PATCH 07/12] Fix tests --- .vscode/launch.json | 17 --------- Tests/SnipeItPS.Tests.ps1 | 76 +++++++++++++++------------------------ 2 files changed, 28 insertions(+), 65 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 247e672..8f51e52 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,17 +1,6 @@ { "version": "0.2.0", -<<<<<<< HEAD "configurations": [{ -======= - "configurations": [ - { - "type": "PowerShell", - "request": "launch", - "name": "PowerShell Interactive Session", - "cwd": "${workspaceRoot}" - }, - { ->>>>>>> 13ec3a62ac71275ec2bbe0bbf993130e9f53589f "type": "PowerShell", "request": "launch", "name": "PowerShell Pester Tests", @@ -26,7 +15,6 @@ "script": "${file}", "args": [], "cwd": "${file}" -<<<<<<< HEAD }, { "type": "PowerShell", @@ -43,8 +31,3 @@ } ] } -======= - } - ] -} ->>>>>>> 13ec3a62ac71275ec2bbe0bbf993130e9f53589f diff --git a/Tests/SnipeItPS.Tests.ps1 b/Tests/SnipeItPS.Tests.ps1 index afa5a96..fb53815 100644 --- a/Tests/SnipeItPS.Tests.ps1 +++ b/Tests/SnipeItPS.Tests.ps1 @@ -8,7 +8,7 @@ $manifestFile = "$moduleRoot\SnipeitPS.psd1" $changelogFile = "$projectRoot\CHANGELOG.md" $appveyorFile = "$projectRoot\appveyor.yml" $publicFunctions = "$moduleRoot\Public" -#$internalFunctions = "$moduleRoot\Private" +$internalFunctions = "$moduleRoot\Internal" Describe "SnipeitPS" { Context "All required tests are present" { @@ -31,18 +31,22 @@ Describe "SnipeitPS" { $script:manifest = $null - foreach ($line in (Get-Content $changelogFile)) { - if ($line -match "^\D*(?(\d+\.){1,3}\d+)") { + foreach ($line in (Get-Content $changelogFile)) + { + if ($line -match "^\D*(?(\d+\.){1,3}\d+)") + { $changelogVersion = $matches.Version break } } - foreach ($line in (Get-Content $appveyorFile)) { + foreach ($line in (Get-Content $appveyorFile)) + { # (?()) - non-capturing group, but named Version. This makes it # easy to reference the inside group later. - if ($line -match '^\D*(?(\d+\.){1,3}\d+).\{build\}') { + if ($line -match '^\D*(?(\d+\.){1,3}\d+).\{build\}') + { $appveyorVersion = $matches.Version break } @@ -99,44 +103,11 @@ Describe "SnipeitPS" { $appveyorVersion | Should Not BeNullOrEmpty $appveyorVersion -as [Version] | Should Not BeNullOrEmpty } - } - - # The CI changes I'm testng now will render this section obsolete, - # as it should automatically patch the module manifest file with all - # exported function names. - # Leaving the code here for the moment while I can ensure those - # features are working correctly. - - # - # Context "Function checking" { - # $functionFiles = Get-ChildItem $publicFunctions -Filter *.ps1 | - # Select-Object -ExpandProperty BaseName | - # Where-Object { $_ -notlike "*.Tests" } - - # $internalFiles = Get-ChildItem $privateFunctions -Filter *.ps1 | - # Select-Object -ExpandProperty BaseName | - # Where-Object { $_ -notlike "*.Tests" } - - # #$exportedFunctions = $script:manifest.ExportedFunctions.Values.Name - # $exportedFunctions = $script:manifest.FunctionsToExport - - # foreach ($f in $functionFiles) { - # It "Exports $f" { - # $exportedFunctions -contains $f | Should Be $true - # } - # } - - # foreach ($f in $internalFiles) { - # It "Does not export $f" { - # $exportedFunctions -contains $f | Should Be $false - # } - # } - # } It "Appveyor version matches manifest version" { $appveyorVersion -as [Version] | Should Be ( $script:manifest.ModuleVersion -as [Version] ) } - + } # The CI changes I'm testng now will render this section obsolete, # as it should automatically patch the module manifest file with all @@ -182,34 +153,41 @@ Describe "SnipeitPS" { It 'Source files contain no trailing whitespace' { $badLines = @( - foreach ($file in $files) { + foreach ($file in $files) + { $lines = [System.IO.File]::ReadAllLines($file.FullName) $lineCount = $lines.Count - for ($i = 0; $i -lt $lineCount; $i++) { - if ($lines[$i] -match '\s+$') { + for ($i = 0; $i -lt $lineCount; $i++) + { + if ($lines[$i] -match '\s+$') + { 'File: {0}, Line: {1}' -f $file.FullName, ($i + 1) } } } ) - if ($badLines.Count -gt 0) { + if ($badLines.Count -gt 0) + { throw "The following $($badLines.Count) lines contain trailing whitespace: `r`n`r`n$($badLines -join "`r`n")" } } It 'Source files all end with a newline' { $badFiles = @( - foreach ($file in $files) { + foreach ($file in $files) + { $string = [System.IO.File]::ReadAllText($file.FullName) - if ($string.Length -gt 0 -and $string[-1] -ne "`n") { + if ($string.Length -gt 0 -and $string[-1] -ne "`n") + { $file.FullName } } ) - if ($badFiles.Count -gt 0) { + if ($badFiles.Count -gt 0) + { throw "The following files do not end with a newline: `r`n`r`n$($badFiles -join "`r`n")" } } @@ -219,9 +197,11 @@ Describe "SnipeitPS" { $analysis = Invoke-ScriptAnalyzer -Path "$moduleRoot" -Recurse $scriptAnalyzerRules = Get-ScriptAnalyzerRule - forEach ($rule in $scriptAnalyzerRules) { + forEach ($rule in $scriptAnalyzerRules) + { It "Should pass $rule" { - If (($analysis) -and ($analysis.RuleName -contains $rule)) { + If (($analysis) -and ($analysis.RuleName -contains $rule)) + { $analysis | Where-Object RuleName -EQ $rule -OutVariable failures | Out-Default From c860da790f22032a3d139383ce47797c58737337 Mon Sep 17 00:00:00 2001 From: Stephen Maunder Date: Sun, 19 Nov 2017 20:57:27 +0000 Subject: [PATCH 08/12] change structure --- ...{Invoke-Method.psm1 => Invoke-Method.psd1} | 0 SnipeitPS/Public/Assets.psm1 | 177 ------------------ SnipeitPS/Public/Get-Asset.psd1 | 40 ++++ .../{Categories.psm1 => Get-Category.psd1} | 0 .../{Components.psm1 => Get-Component.psd1} | 0 ...nufacturers.psm1 => Get-Manufacturer.psm1} | 0 SnipeitPS/Public/Get-Model.psd1 | 16 ++ .../Public/{Status.psm1 => Get-Status.psd1} | 0 .../Public/{Users.psm1 => Get-User.psm1} | 0 SnipeitPS/Public/Models.psm1 | 68 ------- SnipeitPS/Public/New-Asset.psd1 | 50 +++++ SnipeitPS/Public/New-Component.psd1 | 76 ++++++++ SnipeitPS/Public/New-Manufacturer.psd1 | 40 ++++ SnipeitPS/Public/New-Model.psd1 | 50 +++++ SnipeitPS/Public/Set-Asset.psd1 | 52 +++++ SnipeitPS/Public/Set-AssetOwner.psd1 | 41 ++++ SnipeitPS/Public/Set-Components.psd1 | 41 ++++ .../Public/{Set-Info.psm1 => Set-Info.ps1} | 0 SnipeitPS/SnipeItPS.psm1 | 6 +- Tests/SnipeItPS.Tests.ps1 | 1 - 20 files changed, 409 insertions(+), 249 deletions(-) rename SnipeitPS/Private/{Invoke-Method.psm1 => Invoke-Method.psd1} (100%) delete mode 100644 SnipeitPS/Public/Assets.psm1 create mode 100644 SnipeitPS/Public/Get-Asset.psd1 rename SnipeitPS/Public/{Categories.psm1 => Get-Category.psd1} (100%) rename SnipeitPS/Public/{Components.psm1 => Get-Component.psd1} (100%) rename SnipeitPS/Public/{Manufacturers.psm1 => Get-Manufacturer.psm1} (100%) create mode 100644 SnipeitPS/Public/Get-Model.psd1 rename SnipeitPS/Public/{Status.psm1 => Get-Status.psd1} (100%) rename SnipeitPS/Public/{Users.psm1 => Get-User.psm1} (100%) delete mode 100644 SnipeitPS/Public/Models.psm1 create mode 100644 SnipeitPS/Public/New-Asset.psd1 create mode 100644 SnipeitPS/Public/New-Component.psd1 create mode 100644 SnipeitPS/Public/New-Manufacturer.psd1 create mode 100644 SnipeitPS/Public/New-Model.psd1 create mode 100644 SnipeitPS/Public/Set-Asset.psd1 create mode 100644 SnipeitPS/Public/Set-AssetOwner.psd1 create mode 100644 SnipeitPS/Public/Set-Components.psd1 rename SnipeitPS/Public/{Set-Info.psm1 => Set-Info.ps1} (100%) diff --git a/SnipeitPS/Private/Invoke-Method.psm1 b/SnipeitPS/Private/Invoke-Method.psd1 similarity index 100% rename from SnipeitPS/Private/Invoke-Method.psm1 rename to SnipeitPS/Private/Invoke-Method.psd1 diff --git a/SnipeitPS/Public/Assets.psm1 b/SnipeitPS/Public/Assets.psm1 deleted file mode 100644 index e8d0e75..0000000 --- a/SnipeitPS/Public/Assets.psm1 +++ /dev/null @@ -1,177 +0,0 @@ -<# -.SYNOPSIS -# Gets a list of Snipe-it Assets - -.PARAMETER url -URL of Snipeit system, can be set using Set-Info command - -.PARAMETER apiKey -Users API Key for Snipeit, can be set using Set-Info command - -.EXAMPLE -Get-Asset -url "https://assets.dip.co.uk" -token "token..." - -.EXAMPLE -Get-Asset -url "https://assets.dip.co.uk" -token "token..." | Where-Object {$_.name -eq "SUPPORT23" } - -#> - -function Get-Asset() -{ - Param( - [parameter(mandatory=$true)] - [string]$url, - - [parameter(mandatory=$true)] - [string]$apiKey - ) - - $result = Invoke-Method -URi "$url/api/v1/hardware" ` - -Method GET ` - -Token $apiKey - - $result -} - -function New-Asset() -{ - [CmdletBinding( - SupportsShouldProcess=$true, - ConfirmImpact="High" - )] - - Param( - [parameter(mandatory=$true)] - [string]$Name, - - [parameter(mandatory=$true)] - [string]$Status_id, - - [parameter(mandatory=$true)] - [string]$Model_id, - - [parameter(mandatory=$true)] - [string]$url, - - [parameter(mandatory=$true)] - [string]$apiKey, - - [hashtable] $customfields - ) - - $Values = @{ - "name" = $Name - "status_id" = $status_id - "model_id" = $model_id - } - - $Values += $customfields - - $Body = $Values | ConvertTo-Json; - - $Parameters = @{ - Uri = "$url/api/v1/hardware" - Method = 'Post' - Body = $Body - Token = $apiKey - } - - If ($PSCmdlet.ShouldProcess()) { - $result = Invoke-Method @Parameters - } - - $result -} - -function Set-Asset() -{ - [CmdletBinding( - SupportsShouldProcess=$true, - ConfirmImpact="High" - )] - - Param( - [parameter(mandatory=$true)] - [int]$id, - - [parameter(mandatory=$true)] - [string]$Name, - - [parameter(mandatory=$true)] - [string]$Status_id, - - [parameter(mandatory=$true)] - [string]$Model_id, - - [parameter(mandatory=$true)] - [string]$url, - - [parameter(mandatory=$true)] - [string]$apiKey, - - [hashtable] $customfields - ) - - $Values = @{ - "name" = $Name - "status_id" = $status_id - "model_id" = $model_id - } - - $Values += $customfields - $Body = $Values | ConvertTo-Json; - - $Parameters = @{ - Uri = "$url/api/v1/hardware/$id" - Method = 'Put' - Body = $Body - Token = $apiKey - } - - If ($PSCmdlet.ShouldProcess()) { - $result = Invoke-Method @Parameters - } - - $result -} - -function Set-AssetOwner() -{ - [CmdletBinding( - SupportsShouldProcess=$true, - ConfirmImpact="High" - )] - - Param( - [parameter(mandatory=$true)] - [int]$id, - - [parameter(mandatory=$true)] - [int]$user_id, - - [parameter(mandatory=$true)] - [string]$url, - - [parameter(mandatory=$true)] - [string]$apiKey - ) - - $Values = @{ - "user_id" = $user_id - } - - $Body = $Values | ConvertTo-Json; - - $Parameters = @{ - Uri = "$url/api/v1/hardware/$id/checkout" - Method = 'POST' - Body = $Body - Token = $apiKey - } - - If ($PSCmdlet.ShouldProcess()) { - $result = Invoke-Method @Parameters - } - - return $result -} diff --git a/SnipeitPS/Public/Get-Asset.psd1 b/SnipeitPS/Public/Get-Asset.psd1 new file mode 100644 index 0000000..894e251 --- /dev/null +++ b/SnipeitPS/Public/Get-Asset.psd1 @@ -0,0 +1,40 @@ +<# +.SYNOPSIS +# Gets a list of Snipe-it Assets + +.PARAMETER url +URL of Snipeit system, can be set using Set-Info command + +.PARAMETER apiKey +Users API Key for Snipeit, can be set using Set-Info command + +.EXAMPLE +Get-Asset -url "https://assets.dip.co.uk" -token "token..." + +.EXAMPLE +Get-Asset -url "https://assets.dip.co.uk" -token "token..." | Where-Object {$_.name -eq "SUPPORT23" } + +#> + +function Get-Asset() +{ + Param( + [parameter(mandatory=$true)] + [string]$url, + + [parameter(mandatory=$true)] + [string]$apiKey + ) + + $result = Invoke-Method -URi "$url/api/v1/hardware" ` + -Method GET ` + -Token $apiKey + + $result +} + + + + + + diff --git a/SnipeitPS/Public/Categories.psm1 b/SnipeitPS/Public/Get-Category.psd1 similarity index 100% rename from SnipeitPS/Public/Categories.psm1 rename to SnipeitPS/Public/Get-Category.psd1 diff --git a/SnipeitPS/Public/Components.psm1 b/SnipeitPS/Public/Get-Component.psd1 similarity index 100% rename from SnipeitPS/Public/Components.psm1 rename to SnipeitPS/Public/Get-Component.psd1 diff --git a/SnipeitPS/Public/Manufacturers.psm1 b/SnipeitPS/Public/Get-Manufacturer.psm1 similarity index 100% rename from SnipeitPS/Public/Manufacturers.psm1 rename to SnipeitPS/Public/Get-Manufacturer.psm1 diff --git a/SnipeitPS/Public/Get-Model.psd1 b/SnipeitPS/Public/Get-Model.psd1 new file mode 100644 index 0000000..4c4d92f --- /dev/null +++ b/SnipeitPS/Public/Get-Model.psd1 @@ -0,0 +1,16 @@ +function Get-Model() +{ + Param( + [parameter(mandatory = $true)] + [string]$url, + + [parameter(mandatory = $true)] + [string]$apiKey + ) + + $result = Invoke-Method -URi "$url/api/v1/models" ` + -Method GET ` + -Token $apiKey + + $result +} diff --git a/SnipeitPS/Public/Status.psm1 b/SnipeitPS/Public/Get-Status.psd1 similarity index 100% rename from SnipeitPS/Public/Status.psm1 rename to SnipeitPS/Public/Get-Status.psd1 diff --git a/SnipeitPS/Public/Users.psm1 b/SnipeitPS/Public/Get-User.psm1 similarity index 100% rename from SnipeitPS/Public/Users.psm1 rename to SnipeitPS/Public/Get-User.psm1 diff --git a/SnipeitPS/Public/Models.psm1 b/SnipeitPS/Public/Models.psm1 deleted file mode 100644 index caa093e..0000000 --- a/SnipeitPS/Public/Models.psm1 +++ /dev/null @@ -1,68 +0,0 @@ - -function Get-Model() -{ - Param( - [parameter(mandatory=$true)] - [string]$url, - - [parameter(mandatory=$true)] - [string]$apiKey - ) - - $result = Invoke-Method -URi "$url/api/v1/models" ` - -Method GET ` - -Token $apiKey - - $result -} - - -function New-Model() -{ - [CmdletBinding( - SupportsShouldProcess=$true, - ConfirmImpact="High" - )] - - Param( - [parameter(mandatory=$true)] - [string]$name, - - [parameter(mandatory=$true)] - [int]$category_id, - - [parameter(mandatory=$true)] - [int]$manufacturer_id, - - [parameter(mandatory=$true)] - [int]$fieldset_id, - - [parameter(mandatory=$true)] - [string]$url, - - [parameter(mandatory=$true)] - [string]$apiKey - ) - - $Values = @{ - name = $name - category_id = $category_id - manufacturer_id = $manufacturer_id - fieldset_id = $fieldset_id - } - - $Body = $Values | ConvertTo-Json; - - $Parameters = @{ - Uri = "$url/api/v1/models" - Method = 'post' - Body = $Body - Token = $apiKey - } - - If ($PSCmdlet.ShouldProcess()) { - $result = Invoke-Method @Parameters - } - - $result -} diff --git a/SnipeitPS/Public/New-Asset.psd1 b/SnipeitPS/Public/New-Asset.psd1 new file mode 100644 index 0000000..3ac8d95 --- /dev/null +++ b/SnipeitPS/Public/New-Asset.psd1 @@ -0,0 +1,50 @@ +function New-Asset() +{ + [CmdletBinding( + SupportsShouldProcess = $true, + ConfirmImpact = "High" + )] + + Param( + [parameter(mandatory = $true)] + [string]$Name, + + [parameter(mandatory = $true)] + [string]$Status_id, + + [parameter(mandatory = $true)] + [string]$Model_id, + + [parameter(mandatory = $true)] + [string]$url, + + [parameter(mandatory = $true)] + [string]$apiKey, + + [hashtable] $customfields + ) + + $Values = @{ + "name" = $Name + "status_id" = $status_id + "model_id" = $model_id + } + + $Values += $customfields + + $Body = $Values | ConvertTo-Json; + + $Parameters = @{ + Uri = "$url/api/v1/hardware" + Method = 'Post' + Body = $Body + Token = $apiKey + } + + If ($PSCmdlet.ShouldProcess()) + { + $result = Invoke-Method @Parameters + } + + $result +} diff --git a/SnipeitPS/Public/New-Component.psd1 b/SnipeitPS/Public/New-Component.psd1 new file mode 100644 index 0000000..92227ee --- /dev/null +++ b/SnipeitPS/Public/New-Component.psd1 @@ -0,0 +1,76 @@ +<# + .SYNOPSIS + Short description + + .DESCRIPTION + Long description + + .PARAMETER name + Parameter description + + .PARAMETER category_id + Parameter description + + .PARAMETER qty + Parameter description + + .PARAMETER url + Parameter description + + .PARAMETER apiKey + Parameter description + + .EXAMPLE + An example + + .NOTES + General notes +#> + +function New-Component() +{ + [CmdletBinding( + SupportsShouldProcess = $true, + ConfirmImpact = "High" + )] + + Param( + [parameter(mandatory = $true)] + [string]$name, + + [parameter(mandatory = $true)] + [string]$category_id, + + [parameter(mandatory = $true)] + [string]$qty, + + [parameter(mandatory = $true)] + [string]$url, + + [parameter(mandatory = $true)] + [string]$apiKey + ) + + $Values = @{ + "name" = $name + "category_id" = $category_id + "qty" = $qty + } + + $Body = $Values | ConvertTo-Json; + + $Parameters = @{ + Uri = "$url/api/v1/components" + Method = 'POST' + Body = $Body + Token = $apiKey + } + + If ($PSCmdlet.ShouldProcess()) + { + $result = Invoke-Method @Parameters + } + + $result +} + diff --git a/SnipeitPS/Public/New-Manufacturer.psd1 b/SnipeitPS/Public/New-Manufacturer.psd1 new file mode 100644 index 0000000..cbbab4a --- /dev/null +++ b/SnipeitPS/Public/New-Manufacturer.psd1 @@ -0,0 +1,40 @@ +function New-Manufacturer() +{ + [CmdletBinding( + SupportsShouldProcess = $true, + ConfirmImpact = "High" + )] + + Param( + [parameter(mandatory = $true)] + [string]$Name, + + [parameter(mandatory = $true)] + [string]$url, + + [parameter(mandatory = $true)] + [string]$apiKey + ) + + + $Values = @{ + "name" = $Name + } + + #Convert Values to JSON format + $Body = $Values | ConvertTo-Json; + + $Parameters = @{ + Uri = "$url/api/v1/manufacturers" + Method = 'post' + Body = $Body + Token = $apiKey + } + + If ($PSCmdlet.ShouldProcess()) + { + $result = Invoke-Method @Parameters + } + + $result +} diff --git a/SnipeitPS/Public/New-Model.psd1 b/SnipeitPS/Public/New-Model.psd1 new file mode 100644 index 0000000..eec0272 --- /dev/null +++ b/SnipeitPS/Public/New-Model.psd1 @@ -0,0 +1,50 @@ +function New-Model() +{ + [CmdletBinding( + SupportsShouldProcess = $true, + ConfirmImpact = "High" + )] + + Param( + [parameter(mandatory = $true)] + [string]$name, + + [parameter(mandatory = $true)] + [int]$category_id, + + [parameter(mandatory = $true)] + [int]$manufacturer_id, + + [parameter(mandatory = $true)] + [int]$fieldset_id, + + [parameter(mandatory = $true)] + [string]$url, + + [parameter(mandatory = $true)] + [string]$apiKey + ) + + $Values = @{ + name = $name + category_id = $category_id + manufacturer_id = $manufacturer_id + fieldset_id = $fieldset_id + } + + $Body = $Values | ConvertTo-Json; + + $Parameters = @{ + Uri = "$url/api/v1/models" + Method = 'post' + Body = $Body + Token = $apiKey + } + + If ($PSCmdlet.ShouldProcess()) + { + $result = Invoke-Method @Parameters + } + + $result +} diff --git a/SnipeitPS/Public/Set-Asset.psd1 b/SnipeitPS/Public/Set-Asset.psd1 new file mode 100644 index 0000000..39b88d6 --- /dev/null +++ b/SnipeitPS/Public/Set-Asset.psd1 @@ -0,0 +1,52 @@ +function Set-Asset() +{ + [CmdletBinding( + SupportsShouldProcess = $true, + ConfirmImpact = "High" + )] + + Param( + [parameter(mandatory = $true)] + [int]$id, + + [parameter(mandatory = $true)] + [string]$Name, + + [parameter(mandatory = $true)] + [string]$Status_id, + + [parameter(mandatory = $true)] + [string]$Model_id, + + [parameter(mandatory = $true)] + [string]$url, + + [parameter(mandatory = $true)] + [string]$apiKey, + + [hashtable] $customfields + ) + + $Values = @{ + "name" = $Name + "status_id" = $status_id + "model_id" = $model_id + } + + $Values += $customfields + $Body = $Values | ConvertTo-Json; + + $Parameters = @{ + Uri = "$url/api/v1/hardware/$id" + Method = 'Put' + Body = $Body + Token = $apiKey + } + + If ($PSCmdlet.ShouldProcess()) + { + $result = Invoke-Method @Parameters + } + + $result +} diff --git a/SnipeitPS/Public/Set-AssetOwner.psd1 b/SnipeitPS/Public/Set-AssetOwner.psd1 new file mode 100644 index 0000000..18308b0 --- /dev/null +++ b/SnipeitPS/Public/Set-AssetOwner.psd1 @@ -0,0 +1,41 @@ +function Set-AssetOwner() +{ + [CmdletBinding( + SupportsShouldProcess = $true, + ConfirmImpact = "High" + )] + + Param( + [parameter(mandatory = $true)] + [int]$id, + + [parameter(mandatory = $true)] + [int]$user_id, + + [parameter(mandatory = $true)] + [string]$url, + + [parameter(mandatory = $true)] + [string]$apiKey + ) + + $Values = @{ + "user_id" = $user_id + } + + $Body = $Values | ConvertTo-Json; + + $Parameters = @{ + Uri = "$url/api/v1/hardware/$id/checkout" + Method = 'POST' + Body = $Body + Token = $apiKey + } + + If ($PSCmdlet.ShouldProcess()) + { + $result = Invoke-Method @Parameters + } + + return $result +} diff --git a/SnipeitPS/Public/Set-Components.psd1 b/SnipeitPS/Public/Set-Components.psd1 new file mode 100644 index 0000000..0cd2126 --- /dev/null +++ b/SnipeitPS/Public/Set-Components.psd1 @@ -0,0 +1,41 @@ +function Set-Component() +{ + [CmdletBinding( + SupportsShouldProcess = $true, + ConfirmImpact = "High" + )] + + Param( + [parameter(mandatory = $true)] + [string]$id, + + [parameter(mandatory = $true)] + [string]$qty, + + [parameter(mandatory = $true)] + [string]$url, + + [parameter(mandatory = $true)] + [string]$apiKey + ) + + $Values = @{ + "qty" = $qty + } + + $Body = $Values | ConvertTo-Json; + + $Parameters = @{ + Uri = "$url/api/v1/components/$component_id" + Method = 'Patch' + Body = $Body + Token = $apiKey + } + + If ($PSCmdlet.ShouldProcess()) + { + $result = Invoke-Method @Parameters + } + + $result +} diff --git a/SnipeitPS/Public/Set-Info.psm1 b/SnipeitPS/Public/Set-Info.ps1 similarity index 100% rename from SnipeitPS/Public/Set-Info.psm1 rename to SnipeitPS/Public/Set-Info.ps1 diff --git a/SnipeitPS/SnipeItPS.psm1 b/SnipeitPS/SnipeItPS.psm1 index 53f791c..4f4be07 100644 --- a/SnipeitPS/SnipeItPS.psm1 +++ b/SnipeitPS/SnipeItPS.psm1 @@ -1,11 +1,11 @@ $scriptRoot = $PSScriptRoot + '\public' -Get-ChildItem $scriptRoot *.psm1 | ForEach-Object { +Get-ChildItem $scriptRoot *.psd1 | ForEach-Object { Import-Module $_.FullName } $scriptRoot = $PSScriptRoot + '\private' -Get-ChildItem $scriptRoot *.psm1 | ForEach-Object { +Get-ChildItem $scriptRoot *.psd1 | ForEach-Object { Import-Module $_.FullName -} \ No newline at end of file +} diff --git a/Tests/SnipeItPS.Tests.ps1 b/Tests/SnipeItPS.Tests.ps1 index fb53815..010c077 100644 --- a/Tests/SnipeItPS.Tests.ps1 +++ b/Tests/SnipeItPS.Tests.ps1 @@ -8,7 +8,6 @@ $manifestFile = "$moduleRoot\SnipeitPS.psd1" $changelogFile = "$projectRoot\CHANGELOG.md" $appveyorFile = "$projectRoot\appveyor.yml" $publicFunctions = "$moduleRoot\Public" -$internalFunctions = "$moduleRoot\Internal" Describe "SnipeitPS" { Context "All required tests are present" { From 4515fe08342b6e7bba3307fcc924208ef42f091f Mon Sep 17 00:00:00 2001 From: Stephen Maunder Date: Mon, 20 Nov 2017 09:07:58 +0000 Subject: [PATCH 09/12] Update docks and reworked some scripts --- .../{Invoke-Method.psd1 => Invoke-Method.ps1} | 0 .../Public/{Get-Asset.psd1 => Get-Asset.ps1} | 14 +- SnipeitPS/Public/Get-Category.ps1 | 38 ++++ SnipeitPS/Public/Get-Category.psd1 | 16 -- SnipeitPS/Public/Get-Component.ps1 | 38 ++++ SnipeitPS/Public/Get-Component.psd1 | 124 ------------ SnipeitPS/Public/Get-Manufacturer.ps1 | 38 ++++ SnipeitPS/Public/Get-Manufacturer.psm1 | 56 ------ SnipeitPS/Public/Get-Model.ps1 | 38 ++++ SnipeitPS/Public/Get-Model.psd1 | 16 -- SnipeitPS/Public/Get-Status.ps1 | 38 ++++ SnipeitPS/Public/Get-Status.psd1 | 16 -- SnipeitPS/Public/Get-User.ps1 | 40 ++++ SnipeitPS/Public/Get-User.psm1 | 33 --- .../Public/{New-Asset.psd1 => New-Asset.ps1} | 38 ++++ .../{New-Component.psd1 => New-Component.ps1} | 0 ...Manufacturer.psd1 => New-Manufacturer.ps1} | 20 ++ .../Public/{New-Model.psd1 => New-Model.ps1} | 29 +++ .../Public/{Set-Asset.psd1 => Set-Asset.ps1} | 35 ++++ ...Set-AssetOwner.psd1 => Set-AssetOwner.ps1} | 0 ...Set-Components.psd1 => Set-Components.ps1} | 0 SnipeitPS/SnipeItPS.psm1 | 4 +- docs/Get-Asset.md | 4 +- docs/Get-Category.md | 26 ++- docs/Get-Component.md | 26 ++- docs/Get-Manufacturer.md | 26 ++- docs/Get-Model.md | 26 ++- docs/Get-Status.md | 26 ++- docs/Get-User.md | 4 +- docs/New-Asset.md | 133 ++++++------ docs/New-Component.md | 160 +++++++-------- docs/New-Manufacturer.md | 91 ++++----- docs/New-Model.md | 189 +++++++++--------- docs/Set-Asset.md | 146 +++++++------- 34 files changed, 782 insertions(+), 706 deletions(-) rename SnipeitPS/Private/{Invoke-Method.psd1 => Invoke-Method.ps1} (100%) rename SnipeitPS/Public/{Get-Asset.psd1 => Get-Asset.ps1} (54%) create mode 100644 SnipeitPS/Public/Get-Category.ps1 delete mode 100644 SnipeitPS/Public/Get-Category.psd1 create mode 100644 SnipeitPS/Public/Get-Component.ps1 delete mode 100644 SnipeitPS/Public/Get-Component.psd1 create mode 100644 SnipeitPS/Public/Get-Manufacturer.ps1 delete mode 100644 SnipeitPS/Public/Get-Manufacturer.psm1 create mode 100644 SnipeitPS/Public/Get-Model.ps1 delete mode 100644 SnipeitPS/Public/Get-Model.psd1 create mode 100644 SnipeitPS/Public/Get-Status.ps1 delete mode 100644 SnipeitPS/Public/Get-Status.psd1 create mode 100644 SnipeitPS/Public/Get-User.ps1 delete mode 100644 SnipeitPS/Public/Get-User.psm1 rename SnipeitPS/Public/{New-Asset.psd1 => New-Asset.ps1} (50%) rename SnipeitPS/Public/{New-Component.psd1 => New-Component.ps1} (100%) rename SnipeitPS/Public/{New-Manufacturer.psd1 => New-Manufacturer.ps1} (65%) rename SnipeitPS/Public/{New-Model.psd1 => New-Model.ps1} (58%) rename SnipeitPS/Public/{Set-Asset.psd1 => Set-Asset.ps1} (53%) rename SnipeitPS/Public/{Set-AssetOwner.psd1 => Set-AssetOwner.ps1} (100%) rename SnipeitPS/Public/{Set-Components.psd1 => Set-Components.ps1} (100%) diff --git a/SnipeitPS/Private/Invoke-Method.psd1 b/SnipeitPS/Private/Invoke-Method.ps1 similarity index 100% rename from SnipeitPS/Private/Invoke-Method.psd1 rename to SnipeitPS/Private/Invoke-Method.ps1 diff --git a/SnipeitPS/Public/Get-Asset.psd1 b/SnipeitPS/Public/Get-Asset.ps1 similarity index 54% rename from SnipeitPS/Public/Get-Asset.psd1 rename to SnipeitPS/Public/Get-Asset.ps1 index 894e251..33a377f 100644 --- a/SnipeitPS/Public/Get-Asset.psd1 +++ b/SnipeitPS/Public/Get-Asset.ps1 @@ -9,10 +9,10 @@ URL of Snipeit system, can be set using Set-Info command Users API Key for Snipeit, can be set using Set-Info command .EXAMPLE -Get-Asset -url "https://assets.dip.co.uk" -token "token..." +Get-Asset -url "https://assets.example.com" -token "token..." .EXAMPLE -Get-Asset -url "https://assets.dip.co.uk" -token "token..." | Where-Object {$_.name -eq "SUPPORT23" } +Get-Asset -url "https://assets.example.com" -token "token..." | Where-Object {$_.name -eq "MyMachine" } #> @@ -26,9 +26,13 @@ function Get-Asset() [string]$apiKey ) - $result = Invoke-Method -URi "$url/api/v1/hardware" ` - -Method GET ` - -Token $apiKey + $Parameters = @{ + Uri = "$url/api/v1/hardware" + Method = 'Get' + Token = $apiKey + } + + $result = Invoke-Method @Parameters $result } diff --git a/SnipeitPS/Public/Get-Category.ps1 b/SnipeitPS/Public/Get-Category.ps1 new file mode 100644 index 0000000..77b4c84 --- /dev/null +++ b/SnipeitPS/Public/Get-Category.ps1 @@ -0,0 +1,38 @@ +<# +.SYNOPSIS +# Gets a list of Snipe-it Categories + +.PARAMETER url +URL of Snipeit system, can be set using Set-Info command + +.PARAMETER apiKey +Users API Key for Snipeit, can be set using Set-Info command + +.EXAMPLE +Get-Category -url "https://assets.example.com" -token "token..." + +.EXAMPLE +Get-Category -url "https://assets.example.com" -token "token..." | Where-Object {$_.name -eq "Laptop" } + +#> + +function Get-Category() +{ + Param( + [parameter(mandatory=$true)] + [string]$url, + + [parameter(mandatory=$true)] + [string]$apiKey + ) + + $Parameters = @{ + Uri = "$url/api/v1/categories" + Method = 'Get' + Token = $apiKey + } + + $result = Invoke-Method @Parameters + + $result +} diff --git a/SnipeitPS/Public/Get-Category.psd1 b/SnipeitPS/Public/Get-Category.psd1 deleted file mode 100644 index c80cb3d..0000000 --- a/SnipeitPS/Public/Get-Category.psd1 +++ /dev/null @@ -1,16 +0,0 @@ -function Get-Category() -{ - Param( - [parameter(mandatory=$true)] - [string]$url, - - [parameter(mandatory=$true)] - [string]$apiKey - ) - - $result = Invoke-Method -URi "$url/api/v1/categories" ` - -Method GET ` - -Token $apiKey - - $result -} diff --git a/SnipeitPS/Public/Get-Component.ps1 b/SnipeitPS/Public/Get-Component.ps1 new file mode 100644 index 0000000..9e1ca7f --- /dev/null +++ b/SnipeitPS/Public/Get-Component.ps1 @@ -0,0 +1,38 @@ +<# +.SYNOPSIS +# Gets a list of Snipe-it Components + +.PARAMETER url +URL of Snipeit system, can be set using Set-Info command + +.PARAMETER apiKey +Users API Key for Snipeit, can be set using Set-Info command + +.EXAMPLE +Get-Component -url "https://assets.example.com" -token "token..." + +.EXAMPLE +Get-Component -url "https://assets.example.com" -token "token..." | Where-Object {$_.name -eq "Memory" } + +#> + +function Get-Component() +{ + Param( + [parameter(mandatory=$true)] + [string]$url, + + [parameter(mandatory=$true)] + [string]$apiKey + ) + + $Parameters = @{ + Uri = "$url/api/v1/components" + Method = 'Get' + Token = $apiKey + } + + $result = Invoke-Method @Parameters + + $result +} diff --git a/SnipeitPS/Public/Get-Component.psd1 b/SnipeitPS/Public/Get-Component.psd1 deleted file mode 100644 index 28fe70f..0000000 --- a/SnipeitPS/Public/Get-Component.psd1 +++ /dev/null @@ -1,124 +0,0 @@ -function Get-Component() -{ - Param( - [parameter(mandatory=$true)] - [string]$url, - - [parameter(mandatory=$true)] - [string]$apiKey - ) - - $result = Invoke-Method -URi "$url/api/v1/components" ` - -Method GET ` - -Token $apiKey - - $result -} - -function New-Component() -{ - [CmdletBinding( - SupportsShouldProcess=$true, - ConfirmImpact="High" - )] - - Param( - [parameter(mandatory=$true)] - [string]$name, - - [parameter(mandatory=$true)] - [string]$category_id, - - [parameter(mandatory=$true)] - [string]$qty, - - [parameter(mandatory=$true)] - [string]$url, - - [parameter(mandatory=$true)] - [string]$apiKey - ) - - $Values = @{ - "name" = $name - "category_id" = $category_id - "qty" = $qty - } - - $Body = $Values | ConvertTo-Json; - - $Parameters = @{ - Uri = "$url/api/v1/components" - Method = 'POST' - Body = $Body - Token = $apiKey - } - - If ($PSCmdlet.ShouldProcess()) { - $result = Invoke-Method @Parameters - } - - $result -} - -function Set-Component() -{ - [CmdletBinding( - SupportsShouldProcess=$true, - ConfirmImpact="High" - )] - - Param( - [parameter(mandatory=$true)] - [string]$id, - - [parameter(mandatory=$true)] - [string]$qty, - - [parameter(mandatory=$true)] - [string]$url, - - [parameter(mandatory=$true)] - [string]$apiKey - ) - - $Values = @{ - "qty" = $qty - } - - $Body = $Values | ConvertTo-Json; - - $Parameters = @{ - Uri = "$url/api/v1/components/$component_id" - Method = 'Patch' - Body = $Body - Token = $apiKey - } - - If ($PSCmdlet.ShouldProcess()) { - $result = Invoke-Method @Parameters - } - - $result -} - -<# -Checkout does not exsit yet :( - -function Checkout-Component($component_id, $asset_id = "") -{ - $Values = @{ - "asset_id" = $asset_id - } - - $Body = $Values | ConvertTo-Json; - - $Manufacturers = Invoke-RestMethod -Uri "http://assets.dip.co.uk/api/v1/hardware/$component_id/checkout" ` - -Method Post ` - -Header $headers ` - -Body $Body ` - -ContentType "application/json" ` - -UserAgent "DI Script/0.1" - - return $Manufacturers -}#> diff --git a/SnipeitPS/Public/Get-Manufacturer.ps1 b/SnipeitPS/Public/Get-Manufacturer.ps1 new file mode 100644 index 0000000..edb7972 --- /dev/null +++ b/SnipeitPS/Public/Get-Manufacturer.ps1 @@ -0,0 +1,38 @@ +<# +.SYNOPSIS +# Gets a list of Snipe-it Manufacturers + +.PARAMETER url +URL of Snipeit system, can be set using Set-Info command + +.PARAMETER apiKey +Users API Key for Snipeit, can be set using Set-Info command + +.EXAMPLE +Get-Manufacturer -url "https://assets.example.com" -token "token..." + +.EXAMPLE +Get-Manufacturer -url "https://assets.example.com" -token "token..." | Where-Object {$_.name -eq "HP" } + +#> + +function Get-Manufacturer() +{ + Param( + [parameter(mandatory=$true)] + [string]$url, + + [parameter(mandatory=$true)] + [string]$apiKey + ) + + $Parameters = @{ + Uri = "$url/api/v1/manufacturers" + Method = 'Get' + Token = $apiKey + } + + $result = Invoke-Method @Parameters + + $result +} diff --git a/SnipeitPS/Public/Get-Manufacturer.psm1 b/SnipeitPS/Public/Get-Manufacturer.psm1 deleted file mode 100644 index 0fa234d..0000000 --- a/SnipeitPS/Public/Get-Manufacturer.psm1 +++ /dev/null @@ -1,56 +0,0 @@ -function Get-Manufacturer() -{ - Param( - [parameter(mandatory=$true)] - [string]$url, - - [parameter(mandatory=$true)] - [string]$apiKey - ) - - $result = Invoke-Method -URi "$url/api/v1/manufacturers" ` - -Method GET ` - -Token $apiKey - - $result -} - -function New-Manufacturer() -{ - [CmdletBinding( - SupportsShouldProcess=$true, - ConfirmImpact="High" - )] - - Param( - [parameter(mandatory=$true)] - [string]$Name, - - [parameter(mandatory=$true)] - [string]$url, - - [parameter(mandatory=$true)] - [string]$apiKey - ) - - - $Values = @{ - "name" = $Name - } - - #Convert Values to JSON format - $Body = $Values | ConvertTo-Json; - - $Parameters = @{ - Uri = "$url/api/v1/manufacturers" - Method = 'post' - Body = $Body - Token = $apiKey - } - - If ($PSCmdlet.ShouldProcess()) { - $result = Invoke-Method @Parameters - } - - $result -} diff --git a/SnipeitPS/Public/Get-Model.ps1 b/SnipeitPS/Public/Get-Model.ps1 new file mode 100644 index 0000000..218ae64 --- /dev/null +++ b/SnipeitPS/Public/Get-Model.ps1 @@ -0,0 +1,38 @@ +<# +.SYNOPSIS +# Gets a list of Snipe-it Models + +.PARAMETER url +URL of Snipeit system, can be set using Set-Info command + +.PARAMETER apiKey +Users API Key for Snipeit, can be set using Set-Info command + +.EXAMPLE +Get-Models -url "https://assets.example.com" -token "token..." + +.EXAMPLE +Get-Models -url "https://assets.example.com" -token "token..." | Where-Object {$_.name -eq "DL380" } + +#> + +function Get-Model() +{ + Param( + [parameter(mandatory = $true)] + [string]$url, + + [parameter(mandatory = $true)] + [string]$apiKey + ) + + $Parameters = @{ + Uri = "$url/api/v1/models" + Method = 'Get' + Token = $apiKey + } + + $result = Invoke-Method @Parameters + + $result +} diff --git a/SnipeitPS/Public/Get-Model.psd1 b/SnipeitPS/Public/Get-Model.psd1 deleted file mode 100644 index 4c4d92f..0000000 --- a/SnipeitPS/Public/Get-Model.psd1 +++ /dev/null @@ -1,16 +0,0 @@ -function Get-Model() -{ - Param( - [parameter(mandatory = $true)] - [string]$url, - - [parameter(mandatory = $true)] - [string]$apiKey - ) - - $result = Invoke-Method -URi "$url/api/v1/models" ` - -Method GET ` - -Token $apiKey - - $result -} diff --git a/SnipeitPS/Public/Get-Status.ps1 b/SnipeitPS/Public/Get-Status.ps1 new file mode 100644 index 0000000..0ec7eec --- /dev/null +++ b/SnipeitPS/Public/Get-Status.ps1 @@ -0,0 +1,38 @@ +<# +.SYNOPSIS +# Gets a list of Snipe-it Status Labels + +.PARAMETER url +URL of Snipeit system, can be set using Set-Info command + +.PARAMETER apiKey +Users API Key for Snipeit, can be set using Set-Info command + +.EXAMPLE +Get-Status -url "https://assets.example.com" -token "token..." + +.EXAMPLE +Get-Status -url "https://assets.example.com" -token "token..." | Where-Object {$_.name -eq "Ready to Deploy" } + +#> + +function Get-Status() +{ + Param( + [parameter(mandatory=$true)] + [string]$url, + + [parameter(mandatory=$true)] + [string]$apiKey + ) + + $Parameters = @{ + Uri = "$url/api/v1/statuslabels" + Method = 'Get' + Token = $apiKey + } + + $result = Invoke-Method @Parameters + + $result +} diff --git a/SnipeitPS/Public/Get-Status.psd1 b/SnipeitPS/Public/Get-Status.psd1 deleted file mode 100644 index 95141f3..0000000 --- a/SnipeitPS/Public/Get-Status.psd1 +++ /dev/null @@ -1,16 +0,0 @@ -function Get-Status() -{ - Param( - [parameter(mandatory=$true)] - [string]$url, - - [parameter(mandatory=$true)] - [string]$apiKey - ) - - $result = Invoke-Method -URi "$url/api/v1/statuslabels" ` - -Method GET ` - -Token $apiKey - - $result -} diff --git a/SnipeitPS/Public/Get-User.ps1 b/SnipeitPS/Public/Get-User.ps1 new file mode 100644 index 0000000..27d681b --- /dev/null +++ b/SnipeitPS/Public/Get-User.ps1 @@ -0,0 +1,40 @@ +<# +.SYNOPSIS +# Gets a list of Snipe-it Users + +.PARAMETER url +URL of Snipeit system, can be set using Set-Info command + +.PARAMETER apiKey +Users API Key for Snipeit, can be set using Set-Info command + +.EXAMPLE +Get-User -url "https://assets.example.com" -token "token..." + +.EXAMPLE +Get-User -url "https://assets.example.com" -token "token..." | Where-Object {$_.username -eq "stephenm" } + +#> +function Get-User() +{ + Param( + [parameter(mandatory=$true)] + [string]$url, + + [parameter(mandatory=$true)] + [string]$apiKey + ) + + $Parameters = @{ + Uri = "$url/api/v1/users" + Method = 'Get' + GetParameters = @{ + limit = 999 + } + Token = $apiKey + } + + $result = Invoke-Method @Parameters + + $result +} diff --git a/SnipeitPS/Public/Get-User.psm1 b/SnipeitPS/Public/Get-User.psm1 deleted file mode 100644 index e1017d3..0000000 --- a/SnipeitPS/Public/Get-User.psm1 +++ /dev/null @@ -1,33 +0,0 @@ -<# -.SYNOPSIS -# Gets a list of Snipe-it Users - -.PARAMETER url -URL of Snipeit system, can be set using Set-Info command - -.PARAMETER apiKey -Users API Key for Snipeit, can be set using Set-Info command - -.EXAMPLE -Get-Users -url "https://assets.dip.co.uk" -token "token..." - -.EXAMPLE -Get-Users -url "https://assets.dip.co.uk" -token "token..." | Where-Object {$_.username -eq "stephenm" } - -#> -function Get-User() -{ - Param( - [parameter(mandatory=$true)] - [string]$url, - - [parameter(mandatory=$true)] - [string]$apiKey - ) - - $result = Invoke-Method -URi "$url/api/v1/users?limit=999" ` - -Method GET ` - -Token $apiKey - - $result -} diff --git a/SnipeitPS/Public/New-Asset.psd1 b/SnipeitPS/Public/New-Asset.ps1 similarity index 50% rename from SnipeitPS/Public/New-Asset.psd1 rename to SnipeitPS/Public/New-Asset.ps1 index 3ac8d95..d5b9658 100644 --- a/SnipeitPS/Public/New-Asset.psd1 +++ b/SnipeitPS/Public/New-Asset.ps1 @@ -1,3 +1,38 @@ +<# + .SYNOPSIS + Add a new Asset to Snipe-it asset system + + .DESCRIPTION + Long description + + .PARAMETER Tag + Asset Tag for the Asset + + .PARAMETER Name + Name of the Asset + + .PARAMETER Status_id + Status ID of the asset, this can be got using Get-Status + + .PARAMETER Model_id + Model ID of the asset, this can be got using Get-Model + + .PARAMETER url + URL of Snipeit system, can be set using Set-Info command + + .PARAMETER apiKey + Users API Key for Snipeit, can be set using Set-Info command + + .PARAMETER customfields + Hastable of custom fields and extra fields that need passing through to Snipeit + + .EXAMPLE + New-Asset -status_id 1 -model_id 1 -name "Machine1" + + .EXAMPLE + New-Asset -status_id 1 -model_id 1 -name "Machine1" -CustomValues = @{ "_snipeit_os_5 = "Windows 10 Pro" } +#> + function New-Asset() { [CmdletBinding( @@ -6,6 +41,8 @@ function New-Asset() )] Param( + [string]$tag, + [parameter(mandatory = $true)] [string]$Name, @@ -25,6 +62,7 @@ function New-Asset() ) $Values = @{ + "asset_tag" = $tag "name" = $Name "status_id" = $status_id "model_id" = $model_id diff --git a/SnipeitPS/Public/New-Component.psd1 b/SnipeitPS/Public/New-Component.ps1 similarity index 100% rename from SnipeitPS/Public/New-Component.psd1 rename to SnipeitPS/Public/New-Component.ps1 diff --git a/SnipeitPS/Public/New-Manufacturer.psd1 b/SnipeitPS/Public/New-Manufacturer.ps1 similarity index 65% rename from SnipeitPS/Public/New-Manufacturer.psd1 rename to SnipeitPS/Public/New-Manufacturer.ps1 index cbbab4a..9adea0f 100644 --- a/SnipeitPS/Public/New-Manufacturer.psd1 +++ b/SnipeitPS/Public/New-Manufacturer.ps1 @@ -1,3 +1,23 @@ +<# + .SYNOPSIS + Add a new Manufacturer to Snipe-it asset system + + .DESCRIPTION + Long description + + .PARAMETER Name + Name of the Manufacturer + + .PARAMETER url + URL of Snipeit system, can be set using Set-Info command + + .PARAMETER apiKey + Users API Key for Snipeit, can be set using Set-Info command + + .EXAMPLE + New-Manufacturer -name "HP" +#> + function New-Manufacturer() { [CmdletBinding( diff --git a/SnipeitPS/Public/New-Model.psd1 b/SnipeitPS/Public/New-Model.ps1 similarity index 58% rename from SnipeitPS/Public/New-Model.psd1 rename to SnipeitPS/Public/New-Model.ps1 index eec0272..f761d69 100644 --- a/SnipeitPS/Public/New-Model.psd1 +++ b/SnipeitPS/Public/New-Model.ps1 @@ -1,3 +1,32 @@ +<# + .SYNOPSIS + Add a new Model to Snipe-it asset system + + .DESCRIPTION + Long description + + .PARAMETER name + Name of the Asset Model + + .PARAMETER category_id + Category ID that the asset belongs to this can be got using Get-Category + + .PARAMETER manufacturer_id + Manufacturer ID that the asset belongs to this can be got using Get-Manufacturer + + .PARAMETER fieldset_id + Fieldset ID that the asset uses (Custom fields) + + .PARAMETER url + URL of Snipeit system, can be set using Set-Info command + + .PARAMETER apiKey + Users API Key for Snipeit, can be set using Set-Info command + + .EXAMPLE + New-Model -name "DL380" -manufacturer_id 2 -fieldset_id 2 -category_id 1 +#> + function New-Model() { [CmdletBinding( diff --git a/SnipeitPS/Public/Set-Asset.psd1 b/SnipeitPS/Public/Set-Asset.ps1 similarity index 53% rename from SnipeitPS/Public/Set-Asset.psd1 rename to SnipeitPS/Public/Set-Asset.ps1 index 39b88d6..31bb9b0 100644 --- a/SnipeitPS/Public/Set-Asset.psd1 +++ b/SnipeitPS/Public/Set-Asset.ps1 @@ -1,3 +1,38 @@ +<# + .SYNOPSIS + Update a Asset in the Snipe-it asset system + + .DESCRIPTION + Long description + + .PARAMETER id + ID of the Asset + + .PARAMETER Name + Name of the Asset + + .PARAMETER Status_id + Status ID of the asset, this can be got using Get-Status + + .PARAMETER Model_id + Model ID of the asset, this can be got using Get-Model + + .PARAMETER url + URL of Snipeit system, can be set using Set-Info command + + .PARAMETER apiKey + Users API Key for Snipeit, can be set using Set-Info command + + .PARAMETER customfields + Hastable of custom fields and extra fields that need passing through to Snipeit + + .EXAMPLE + Set-Asset -id 1 -status_id 1 -model_id 1 -name "Machine1" + + .EXAMPLE + Set-Asset -id 1 -status_id 1 -model_id 1 -name "Machine1" -CustomValues = @{ "_snipeit_os_5 = "Windows 10 Pro" } +#> + function Set-Asset() { [CmdletBinding( diff --git a/SnipeitPS/Public/Set-AssetOwner.psd1 b/SnipeitPS/Public/Set-AssetOwner.ps1 similarity index 100% rename from SnipeitPS/Public/Set-AssetOwner.psd1 rename to SnipeitPS/Public/Set-AssetOwner.ps1 diff --git a/SnipeitPS/Public/Set-Components.psd1 b/SnipeitPS/Public/Set-Components.ps1 similarity index 100% rename from SnipeitPS/Public/Set-Components.psd1 rename to SnipeitPS/Public/Set-Components.ps1 diff --git a/SnipeitPS/SnipeItPS.psm1 b/SnipeitPS/SnipeItPS.psm1 index 4f4be07..2290ad8 100644 --- a/SnipeitPS/SnipeItPS.psm1 +++ b/SnipeitPS/SnipeItPS.psm1 @@ -1,11 +1,11 @@ $scriptRoot = $PSScriptRoot + '\public' -Get-ChildItem $scriptRoot *.psd1 | ForEach-Object { +Get-ChildItem $scriptRoot *.ps1 | ForEach-Object { Import-Module $_.FullName } $scriptRoot = $PSScriptRoot + '\private' -Get-ChildItem $scriptRoot *.psd1 | ForEach-Object { +Get-ChildItem $scriptRoot *.ps1 | ForEach-Object { Import-Module $_.FullName } diff --git a/docs/Get-Asset.md b/docs/Get-Asset.md index 0be936a..deaafc9 100644 --- a/docs/Get-Asset.md +++ b/docs/Get-Asset.md @@ -23,12 +23,12 @@ Get-Asset [-url] [-apiKey] ### -------------------------- EXAMPLE 1 -------------------------- ``` -Get-Asset -url "https://assets.dip.co.uk" -token "token..." +Get-Asset -url "https://assets.example.com" -token "token..." ``` ### -------------------------- EXAMPLE 2 -------------------------- ``` -Get-Asset -url "https://assets.dip.co.uk" -token "token..." | Where-Object {$_.name -eq "SUPPORT23" } +Get-Asset -url "https://assets.example.com" -token "token..." | Where-Object {$_.name -eq "MyMachine" } ``` ## PARAMETERS diff --git a/docs/Get-Category.md b/docs/Get-Category.md index bbbca5a..b63484f 100644 --- a/docs/Get-Category.md +++ b/docs/Get-Category.md @@ -8,7 +8,7 @@ schema: 2.0.0 # Get-Category ## SYNOPSIS -{{Fill in the Synopsis}} +# Gets a list of Snipe-it Categories ## SYNTAX @@ -21,17 +21,20 @@ Get-Category [-url] [-apiKey] ## EXAMPLES -### Example 1 +### -------------------------- EXAMPLE 1 -------------------------- ``` -PS C:\> {{ Add example code here }} +Get-Category -url "https://assets.example.com" -token "token..." ``` -{{ Add example description here }} +### -------------------------- EXAMPLE 2 -------------------------- +``` +Get-Category -url "https://assets.example.com" -token "token..." | Where-Object {$_.name -eq "Laptop" } +``` ## PARAMETERS -### -apiKey -{{Fill apiKey Description}} +### -url +URL of Snipeit system, can be set using Set-Info command ```yaml Type: String @@ -45,8 +48,8 @@ Accept pipeline input: False Accept wildcard characters: False ``` -### -url -{{Fill url Description}} +### -apiKey +Users API Key for Snipeit, can be set using Set-Info command ```yaml Type: String @@ -54,7 +57,7 @@ Parameter Sets: (All) Aliases: Required: True -Position: 0 +Position: 2 Default value: None Accept pipeline input: False Accept wildcard characters: False @@ -62,13 +65,8 @@ Accept wildcard characters: False ## INPUTS -### None - - ## OUTPUTS -### System.Object - ## NOTES ## RELATED LINKS diff --git a/docs/Get-Component.md b/docs/Get-Component.md index d19612d..e780747 100644 --- a/docs/Get-Component.md +++ b/docs/Get-Component.md @@ -8,7 +8,7 @@ schema: 2.0.0 # Get-Component ## SYNOPSIS -{{Fill in the Synopsis}} +# Gets a list of Snipe-it Components ## SYNTAX @@ -21,17 +21,20 @@ Get-Component [-url] [-apiKey] ## EXAMPLES -### Example 1 +### -------------------------- EXAMPLE 1 -------------------------- ``` -PS C:\> {{ Add example code here }} +Get-Component -url "https://assets.example.com" -token "token..." ``` -{{ Add example description here }} +### -------------------------- EXAMPLE 2 -------------------------- +``` +Get-Component -url "https://assets.example.com" -token "token..." | Where-Object {$_.name -eq "Memory" } +``` ## PARAMETERS -### -apiKey -{{Fill apiKey Description}} +### -url +URL of Snipeit system, can be set using Set-Info command ```yaml Type: String @@ -45,8 +48,8 @@ Accept pipeline input: False Accept wildcard characters: False ``` -### -url -{{Fill url Description}} +### -apiKey +Users API Key for Snipeit, can be set using Set-Info command ```yaml Type: String @@ -54,7 +57,7 @@ Parameter Sets: (All) Aliases: Required: True -Position: 0 +Position: 2 Default value: None Accept pipeline input: False Accept wildcard characters: False @@ -62,13 +65,8 @@ Accept wildcard characters: False ## INPUTS -### None - - ## OUTPUTS -### System.Object - ## NOTES ## RELATED LINKS diff --git a/docs/Get-Manufacturer.md b/docs/Get-Manufacturer.md index f29d362..df5ca85 100644 --- a/docs/Get-Manufacturer.md +++ b/docs/Get-Manufacturer.md @@ -8,7 +8,7 @@ schema: 2.0.0 # Get-Manufacturer ## SYNOPSIS -{{Fill in the Synopsis}} +# Gets a list of Snipe-it Manufacturers ## SYNTAX @@ -21,17 +21,20 @@ Get-Manufacturer [-url] [-apiKey] ## EXAMPLES -### Example 1 +### -------------------------- EXAMPLE 1 -------------------------- ``` -PS C:\> {{ Add example code here }} +Get-Manufacturer -url "https://assets.example.com" -token "token..." ``` -{{ Add example description here }} +### -------------------------- EXAMPLE 2 -------------------------- +``` +Get-Manufacturer -url "https://assets.example.com" -token "token..." | Where-Object {$_.name -eq "HP" } +``` ## PARAMETERS -### -apiKey -{{Fill apiKey Description}} +### -url +URL of Snipeit system, can be set using Set-Info command ```yaml Type: String @@ -45,8 +48,8 @@ Accept pipeline input: False Accept wildcard characters: False ``` -### -url -{{Fill url Description}} +### -apiKey +Users API Key for Snipeit, can be set using Set-Info command ```yaml Type: String @@ -54,7 +57,7 @@ Parameter Sets: (All) Aliases: Required: True -Position: 0 +Position: 2 Default value: None Accept pipeline input: False Accept wildcard characters: False @@ -62,13 +65,8 @@ Accept wildcard characters: False ## INPUTS -### None - - ## OUTPUTS -### System.Object - ## NOTES ## RELATED LINKS diff --git a/docs/Get-Model.md b/docs/Get-Model.md index 215ba79..55c1504 100644 --- a/docs/Get-Model.md +++ b/docs/Get-Model.md @@ -8,7 +8,7 @@ schema: 2.0.0 # Get-Model ## SYNOPSIS -{{Fill in the Synopsis}} +# Gets a list of Snipe-it Models ## SYNTAX @@ -21,17 +21,20 @@ Get-Model [-url] [-apiKey] ## EXAMPLES -### Example 1 +### -------------------------- EXAMPLE 1 -------------------------- ``` -PS C:\> {{ Add example code here }} +Get-Models -url "https://assets.example.com" -token "token..." ``` -{{ Add example description here }} +### -------------------------- EXAMPLE 2 -------------------------- +``` +Get-Models -url "https://assets.example.com" -token "token..." | Where-Object {$_.name -eq "DL380" } +``` ## PARAMETERS -### -apiKey -{{Fill apiKey Description}} +### -url +URL of Snipeit system, can be set using Set-Info command ```yaml Type: String @@ -45,8 +48,8 @@ Accept pipeline input: False Accept wildcard characters: False ``` -### -url -{{Fill url Description}} +### -apiKey +Users API Key for Snipeit, can be set using Set-Info command ```yaml Type: String @@ -54,7 +57,7 @@ Parameter Sets: (All) Aliases: Required: True -Position: 0 +Position: 2 Default value: None Accept pipeline input: False Accept wildcard characters: False @@ -62,13 +65,8 @@ Accept wildcard characters: False ## INPUTS -### None - - ## OUTPUTS -### System.Object - ## NOTES ## RELATED LINKS diff --git a/docs/Get-Status.md b/docs/Get-Status.md index 6eea36f..be5c90a 100644 --- a/docs/Get-Status.md +++ b/docs/Get-Status.md @@ -8,7 +8,7 @@ schema: 2.0.0 # Get-Status ## SYNOPSIS -{{Fill in the Synopsis}} +# Gets a list of Snipe-it Status Labels ## SYNTAX @@ -21,17 +21,20 @@ Get-Status [-url] [-apiKey] ## EXAMPLES -### Example 1 +### -------------------------- EXAMPLE 1 -------------------------- ``` -PS C:\> {{ Add example code here }} +Get-Status -url "https://assets.example.com" -token "token..." ``` -{{ Add example description here }} +### -------------------------- EXAMPLE 2 -------------------------- +``` +Get-Status -url "https://assets.example.com" -token "token..." | Where-Object {$_.name -eq "Ready to Deploy" } +``` ## PARAMETERS -### -apiKey -{{Fill apiKey Description}} +### -url +URL of Snipeit system, can be set using Set-Info command ```yaml Type: String @@ -45,8 +48,8 @@ Accept pipeline input: False Accept wildcard characters: False ``` -### -url -{{Fill url Description}} +### -apiKey +Users API Key for Snipeit, can be set using Set-Info command ```yaml Type: String @@ -54,7 +57,7 @@ Parameter Sets: (All) Aliases: Required: True -Position: 0 +Position: 2 Default value: None Accept pipeline input: False Accept wildcard characters: False @@ -62,13 +65,8 @@ Accept wildcard characters: False ## INPUTS -### None - - ## OUTPUTS -### System.Object - ## NOTES ## RELATED LINKS diff --git a/docs/Get-User.md b/docs/Get-User.md index 31ccdb6..5f1610d 100644 --- a/docs/Get-User.md +++ b/docs/Get-User.md @@ -23,12 +23,12 @@ Get-User [-url] [-apiKey] ### -------------------------- EXAMPLE 1 -------------------------- ``` -Get-Users -url "https://assets.dip.co.uk" -token "token..." +Get-User -url "https://assets.example.com" -token "token..." ``` ### -------------------------- EXAMPLE 2 -------------------------- ``` -Get-Users -url "https://assets.dip.co.uk" -token "token..." | Where-Object {$_.username -eq "stephenm" } +Get-User -url "https://assets.example.com" -token "token..." | Where-Object {$_.username -eq "stephenm" } ``` ## PARAMETERS diff --git a/docs/New-Asset.md b/docs/New-Asset.md index 30fbb22..334c85e 100644 --- a/docs/New-Asset.md +++ b/docs/New-Asset.md @@ -8,46 +8,49 @@ schema: 2.0.0 # New-Asset ## SYNOPSIS -{{Fill in the Synopsis}} +Add a new Asset to Snipe-it asset system ## SYNTAX ``` -New-Asset [-Name] [-Status_id] [-Model_id] [-url] [-apiKey] - [[-customfields] ] [-WhatIf] [-Confirm] +New-Asset [[-tag] ] [-Name] [-Status_id] [-Model_id] [-url] + [-apiKey] [[-customfields] ] [-WhatIf] [-Confirm] ``` ## DESCRIPTION -{{Fill in the Description}} +Long description ## EXAMPLES -### Example 1 +### -------------------------- EXAMPLE 1 -------------------------- ``` -PS C:\> {{ Add example code here }} +New-Asset -status_id 1 -model_id 1 -name "Machine1" ``` -{{ Add example description here }} +### -------------------------- EXAMPLE 2 -------------------------- +``` +New-Asset -status_id 1 -model_id 1 -name "Machine1" -CustomValues = @{ "_snipeit_os_5 = "Windows 10 Pro" } +``` ## PARAMETERS -### -Confirm -Prompts you for confirmation before running the cmdlet. +### -tag +Asset Tag for the Asset ```yaml -Type: SwitchParameter +Type: String Parameter Sets: (All) -Aliases: cf +Aliases: Required: False -Position: Named +Position: 1 Default value: None Accept pipeline input: False Accept wildcard characters: False ``` -### -Model_id -{{Fill Model_id Description}} +### -Name +Name of the Asset ```yaml Type: String @@ -61,8 +64,8 @@ Accept pipeline input: False Accept wildcard characters: False ``` -### -Name -{{Fill Name Description}} +### -Status_id +Status ID of the asset, this can be got using Get-Status ```yaml Type: String @@ -70,14 +73,14 @@ Parameter Sets: (All) Aliases: Required: True -Position: 0 +Position: 3 Default value: None Accept pipeline input: False Accept wildcard characters: False ``` -### -Status_id -{{Fill Status_id Description}} +### -Model_id +Model ID of the asset, this can be got using Get-Model ```yaml Type: String @@ -85,7 +88,52 @@ Parameter Sets: (All) Aliases: Required: True -Position: 1 +Position: 4 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -url +URL of Snipeit system, can be set using Set-Info command + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 5 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -apiKey +Users API Key for Snipeit, can be set using Set-Info command + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 6 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -customfields +Hastable of custom fields and extra fields that need passing through to Snipeit + +```yaml +Type: Hashtable +Parameter Sets: (All) +Aliases: + +Required: False +Position: 7 Default value: None Accept pipeline input: False Accept wildcard characters: False @@ -107,46 +155,16 @@ Accept pipeline input: False Accept wildcard characters: False ``` -### -apiKey -{{Fill apiKey Description}} +### -Confirm +Prompts you for confirmation before running the cmdlet. ```yaml -Type: String +Type: SwitchParameter Parameter Sets: (All) -Aliases: - -Required: True -Position: 4 -Default value: None -Accept pipeline input: False -Accept wildcard characters: False -``` - -### -customfields -{{Fill customfields Description}} - -```yaml -Type: Hashtable -Parameter Sets: (All) -Aliases: +Aliases: cf Required: False -Position: 5 -Default value: None -Accept pipeline input: False -Accept wildcard characters: False -``` - -### -url -{{Fill url Description}} - -```yaml -Type: String -Parameter Sets: (All) -Aliases: - -Required: True -Position: 3 +Position: Named Default value: None Accept pipeline input: False Accept wildcard characters: False @@ -154,13 +172,8 @@ Accept wildcard characters: False ## INPUTS -### None - - ## OUTPUTS -### System.Object - ## NOTES ## RELATED LINKS diff --git a/docs/New-Component.md b/docs/New-Component.md index 8d4bba7..ff564f9 100644 --- a/docs/New-Component.md +++ b/docs/New-Component.md @@ -8,7 +8,7 @@ schema: 2.0.0 # New-Component ## SYNOPSIS -{{Fill in the Synopsis}} +Short description ## SYNTAX @@ -18,29 +18,87 @@ New-Component [-name] [-category_id] [-qty] [-url] {{ Add example code here }} +An example ``` -{{ Add example description here }} - ## PARAMETERS -### -Confirm -Prompts you for confirmation before running the cmdlet. +### -name +Parameter description ```yaml -Type: SwitchParameter +Type: String Parameter Sets: (All) -Aliases: cf +Aliases: -Required: False -Position: Named +Required: True +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -category_id +Parameter description + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 2 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -qty +Parameter description + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 3 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -url +Parameter description + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 4 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -apiKey +Parameter description + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 5 Default value: None Accept pipeline input: False Accept wildcard characters: False @@ -62,76 +120,16 @@ Accept pipeline input: False Accept wildcard characters: False ``` -### -apiKey -{{Fill apiKey Description}} +### -Confirm +Prompts you for confirmation before running the cmdlet. ```yaml -Type: String +Type: SwitchParameter Parameter Sets: (All) -Aliases: +Aliases: cf -Required: True -Position: 4 -Default value: None -Accept pipeline input: False -Accept wildcard characters: False -``` - -### -category_id -{{Fill category_id Description}} - -```yaml -Type: String -Parameter Sets: (All) -Aliases: - -Required: True -Position: 1 -Default value: None -Accept pipeline input: False -Accept wildcard characters: False -``` - -### -name -{{Fill name Description}} - -```yaml -Type: String -Parameter Sets: (All) -Aliases: - -Required: True -Position: 0 -Default value: None -Accept pipeline input: False -Accept wildcard characters: False -``` - -### -qty -{{Fill qty Description}} - -```yaml -Type: String -Parameter Sets: (All) -Aliases: - -Required: True -Position: 2 -Default value: None -Accept pipeline input: False -Accept wildcard characters: False -``` - -### -url -{{Fill url Description}} - -```yaml -Type: String -Parameter Sets: (All) -Aliases: - -Required: True -Position: 3 +Required: False +Position: Named Default value: None Accept pipeline input: False Accept wildcard characters: False @@ -139,14 +137,10 @@ Accept wildcard characters: False ## INPUTS -### None - - ## OUTPUTS -### System.Object - ## NOTES +General notes ## RELATED LINKS diff --git a/docs/New-Manufacturer.md b/docs/New-Manufacturer.md index 5616130..8f32b60 100644 --- a/docs/New-Manufacturer.md +++ b/docs/New-Manufacturer.md @@ -8,7 +8,7 @@ schema: 2.0.0 # New-Manufacturer ## SYNOPSIS -{{Fill in the Synopsis}} +Add a new Manufacturer to Snipe-it asset system ## SYNTAX @@ -17,36 +17,19 @@ New-Manufacturer [-Name] [-url] [-apiKey] [-WhatIf] [ ``` ## DESCRIPTION -{{Fill in the Description}} +Long description ## EXAMPLES -### Example 1 +### -------------------------- EXAMPLE 1 -------------------------- ``` -PS C:\> {{ Add example code here }} +New-Manufacturer -name "HP" ``` -{{ Add example description here }} - ## PARAMETERS -### -Confirm -Prompts you for confirmation before running the cmdlet. - -```yaml -Type: SwitchParameter -Parameter Sets: (All) -Aliases: cf - -Required: False -Position: Named -Default value: None -Accept pipeline input: False -Accept wildcard characters: False -``` - ### -Name -{{Fill Name Description}} +Name of the Manufacturer ```yaml Type: String @@ -54,7 +37,37 @@ Parameter Sets: (All) Aliases: Required: True -Position: 0 +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -url +URL of Snipeit system, can be set using Set-Info command + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 2 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -apiKey +Users API Key for Snipeit, can be set using Set-Info command + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 3 Default value: None Accept pipeline input: False Accept wildcard characters: False @@ -76,31 +89,16 @@ Accept pipeline input: False Accept wildcard characters: False ``` -### -apiKey -{{Fill apiKey Description}} +### -Confirm +Prompts you for confirmation before running the cmdlet. ```yaml -Type: String +Type: SwitchParameter Parameter Sets: (All) -Aliases: +Aliases: cf -Required: True -Position: 2 -Default value: None -Accept pipeline input: False -Accept wildcard characters: False -``` - -### -url -{{Fill url Description}} - -```yaml -Type: String -Parameter Sets: (All) -Aliases: - -Required: True -Position: 1 +Required: False +Position: Named Default value: None Accept pipeline input: False Accept wildcard characters: False @@ -108,13 +106,8 @@ Accept wildcard characters: False ## INPUTS -### None - - ## OUTPUTS -### System.Object - ## NOTES ## RELATED LINKS diff --git a/docs/New-Model.md b/docs/New-Model.md index 06b064b..6202855 100644 --- a/docs/New-Model.md +++ b/docs/New-Model.md @@ -8,7 +8,7 @@ schema: 2.0.0 # New-Model ## SYNOPSIS -{{Fill in the Synopsis}} +Add a new Model to Snipe-it asset system ## SYNTAX @@ -18,29 +18,102 @@ New-Model [-name] [-category_id] [-manufacturer_id] [-f ``` ## DESCRIPTION -{{Fill in the Description}} +Long description ## EXAMPLES -### Example 1 +### -------------------------- EXAMPLE 1 -------------------------- ``` -PS C:\> {{ Add example code here }} +New-Model -name "DL380" -manufacturer_id 2 -fieldset_id 2 -category_id 1 ``` -{{ Add example description here }} - ## PARAMETERS -### -Confirm -Prompts you for confirmation before running the cmdlet. +### -name +Name of the Asset Model ```yaml -Type: SwitchParameter +Type: String Parameter Sets: (All) -Aliases: cf +Aliases: -Required: False -Position: Named +Required: True +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -category_id +Category ID that the asset belongs to this can be got using Get-Category + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: + +Required: True +Position: 2 +Default value: 0 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -manufacturer_id +Manufacturer ID that the asset belongs to this can be got using Get-Manufacturer + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: + +Required: True +Position: 3 +Default value: 0 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -fieldset_id +Fieldset ID that the asset uses (Custom fields) + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: + +Required: True +Position: 4 +Default value: 0 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -url +URL of Snipeit system, can be set using Set-Info command + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 5 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -apiKey +Users API Key for Snipeit, can be set using Set-Info command + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 6 Default value: None Accept pipeline input: False Accept wildcard characters: False @@ -62,91 +135,16 @@ Accept pipeline input: False Accept wildcard characters: False ``` -### -apiKey -{{Fill apiKey Description}} +### -Confirm +Prompts you for confirmation before running the cmdlet. ```yaml -Type: String +Type: SwitchParameter Parameter Sets: (All) -Aliases: +Aliases: cf -Required: True -Position: 5 -Default value: None -Accept pipeline input: False -Accept wildcard characters: False -``` - -### -category_id -{{Fill category_id Description}} - -```yaml -Type: Int32 -Parameter Sets: (All) -Aliases: - -Required: True -Position: 1 -Default value: None -Accept pipeline input: False -Accept wildcard characters: False -``` - -### -fieldset_id -{{Fill fieldset_id Description}} - -```yaml -Type: Int32 -Parameter Sets: (All) -Aliases: - -Required: True -Position: 3 -Default value: None -Accept pipeline input: False -Accept wildcard characters: False -``` - -### -manufacturer_id -{{Fill manufacturer_id Description}} - -```yaml -Type: Int32 -Parameter Sets: (All) -Aliases: - -Required: True -Position: 2 -Default value: None -Accept pipeline input: False -Accept wildcard characters: False -``` - -### -name -{{Fill name Description}} - -```yaml -Type: String -Parameter Sets: (All) -Aliases: - -Required: True -Position: 0 -Default value: None -Accept pipeline input: False -Accept wildcard characters: False -``` - -### -url -{{Fill url Description}} - -```yaml -Type: String -Parameter Sets: (All) -Aliases: - -Required: True -Position: 4 +Required: False +Position: Named Default value: None Accept pipeline input: False Accept wildcard characters: False @@ -154,13 +152,8 @@ Accept wildcard characters: False ## INPUTS -### None - - ## OUTPUTS -### System.Object - ## NOTES ## RELATED LINKS diff --git a/docs/Set-Asset.md b/docs/Set-Asset.md index d578e3b..11ff0e6 100644 --- a/docs/Set-Asset.md +++ b/docs/Set-Asset.md @@ -8,7 +8,7 @@ schema: 2.0.0 # Set-Asset ## SYNOPSIS -{{Fill in the Synopsis}} +Update a Asset in the Snipe-it asset system ## SYNTAX @@ -18,36 +18,54 @@ Set-Asset [-id] [-Name] [-Status_id] [-Model_id] {{ Add example code here }} +Set-Asset -id 1 -status_id 1 -model_id 1 -name "Machine1" ``` -{{ Add example description here }} +### -------------------------- EXAMPLE 2 -------------------------- +``` +Set-Asset -id 1 -status_id 1 -model_id 1 -name "Machine1" -CustomValues = @{ "_snipeit_os_5 = "Windows 10 Pro" } +``` ## PARAMETERS -### -Confirm -Prompts you for confirmation before running the cmdlet. +### -id +ID of the Asset ```yaml -Type: SwitchParameter +Type: Int32 Parameter Sets: (All) -Aliases: cf +Aliases: -Required: False -Position: Named +Required: True +Position: 1 +Default value: 0 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Name +Name of the Asset + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 2 Default value: None Accept pipeline input: False Accept wildcard characters: False ``` -### -Model_id -{{Fill Model_id Description}} +### -Status_id +Status ID of the asset, this can be got using Get-Status ```yaml Type: String @@ -61,8 +79,8 @@ Accept pipeline input: False Accept wildcard characters: False ``` -### -Name -{{Fill Name Description}} +### -Model_id +Model ID of the asset, this can be got using Get-Model ```yaml Type: String @@ -70,14 +88,14 @@ Parameter Sets: (All) Aliases: Required: True -Position: 1 +Position: 4 Default value: None Accept pipeline input: False Accept wildcard characters: False ``` -### -Status_id -{{Fill Status_id Description}} +### -url +URL of Snipeit system, can be set using Set-Info command ```yaml Type: String @@ -85,7 +103,37 @@ Parameter Sets: (All) Aliases: Required: True -Position: 2 +Position: 5 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -apiKey +Users API Key for Snipeit, can be set using Set-Info command + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 6 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -customfields +Hastable of custom fields and extra fields that need passing through to Snipeit + +```yaml +Type: Hashtable +Parameter Sets: (All) +Aliases: + +Required: False +Position: 7 Default value: None Accept pipeline input: False Accept wildcard characters: False @@ -107,61 +155,16 @@ Accept pipeline input: False Accept wildcard characters: False ``` -### -apiKey -{{Fill apiKey Description}} +### -Confirm +Prompts you for confirmation before running the cmdlet. ```yaml -Type: String +Type: SwitchParameter Parameter Sets: (All) -Aliases: - -Required: True -Position: 5 -Default value: None -Accept pipeline input: False -Accept wildcard characters: False -``` - -### -customfields -{{Fill customfields Description}} - -```yaml -Type: Hashtable -Parameter Sets: (All) -Aliases: +Aliases: cf Required: False -Position: 6 -Default value: None -Accept pipeline input: False -Accept wildcard characters: False -``` - -### -id -{{Fill id Description}} - -```yaml -Type: Int32 -Parameter Sets: (All) -Aliases: - -Required: True -Position: 0 -Default value: None -Accept pipeline input: False -Accept wildcard characters: False -``` - -### -url -{{Fill url Description}} - -```yaml -Type: String -Parameter Sets: (All) -Aliases: - -Required: True -Position: 4 +Position: Named Default value: None Accept pipeline input: False Accept wildcard characters: False @@ -169,13 +172,8 @@ Accept wildcard characters: False ## INPUTS -### None - - ## OUTPUTS -### System.Object - ## NOTES ## RELATED LINKS From 2c1454b67356b5d4c620a940bf90269545b6699a Mon Sep 17 00:00:00 2001 From: Stephen Maunder Date: Mon, 20 Nov 2017 09:12:54 +0000 Subject: [PATCH 10/12] Extra checks --- SnipeitPS/Public/New-Asset.ps1 | 7 +++++-- SnipeitPS/Public/New-Component.ps1 | 2 +- SnipeitPS/Public/New-Manufacturer.ps1 | 2 +- SnipeitPS/Public/New-Model.ps1 | 2 +- SnipeitPS/Public/Set-Asset.ps1 | 8 ++++++-- SnipeitPS/Public/Set-AssetOwner.ps1 | 2 +- SnipeitPS/Public/Set-Components.ps1 | 2 +- 7 files changed, 16 insertions(+), 9 deletions(-) diff --git a/SnipeitPS/Public/New-Asset.ps1 b/SnipeitPS/Public/New-Asset.ps1 index d5b9658..0cfc706 100644 --- a/SnipeitPS/Public/New-Asset.ps1 +++ b/SnipeitPS/Public/New-Asset.ps1 @@ -68,7 +68,10 @@ function New-Asset() "model_id" = $model_id } - $Values += $customfields + if ($customfields) + { + $Values += $customfields + } $Body = $Values | ConvertTo-Json; @@ -79,7 +82,7 @@ function New-Asset() Token = $apiKey } - If ($PSCmdlet.ShouldProcess()) + If ($PSCmdlet.ShouldProcess("ShouldProcess?")) { $result = Invoke-Method @Parameters } diff --git a/SnipeitPS/Public/New-Component.ps1 b/SnipeitPS/Public/New-Component.ps1 index 92227ee..3f57891 100644 --- a/SnipeitPS/Public/New-Component.ps1 +++ b/SnipeitPS/Public/New-Component.ps1 @@ -66,7 +66,7 @@ function New-Component() Token = $apiKey } - If ($PSCmdlet.ShouldProcess()) + If ($PSCmdlet.ShouldProcess("ShouldProcess?")) { $result = Invoke-Method @Parameters } diff --git a/SnipeitPS/Public/New-Manufacturer.ps1 b/SnipeitPS/Public/New-Manufacturer.ps1 index 9adea0f..5ccca1e 100644 --- a/SnipeitPS/Public/New-Manufacturer.ps1 +++ b/SnipeitPS/Public/New-Manufacturer.ps1 @@ -51,7 +51,7 @@ function New-Manufacturer() Token = $apiKey } - If ($PSCmdlet.ShouldProcess()) + If ($PSCmdlet.ShouldProcess("ShouldProcess?")) { $result = Invoke-Method @Parameters } diff --git a/SnipeitPS/Public/New-Model.ps1 b/SnipeitPS/Public/New-Model.ps1 index f761d69..ae19efa 100644 --- a/SnipeitPS/Public/New-Model.ps1 +++ b/SnipeitPS/Public/New-Model.ps1 @@ -70,7 +70,7 @@ function New-Model() Token = $apiKey } - If ($PSCmdlet.ShouldProcess()) + If ($PSCmdlet.ShouldProcess("ShouldProcess?")) { $result = Invoke-Method @Parameters } diff --git a/SnipeitPS/Public/Set-Asset.ps1 b/SnipeitPS/Public/Set-Asset.ps1 index 31bb9b0..a821450 100644 --- a/SnipeitPS/Public/Set-Asset.ps1 +++ b/SnipeitPS/Public/Set-Asset.ps1 @@ -68,7 +68,11 @@ function Set-Asset() "model_id" = $model_id } - $Values += $customfields + if ($customfields) + { + $Values += $customfields + } + $Body = $Values | ConvertTo-Json; $Parameters = @{ @@ -78,7 +82,7 @@ function Set-Asset() Token = $apiKey } - If ($PSCmdlet.ShouldProcess()) + If ($PSCmdlet.ShouldProcess("ShouldProcess?")) { $result = Invoke-Method @Parameters } diff --git a/SnipeitPS/Public/Set-AssetOwner.ps1 b/SnipeitPS/Public/Set-AssetOwner.ps1 index 18308b0..18d6ccc 100644 --- a/SnipeitPS/Public/Set-AssetOwner.ps1 +++ b/SnipeitPS/Public/Set-AssetOwner.ps1 @@ -32,7 +32,7 @@ function Set-AssetOwner() Token = $apiKey } - If ($PSCmdlet.ShouldProcess()) + If ($PSCmdlet.ShouldProcess("ShouldProcess?")) { $result = Invoke-Method @Parameters } diff --git a/SnipeitPS/Public/Set-Components.ps1 b/SnipeitPS/Public/Set-Components.ps1 index 0cd2126..90f97ce 100644 --- a/SnipeitPS/Public/Set-Components.ps1 +++ b/SnipeitPS/Public/Set-Components.ps1 @@ -32,7 +32,7 @@ function Set-Component() Token = $apiKey } - If ($PSCmdlet.ShouldProcess()) + If ($PSCmdlet.ShouldProcess("ShouldProcess?")) { $result = Invoke-Method @Parameters } From d74644ae1639c054b8f341787b4d130cb9c33f17 Mon Sep 17 00:00:00 2001 From: Stephen Maunder Date: Mon, 20 Nov 2017 09:15:11 +0000 Subject: [PATCH 11/12] Change Method to be more specific --- ...{Invoke-Method.ps1 => Invoke-SnipeitMethod.ps1} | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) rename SnipeitPS/Private/{Invoke-Method.ps1 => Invoke-SnipeitMethod.ps1} (96%) diff --git a/SnipeitPS/Private/Invoke-Method.ps1 b/SnipeitPS/Private/Invoke-SnipeitMethod.ps1 similarity index 96% rename from SnipeitPS/Private/Invoke-Method.ps1 rename to SnipeitPS/Private/Invoke-SnipeitMethod.ps1 index a5188a4..f340fa6 100644 --- a/SnipeitPS/Private/Invoke-Method.ps1 +++ b/SnipeitPS/Private/Invoke-SnipeitMethod.ps1 @@ -1,4 +1,4 @@ -function Invoke-Method { +function Invoke-SnipeitMethod { <# .SYNOPSIS Extracted invokation of the REST method to own function. @@ -42,7 +42,7 @@ } Process { - if ($GetParameters -and ($URi -notlike "*\?*")) + if ($GetParameters -and ($URi -notlike "*\?*")) { Write-Debug "Using `$GetParameters: $($GetParameters | Out-String)" [string]$URI += (ConvertTo-GetParameter $GetParameters) @@ -86,7 +86,7 @@ # API returned a Content: lets work wit it $response = ConvertFrom-Json -InputObject $webResponse.Content - + if ($response.status -eq "error") { Write-Verbose "[$($MyInvocation.MyCommand.Name)] An error response was received from; resolving" # This could be handled nicely in an function such as: @@ -95,14 +95,14 @@ } else { $result = $response - if (($response) -and ($response | Get-Member -Name payload)) + if (($response) -and ($response | Get-Member -Name payload)) { $result = $response.payload } elseif (($response) -and ($response | Get-Member -Name rows)) { $result = $response.rows } - + $result } } @@ -111,7 +111,7 @@ # This could be wanted behavior of the API Write-Verbose "[$($MyInvocation.MyCommand.Name)] No content was returned from." } - + } else { Write-Verbose "[$($MyInvocation.MyCommand.Name)] No Web result object was returned from. This is unusual!" @@ -121,4 +121,4 @@ END { Write-Verbose "[$($MyInvocation.MyCommand.Name)] Function ended" } -} \ No newline at end of file +} From ebb99a24fa85a892b8ac8e76c1fc07b73954288b Mon Sep 17 00:00:00 2001 From: Stephen Maunder Date: Thu, 28 Dec 2017 14:17:22 +0000 Subject: [PATCH 12/12] Update all Methods to call correct Rest Call --- SnipeitPS/Public/Get-Asset.ps1 | 2 +- SnipeitPS/Public/Get-Category.ps1 | 2 +- SnipeitPS/Public/Get-Component.ps1 | 2 +- SnipeitPS/Public/Get-Manufacturer.ps1 | 2 +- SnipeitPS/Public/Get-Model.ps1 | 2 +- SnipeitPS/Public/Get-Status.ps1 | 2 +- SnipeitPS/Public/Get-User.ps1 | 2 +- SnipeitPS/Public/New-Asset.ps1 | 2 +- SnipeitPS/Public/New-Component.ps1 | 2 +- SnipeitPS/Public/New-Manufacturer.ps1 | 2 +- SnipeitPS/Public/New-Model.ps1 | 2 +- SnipeitPS/Public/Set-Asset.ps1 | 2 +- SnipeitPS/Public/Set-AssetOwner.ps1 | 2 +- SnipeitPS/Public/Set-Components.ps1 | 2 +- 14 files changed, 14 insertions(+), 14 deletions(-) diff --git a/SnipeitPS/Public/Get-Asset.ps1 b/SnipeitPS/Public/Get-Asset.ps1 index 33a377f..4eb0e2d 100644 --- a/SnipeitPS/Public/Get-Asset.ps1 +++ b/SnipeitPS/Public/Get-Asset.ps1 @@ -32,7 +32,7 @@ function Get-Asset() Token = $apiKey } - $result = Invoke-Method @Parameters + $result = Invoke-SnipeitMethod @Parameters $result } diff --git a/SnipeitPS/Public/Get-Category.ps1 b/SnipeitPS/Public/Get-Category.ps1 index 77b4c84..0b11baa 100644 --- a/SnipeitPS/Public/Get-Category.ps1 +++ b/SnipeitPS/Public/Get-Category.ps1 @@ -32,7 +32,7 @@ function Get-Category() Token = $apiKey } - $result = Invoke-Method @Parameters + $result = Invoke-SnipeitMethod @Parameters $result } diff --git a/SnipeitPS/Public/Get-Component.ps1 b/SnipeitPS/Public/Get-Component.ps1 index 9e1ca7f..bb985f7 100644 --- a/SnipeitPS/Public/Get-Component.ps1 +++ b/SnipeitPS/Public/Get-Component.ps1 @@ -32,7 +32,7 @@ function Get-Component() Token = $apiKey } - $result = Invoke-Method @Parameters + $result = Invoke-SnipeitMethod @Parameters $result } diff --git a/SnipeitPS/Public/Get-Manufacturer.ps1 b/SnipeitPS/Public/Get-Manufacturer.ps1 index edb7972..fb06d4f 100644 --- a/SnipeitPS/Public/Get-Manufacturer.ps1 +++ b/SnipeitPS/Public/Get-Manufacturer.ps1 @@ -32,7 +32,7 @@ function Get-Manufacturer() Token = $apiKey } - $result = Invoke-Method @Parameters + $result = Invoke-SnipeitMethod @Parameters $result } diff --git a/SnipeitPS/Public/Get-Model.ps1 b/SnipeitPS/Public/Get-Model.ps1 index 218ae64..f531107 100644 --- a/SnipeitPS/Public/Get-Model.ps1 +++ b/SnipeitPS/Public/Get-Model.ps1 @@ -32,7 +32,7 @@ function Get-Model() Token = $apiKey } - $result = Invoke-Method @Parameters + $result = Invoke-SnipeitMethod @Parameters $result } diff --git a/SnipeitPS/Public/Get-Status.ps1 b/SnipeitPS/Public/Get-Status.ps1 index 0ec7eec..948a9b3 100644 --- a/SnipeitPS/Public/Get-Status.ps1 +++ b/SnipeitPS/Public/Get-Status.ps1 @@ -32,7 +32,7 @@ function Get-Status() Token = $apiKey } - $result = Invoke-Method @Parameters + $result = Invoke-SnipeitMethod @Parameters $result } diff --git a/SnipeitPS/Public/Get-User.ps1 b/SnipeitPS/Public/Get-User.ps1 index 27d681b..a11a455 100644 --- a/SnipeitPS/Public/Get-User.ps1 +++ b/SnipeitPS/Public/Get-User.ps1 @@ -34,7 +34,7 @@ function Get-User() Token = $apiKey } - $result = Invoke-Method @Parameters + $result = Invoke-SnipeitMethod @Parameters $result } diff --git a/SnipeitPS/Public/New-Asset.ps1 b/SnipeitPS/Public/New-Asset.ps1 index 0cfc706..db6c7f6 100644 --- a/SnipeitPS/Public/New-Asset.ps1 +++ b/SnipeitPS/Public/New-Asset.ps1 @@ -84,7 +84,7 @@ function New-Asset() If ($PSCmdlet.ShouldProcess("ShouldProcess?")) { - $result = Invoke-Method @Parameters + $result = Invoke-SnipeitMethod @Parameters } $result diff --git a/SnipeitPS/Public/New-Component.ps1 b/SnipeitPS/Public/New-Component.ps1 index 3f57891..7105811 100644 --- a/SnipeitPS/Public/New-Component.ps1 +++ b/SnipeitPS/Public/New-Component.ps1 @@ -68,7 +68,7 @@ function New-Component() If ($PSCmdlet.ShouldProcess("ShouldProcess?")) { - $result = Invoke-Method @Parameters + $result = Invoke-SnipeitMethod @Parameters } $result diff --git a/SnipeitPS/Public/New-Manufacturer.ps1 b/SnipeitPS/Public/New-Manufacturer.ps1 index 5ccca1e..b198a60 100644 --- a/SnipeitPS/Public/New-Manufacturer.ps1 +++ b/SnipeitPS/Public/New-Manufacturer.ps1 @@ -53,7 +53,7 @@ function New-Manufacturer() If ($PSCmdlet.ShouldProcess("ShouldProcess?")) { - $result = Invoke-Method @Parameters + $result = Invoke-SnipeitMethod @Parameters } $result diff --git a/SnipeitPS/Public/New-Model.ps1 b/SnipeitPS/Public/New-Model.ps1 index ae19efa..c7a5067 100644 --- a/SnipeitPS/Public/New-Model.ps1 +++ b/SnipeitPS/Public/New-Model.ps1 @@ -72,7 +72,7 @@ function New-Model() If ($PSCmdlet.ShouldProcess("ShouldProcess?")) { - $result = Invoke-Method @Parameters + $result = Invoke-SnipeitMethod @Parameters } $result diff --git a/SnipeitPS/Public/Set-Asset.ps1 b/SnipeitPS/Public/Set-Asset.ps1 index a821450..a53391a 100644 --- a/SnipeitPS/Public/Set-Asset.ps1 +++ b/SnipeitPS/Public/Set-Asset.ps1 @@ -84,7 +84,7 @@ function Set-Asset() If ($PSCmdlet.ShouldProcess("ShouldProcess?")) { - $result = Invoke-Method @Parameters + $result = Invoke-SnipeitMethod @Parameters } $result diff --git a/SnipeitPS/Public/Set-AssetOwner.ps1 b/SnipeitPS/Public/Set-AssetOwner.ps1 index 18d6ccc..e58febe 100644 --- a/SnipeitPS/Public/Set-AssetOwner.ps1 +++ b/SnipeitPS/Public/Set-AssetOwner.ps1 @@ -34,7 +34,7 @@ function Set-AssetOwner() If ($PSCmdlet.ShouldProcess("ShouldProcess?")) { - $result = Invoke-Method @Parameters + $result = Invoke-SnipeitMethod @Parameters } return $result diff --git a/SnipeitPS/Public/Set-Components.ps1 b/SnipeitPS/Public/Set-Components.ps1 index 90f97ce..84dd6b8 100644 --- a/SnipeitPS/Public/Set-Components.ps1 +++ b/SnipeitPS/Public/Set-Components.ps1 @@ -34,7 +34,7 @@ function Set-Component() If ($PSCmdlet.ShouldProcess("ShouldProcess?")) { - $result = Invoke-Method @Parameters + $result = Invoke-SnipeitMethod @Parameters } $result