mirror of
https://github.com/snazy2000/SnipeitPS.git
synced 2025-12-15 02:35:47 +00:00
Compare commits
395 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d14244d727 | ||
|
|
fadfa2d797 | ||
|
|
3a5d951cb9 | ||
|
|
7582b0fa1a | ||
|
|
381b6e3586 | ||
|
|
79b94981ec | ||
|
|
6b3bc0f459 | ||
|
|
4a889cfb44 | ||
|
|
98095b6a53 | ||
|
|
758c5140b6 | ||
|
|
d70f22d5f5 | ||
|
|
5feafa0574 | ||
|
|
72215faf0b | ||
|
|
8af189e95b | ||
|
|
56a4525230 | ||
|
|
32c95f8077 | ||
|
|
cc475abf8c | ||
|
|
f3391bb521 | ||
|
|
5aa6a2eed5 | ||
|
|
452573c9a0 | ||
|
|
72c6ccbd38 | ||
|
|
e321cd3fa1 | ||
|
|
b4c2b51024 | ||
|
|
f26db93a16 | ||
|
|
51cb9f88f5 | ||
|
|
68ae039013 | ||
|
|
9e014ad06b | ||
|
|
7ac8a5c9bd | ||
|
|
e2923cade8 | ||
|
|
e10f520008 | ||
|
|
4e4a739418 | ||
|
|
2f1873497d | ||
|
|
db2fb6278c | ||
|
|
536bff19bb | ||
|
|
ec40912018 | ||
|
|
83e8e43bc2 | ||
|
|
26ae35d1bd | ||
|
|
2a6d62bff5 | ||
|
|
dd2bf7371e | ||
|
|
612d08c5d3 | ||
|
|
d224f97d73 | ||
|
|
0f7e6b3fc6 | ||
|
|
10e87b48cc | ||
|
|
b5fe626f6c | ||
|
|
b90e1a94ea | ||
|
|
3f39425a6c | ||
|
|
422cf7b32e | ||
|
|
bc88c6d8cf | ||
|
|
bc48d74650 | ||
|
|
fbef90ee79 | ||
|
|
f4592ae9f2 | ||
|
|
c81d77962a | ||
|
|
44fb65ca60 | ||
|
|
8c79c0fe6d | ||
|
|
96dc4e0907 | ||
|
|
0c72cb5155 | ||
|
|
afeb8df60e | ||
|
|
69faba1856 | ||
|
|
88a94115b1 | ||
|
|
923838e15f | ||
|
|
3446a885dc | ||
|
|
bc0b266339 | ||
|
|
e934d20ced | ||
|
|
64d4d4f55d | ||
|
|
7022b9fc3b | ||
|
|
6e1d7ebdb5 | ||
|
|
0a227795ed | ||
|
|
721e6c5e3a | ||
|
|
7a83c09370 | ||
|
|
e43e09b752 | ||
|
|
0acba743d8 | ||
|
|
b85a653794 | ||
|
|
2485854729 | ||
|
|
dfe6146d3d | ||
|
|
3bcf47c945 | ||
|
|
ed080618a7 | ||
|
|
0afd33368b | ||
|
|
4c0b9b0e85 | ||
|
|
7b2cffda28 | ||
|
|
cde16b1983 | ||
|
|
52dfdb62f5 | ||
|
|
0acac3a29f | ||
|
|
64902b58b5 | ||
|
|
fab7a71abf | ||
|
|
ae68666bbd | ||
|
|
794589622a | ||
|
|
ec3b9b4972 | ||
|
|
464c9430f7 | ||
|
|
11e087944a | ||
|
|
7f6a5e1244 | ||
|
|
fd2f5c51c7 | ||
|
|
ccce2ab26f | ||
|
|
65f03b0476 | ||
|
|
9f84595e36 | ||
|
|
bab98270fa | ||
|
|
989af1bf88 | ||
|
|
9b356a2b9e | ||
|
|
7871fc3711 | ||
|
|
3ac0bbceb2 | ||
|
|
e8077d5c21 | ||
|
|
9ff9617b38 | ||
|
|
d4b6fc595b | ||
|
|
44a5886f09 | ||
|
|
508e484b17 | ||
|
|
193f3f7f11 | ||
|
|
95839398e9 | ||
|
|
9bfa4173de | ||
|
|
2d7c315424 | ||
|
|
0759f0b6b3 | ||
|
|
6099ab7eea | ||
|
|
d5c25e2bdc | ||
|
|
041c3da73b | ||
|
|
b337608d7b | ||
|
|
64fa3799fe | ||
|
|
9ecf9e7313 | ||
|
|
12d8b76aa6 | ||
|
|
c7c349ca99 | ||
|
|
baabd3eaa8 | ||
|
|
cbb9e13a45 | ||
|
|
6dc704c0fc | ||
|
|
bd21037466 | ||
|
|
6dba0ae2f6 | ||
|
|
7de0a38f9e | ||
|
|
dde27f055e | ||
|
|
b9de3ddaa0 | ||
|
|
208477f269 | ||
|
|
6e8d27e69d | ||
|
|
b78fe104e3 | ||
|
|
45b3bfab33 | ||
|
|
115fd7bd5a | ||
|
|
750d4129fd | ||
|
|
959c679f33 | ||
|
|
bd7d4ce5ff | ||
|
|
14ae8c1922 | ||
|
|
376949498d | ||
|
|
36a9fe3d04 | ||
|
|
d9be192b3e | ||
|
|
2850b82a16 | ||
|
|
28a6ffd05f | ||
|
|
aaeab1cb27 | ||
|
|
c485fcd230 | ||
|
|
da7dd14c4b | ||
|
|
eb3b334e42 | ||
|
|
cbc80dc633 | ||
|
|
fad878460a | ||
|
|
b19aa28e41 | ||
|
|
ec6c96f2c4 | ||
|
|
8ec56d8e7f | ||
|
|
6f267ce94d | ||
|
|
42a6a563ee | ||
|
|
28023285a0 | ||
|
|
6b4bad903b | ||
|
|
42f8776e49 | ||
|
|
53b1560d83 | ||
|
|
9d5c3e7850 | ||
|
|
bb00f1bc5e | ||
|
|
6254b82e3a | ||
|
|
7d6aa54279 | ||
|
|
3a0b1d853a | ||
|
|
e8d52ab59c | ||
|
|
528367cbd6 | ||
|
|
cd86c6749d | ||
|
|
83eb363889 | ||
|
|
dfb271dbec | ||
|
|
1b5e5e5237 | ||
|
|
b35230e3b8 | ||
|
|
621ee76709 | ||
|
|
ac842e3d6a | ||
|
|
b495032167 | ||
|
|
211460cfb6 | ||
|
|
b76d78ec05 | ||
|
|
3c45eceff9 | ||
|
|
d8652d0cba | ||
|
|
a69a583429 | ||
|
|
0d201e6a6b | ||
|
|
dbef8c5a26 | ||
|
|
19fb68fc6d | ||
|
|
7644e08f2a | ||
|
|
18192e9eb0 | ||
|
|
d661545228 | ||
|
|
03ed9d3a27 | ||
|
|
068b661978 | ||
|
|
f89fb1f31a | ||
|
|
6ef20bd333 | ||
|
|
843f10bbb4 | ||
|
|
a27f20f0cd | ||
|
|
69f498e06f | ||
|
|
d6a8289241 | ||
|
|
bfebf0603f | ||
|
|
222eff98f8 | ||
|
|
e50d7bd5cb | ||
|
|
2309dd682f | ||
|
|
8c41f41644 | ||
|
|
0eb9324597 | ||
|
|
97b46a66ad | ||
|
|
92d67895df | ||
|
|
b24b0fce1d | ||
|
|
f8f5224cc8 | ||
|
|
9f68e602e3 | ||
|
|
727c1b4785 | ||
|
|
8fad0f653c | ||
|
|
2739a4f438 | ||
|
|
1e31256487 | ||
|
|
9562ab3d46 | ||
|
|
ce1fdcc115 | ||
|
|
064ff9c4ed | ||
|
|
a2bda89abb | ||
|
|
d4c138604d | ||
|
|
0cbfbab86e | ||
|
|
7317157dfc | ||
|
|
7ba3de55bb | ||
|
|
0b1d7f9c95 | ||
|
|
b062072239 | ||
|
|
0d832f07cc | ||
|
|
4744e6c8fe | ||
|
|
213386f440 | ||
|
|
1742db7f5e | ||
|
|
fca66e4f7a | ||
|
|
3f58e8eaac | ||
|
|
01e1746b2c | ||
|
|
1b45467675 | ||
|
|
446a21fcf7 | ||
|
|
eed5a09ba2 | ||
|
|
4810bbf54f | ||
|
|
5a10799eb8 | ||
|
|
66e746bce0 | ||
|
|
9a7bc1339c | ||
|
|
5d15719185 | ||
|
|
09d16fe5a5 | ||
|
|
32542fe5fc | ||
|
|
160ba60069 | ||
|
|
64dcc2e127 | ||
|
|
ad5c8b3231 | ||
|
|
f12e1346db | ||
|
|
5934568b20 | ||
|
|
575a17c6d1 | ||
|
|
3938f360d3 | ||
|
|
33aa1d64bf | ||
|
|
17b8a726d1 | ||
|
|
4c230807aa | ||
|
|
69ac809fb0 | ||
|
|
906fedd71a | ||
|
|
06305b1b63 | ||
|
|
8d1dd48b2c | ||
|
|
7d95d5078f | ||
|
|
ee0d285ab0 | ||
|
|
bb4cf89bdd | ||
|
|
f98315a614 | ||
|
|
e34b36db21 | ||
|
|
9dece1ceff | ||
|
|
e80c6be8f9 | ||
|
|
b58267e222 | ||
|
|
cdc60fbeaa | ||
|
|
ccbe86c2c9 | ||
|
|
46aa80b16f | ||
|
|
fe39b3cb32 | ||
|
|
5bc402b847 | ||
|
|
d4e2360d72 | ||
|
|
bf13cdab6f | ||
|
|
5c17660cca | ||
|
|
c5e02c8cfb | ||
|
|
8fbd9297cd | ||
|
|
1456b17a0a | ||
|
|
d4d50d8fd5 | ||
|
|
8d33d687b0 | ||
|
|
5213efcc00 | ||
|
|
2a29a8a869 | ||
|
|
5697df0049 | ||
|
|
5d945b9327 | ||
|
|
5652588493 | ||
|
|
05134e77ed | ||
|
|
db41381010 | ||
|
|
7b20f86fb4 | ||
|
|
5ae9875692 | ||
|
|
2ded293ede | ||
|
|
75fb4caad9 | ||
|
|
d5d282541f | ||
|
|
fe1bcc52f7 | ||
|
|
8fd8082aa3 | ||
|
|
5761f15eab | ||
|
|
c906c15890 | ||
|
|
d2805b1ffd | ||
|
|
26e67d2b29 | ||
|
|
738b4c6051 | ||
|
|
cb66a0112a | ||
|
|
312eb8e8df | ||
|
|
a3ab7f4fd9 | ||
|
|
981e90e103 | ||
|
|
4ed189b45d | ||
|
|
b8923b2029 | ||
|
|
c72eaf7c95 | ||
|
|
997af62157 | ||
|
|
589c34539c | ||
|
|
7dde5ce1de | ||
|
|
3804a6df17 | ||
|
|
d51a3d2d45 | ||
|
|
d52e63d2c9 | ||
|
|
44c14d6cc0 | ||
|
|
b380e861c8 | ||
|
|
5b3d63f9bc | ||
|
|
51ddcf8847 | ||
|
|
d3cf37173d | ||
|
|
b24277ac4c | ||
|
|
6c5be69f6c | ||
|
|
cbf8e92f4d | ||
|
|
f2db33fa59 | ||
|
|
dad8156c60 | ||
|
|
7fa802197b | ||
|
|
726f5809cd | ||
|
|
51b65be06c | ||
|
|
756223f7b7 | ||
|
|
dccbd18add | ||
|
|
50068f7e62 | ||
|
|
5fea2cf86d | ||
|
|
5a30192d8f | ||
|
|
85fa16ae70 | ||
|
|
63f6ae12e2 | ||
|
|
0708776249 | ||
|
|
a4bc6bb3f0 | ||
|
|
ddb0036156 | ||
|
|
d3fb9762ab | ||
|
|
6828244dfa | ||
|
|
a5e691d8f0 | ||
|
|
22ea1ceeb8 | ||
|
|
e559e71143 | ||
|
|
35a4ab68fe | ||
|
|
fdf52ce2e4 | ||
|
|
8ae7ff7622 | ||
|
|
1b12288920 | ||
|
|
a09eb8c23e | ||
|
|
3c064938e1 | ||
|
|
608d8f04ca | ||
|
|
953a3453fc | ||
|
|
f688b32c50 | ||
|
|
c3cb7d14b6 | ||
|
|
2925106297 | ||
|
|
d78d5d5281 | ||
|
|
9afb3a1be6 | ||
|
|
c88dd83323 | ||
|
|
f182756b30 | ||
|
|
efe36f81f2 | ||
|
|
1c31e67419 | ||
|
|
2f32d12aa1 | ||
|
|
fe5e3c6ba2 | ||
|
|
13fa97f36f | ||
|
|
af62a28bef | ||
|
|
b3826d33ec | ||
|
|
95eed3330c | ||
|
|
54b7b4db3b | ||
|
|
ea04619706 | ||
|
|
bb53a87cf4 | ||
|
|
4385d87093 | ||
|
|
8214d8db99 | ||
|
|
54043c68e4 | ||
|
|
0e07eed7d1 | ||
|
|
4ae8b11e10 | ||
|
|
3266e6ae91 | ||
|
|
bead7cbe8d | ||
|
|
28a3d40d51 | ||
|
|
059f9e3938 | ||
|
|
bfa0aa1de0 | ||
|
|
a779b8c782 | ||
|
|
998016b135 | ||
|
|
03e2fdf043 | ||
|
|
e6360a0def | ||
|
|
d2e70120bb | ||
|
|
e5c9a9db51 | ||
|
|
381ee730fd | ||
|
|
621bab7d4e | ||
|
|
7cbcd575f6 | ||
|
|
96c39e04a1 | ||
|
|
217ca45578 | ||
|
|
2ec48c67a1 | ||
|
|
a3eb07c246 | ||
|
|
cab9e4d993 | ||
|
|
13dde3903b | ||
|
|
12415c5cf3 | ||
|
|
90f664a56a | ||
|
|
55268bfe88 | ||
|
|
3cf0baff41 | ||
|
|
1b5b8428d4 | ||
|
|
cdfd8442ff | ||
|
|
6307dc3d9d | ||
|
|
3f9b01f92f | ||
|
|
d33aa90549 | ||
|
|
56852d863e | ||
|
|
29345d496d | ||
|
|
4f22833342 | ||
|
|
1ec8bf1b13 | ||
|
|
196952bddc | ||
|
|
6611be2171 | ||
|
|
b61f89fee2 | ||
|
|
f175d33951 | ||
|
|
b967ebbf50 | ||
|
|
51bf9f43cd |
208 changed files with 24952 additions and 4087 deletions
32
.github/ISSUE_TEMPLATE.md
vendored
Normal file
32
.github/ISSUE_TEMPLATE.md
vendored
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
## Context
|
||||
<!--- How has this issue affected you? What are you trying to accomplish? -->
|
||||
<!--- Providing context helps us come up with a solution that is most useful in the real world -->
|
||||
|
||||
## Your Environment
|
||||
<!--- Include as many relevant details about the environment you experienced the bug in -->
|
||||
* SnipitPS Module version used:
|
||||
* Operating System and PowerShell version:
|
||||
* Snipe It version:
|
||||
|
||||
## Expected Behavior
|
||||
<!--- If you're describing a bug, tell us what should happen -->
|
||||
<!--- If you're suggesting a change/improvement, tell us how it should work -->
|
||||
|
||||
## Current Behavior
|
||||
<!--- If describing a bug, tell us what happens instead of the expected behavior -->
|
||||
<!--- Please add command output with -Verbose and if possible -Debug switches -->
|
||||
|
||||
## Possible Solution
|
||||
<!--- Not obligatory, but suggest a fix/reason for the bug, -->
|
||||
<!--- or ideas how to implement the addition or change -->
|
||||
|
||||
## Steps to Reproduce (for bugs)
|
||||
<!--- Provide a link to a live example, or an unambiguous set of steps to -->
|
||||
<!--- reproduce this bug. Include code to reproduce, if relevant -->
|
||||
1.
|
||||
2.
|
||||
3.
|
||||
4.
|
||||
|
||||
|
||||
|
||||
198
CHANGELOG.md
198
CHANGELOG.md
|
|
@ -5,4 +5,200 @@ 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
|
||||
# [v.1.10.x] - 2021-09-03
|
||||
|
||||
## New secure ways to connect Snipe it
|
||||
|
||||
### -secureApiKey allow pass apiKey as SecureString
|
||||
Connect-SnipeitPS -URL 'https://asset.example.com' -secureApiKey 'tokenKey'
|
||||
|
||||
### Set connection with safely saved credentials, first save credentials
|
||||
$SnipeCred= Get-Credential -message "Use url as username and apikey as password"
|
||||
$SnipeCred | Export-CliXml snipecred.xml
|
||||
|
||||
### ..then use your saved credentials like
|
||||
Connect-SnipeitPS -siteCred (Import-CliXml snipecred.xml)
|
||||
|
||||
## Fix for content encoding in invoke-snipeitmethod
|
||||
Version 1.9 introduced bug that converted non ascii characters to ascii
|
||||
during request.
|
||||
|
||||
# [v.1.9.x] - 2021-07-14
|
||||
|
||||
## Image uploads
|
||||
|
||||
## New features
|
||||
Support for image upload and removes. Just specify filename for -image para-
|
||||
meter when creating or updating item on snipe.
|
||||
Remove image use -image_delete parameter.
|
||||
|
||||
*Snipe It version greater than 5.1.8 is needed to support image parameters.*
|
||||
|
||||
Most of set-commands have new -RequestType parameter that defaults to Patch.
|
||||
If needed request method can be changed from default.
|
||||
|
||||
## New Functions
|
||||
Following new commands have been added to SnipeitPS:
|
||||
- New-Supplier
|
||||
- Set-Supplier
|
||||
- Remove-Supplier
|
||||
- Set-Manufacturer
|
||||
|
||||
|
||||
# [v.1.8.x] - 2021-06-17
|
||||
|
||||
## Support for new Snipe it endpoints
|
||||
|
||||
## New features
|
||||
|
||||
Get-SnipeitAccessories -user_id
|
||||
returns accessories checked out to user id
|
||||
|
||||
Get-SnipeitAsset -user_id
|
||||
Return Assets checked out to user id
|
||||
|
||||
Get-SnipeitAsset -component_id
|
||||
Returns assets with specific component id
|
||||
|
||||
Get-SnipeitLicense -user_id
|
||||
Get licenses checked out to user ID
|
||||
|
||||
Get-SnipeitLicense -asset_id
|
||||
Get licenses checked out to asset ID
|
||||
|
||||
Get-SnipeitUser -accessory_id
|
||||
Get users that have specific accessory id checked out
|
||||
|
||||
# [v.1.7.x] - 2021-06-14
|
||||
|
||||
## Consumables
|
||||
|
||||
## New features
|
||||
Added support for consumables
|
||||
|
||||
## New functions
|
||||
- New-SnipeitConsumable
|
||||
- Get-SnipeitConsumable
|
||||
- Set-SnipeitConsumable
|
||||
- Remove-SnipeitConsumable
|
||||
|
||||
|
||||
# [v.1.6.x] - 2021-06-14
|
||||
|
||||
## Remove more things ja set some more
|
||||
|
||||
### New features
|
||||
Added some set and remove functions. Pipelineinput supported
|
||||
for all remove functions.
|
||||
|
||||
### New functions
|
||||
- Remove-SnipeitAccessory
|
||||
- Remove-SnipeitCategory
|
||||
- Remove-SnipeitCompany
|
||||
- Remove-SnipeitComponent
|
||||
- Remove-SnipeitCustomField
|
||||
- Remove-SnipeitDepartment
|
||||
- Remove-SnipeitLicense
|
||||
- Remove-SnipeitLocation
|
||||
- Remove-SnipeitManufacturer
|
||||
- Remove-SnipeitModel
|
||||
- Set-SnipeitCategory
|
||||
- Set-SnipeitCompany
|
||||
- Set-SnipeitCustomField
|
||||
- Set-SnipeitDepartment
|
||||
- Set-SnipeitStatus
|
||||
|
||||
|
||||
# [v1.5.x] - 2021-06-08
|
||||
|
||||
## Piping input
|
||||
|
||||
### New features
|
||||
Most of "Set" command accepts piped input. Piped objects "id" attribute
|
||||
is used to select asset set values. Like
|
||||
Get-SnipeitAsset -model_id 213 | Set-SnipeitAsset -notes 'This is nice!'
|
||||
|
||||
Set command accept id parameter as array, so its easier to set multiple items
|
||||
in one run.
|
||||
|
||||
Parameter sets. Get commands have now parameters sets.This will make syntax more
|
||||
clear between search and get by ID use. Use get-help to
|
||||
|
||||
### Fixes
|
||||
-Empty strings are accepted as input so it's possible to wipe field values if
|
||||
needed
|
||||
|
||||
# [v1.4.x] - 2021-05-27
|
||||
|
||||
## More Activity
|
||||
|
||||
### New features
|
||||
Snipeit activity history is now searchable. So finding out checked out the
|
||||
assest its easy. Api support many different target or item types that can
|
||||
be uses as filter. Searchable types are 'Accessory','Asset','AssetMaintenance'
|
||||
,'AssetModel','Category','Company','Component','Consumable','CustomField',
|
||||
,'Group','Licence','LicenseSeat','Location','Manufacturer','Statuslabel',
|
||||
'Supplier','User'
|
||||
|
||||
|
||||
### New Functions
|
||||
- Get-SnipeitActivity Get and search Snipe-It change history.
|
||||
|
||||
|
||||
# [v1.3.x] - 2021-05-27
|
||||
|
||||
## Checking out accessories
|
||||
|
||||
### New features
|
||||
You can specify Put or Patch for Set-SnipeitAsset when updating assets.
|
||||
Set-SnipeitLocation new -city parameter
|
||||
|
||||
### New Functions
|
||||
- Set-SnipeitAccessoryOwner checkout accessory
|
||||
- Get-SnipeitAccessoryOwner list checkedout accessories
|
||||
- Reset-SnipeitAccessoryOwner checkin accessory
|
||||
|
||||
### Fixes
|
||||
- Set-SnipeitAsset fixed datetime and name inputs #126,128
|
||||
-
|
||||
|
||||
# [v1.2.x] - 2021-05-24
|
||||
|
||||
## Prefixing SnipeitPS
|
||||
|
||||
### New Features
|
||||
All commands are now prefixed like Set-Info -> Set-SnipeitInfo.
|
||||
To keep compatibility all old commands are available as aliases.
|
||||
To update existing scripts theres Update-SnipeitAlias command.
|
||||
|
||||
### New fuctions
|
||||
- Update-SnipeitAlias Tool to update existing scripts
|
||||
- Get-SnipeitLicenceSeat lists license seats
|
||||
- Set-SnipeitLicenseSeat Set and checkouts/in license seats
|
||||
Licenseseat api is supported from Snipe-It release => v5.1.5
|
||||
|
||||
### New fixes
|
||||
Added -id parameter support to support Get-SnipeitCustomField and
|
||||
Get-SnipeitFieldSet commands
|
||||
|
||||
# [v1.1.x] - 2021-05-18
|
||||
|
||||
## Pull request rollup release. Lots of new features including:
|
||||
|
||||
### New features
|
||||
- Powershell 7 compatibility. So you can use SnipeitPS on macos or linux .
|
||||
- Get every asset, model, licence with snipeit id by using -id parameter
|
||||
- Get assets also by -asset_tag -or serialnumber
|
||||
- Get functions also return all results from snipe when using -all parameter (by @PetriAsi)
|
||||
|
||||
### New functions
|
||||
- Reset-AssetOwner by @lunchboxrts
|
||||
- Remove-Asset by @sheppyh
|
||||
- Added Remove-AssetMaintenance by @sheppyh
|
||||
- Remove-User @gvoynov
|
||||
|
||||
### Fixes
|
||||
- Fixed version number on powershell gallery
|
||||
- Fixed Set-AssetOwner when checking asset out to an other asset.
|
||||
|
||||
## [v1.0] - 2017-11-18
|
||||
|
|
|
|||
27
README.md
27
README.md
|
|
@ -2,6 +2,10 @@
|
|||
|
||||
---
|
||||
|
||||
## Want to say thanks?
|
||||
|
||||
[](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=XP29MAD7P3WDN&source=url)
|
||||
|
||||
## Instructions
|
||||
|
||||
### Installation
|
||||
|
|
@ -15,9 +19,23 @@ Install-Module SnipeitPS
|
|||
# Check for updates occasionally:
|
||||
Update-Module SnipeitPS
|
||||
|
||||
# To use each session:
|
||||
# import module to session:
|
||||
Import-Module SnipeitPS
|
||||
Set-Info -URL 'https://asset.example.com' -apiKey 'tokenKey'
|
||||
|
||||
# Set connection
|
||||
Connect-SnipeitPS -URL 'https://asset.example.com' -apiKey 'tokenKey'
|
||||
|
||||
# Or set connection with safely saved credentials, first save credentials
|
||||
$SnipeCred =Get-Credential -message "Use url as username and apikey as password"
|
||||
$SnipeCred | Export-CliXml snipecred.xml
|
||||
|
||||
# ..then use your saved credentials like
|
||||
Connect-SnipeitPS -siteCred (Import-CliXml snipecred.xml)
|
||||
|
||||
# OR use -secureApiKey that allow pass apiKey as SecureString
|
||||
# if you are usin Microsoft.PowerShell.SecretManagement or like
|
||||
Connect-SnipeitPS -URL 'https://asset.example.com' -secureApiKey 'tokenKey'
|
||||
|
||||
```
|
||||
|
||||
### Usage
|
||||
|
|
@ -26,5 +44,8 @@ Set-Info -URL 'https://asset.example.com' -apiKey 'tokenKey'
|
|||
# Review the help at any time!
|
||||
Get-Help about_SnipeitPS
|
||||
Get-Command -Module SnipeitPS
|
||||
Get-Help Get-Asset -Full # or any other command
|
||||
Get-Help Get-SnipeitAsset -Full # or any other command
|
||||
```
|
||||
### Reporting bugs and issues
|
||||
Please use -Verbose switch with command you have problem with.
|
||||
Then create ticket here with all -Verbose output
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ $env:PSModulePath = "$($env:PSModulePath);$releasePath"
|
|||
Import-Module BuildHelpers
|
||||
|
||||
# Ensure Invoke-Build works in the most strict mode.
|
||||
Set-StrictMode -Version Latest
|
||||
#Set-StrictMode -Version Latest
|
||||
|
||||
# region debug information
|
||||
task ShowDebug {
|
||||
|
|
@ -88,15 +88,14 @@ task GitStatus -If (Test-Path .git) {
|
|||
}
|
||||
}
|
||||
|
||||
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}
|
||||
task TestVersions TestPS
|
||||
|
||||
task TestPS {
|
||||
if($env:PShell -eq '7') {
|
||||
exec {pwsh.exe -NoProfile Invoke-Build PesterTests}
|
||||
}else {
|
||||
exec {powershell.exe -NoProfile Invoke-Build PesterTests}
|
||||
}
|
||||
}
|
||||
|
||||
# Synopsis: Invoke Pester Tests
|
||||
|
|
@ -192,7 +191,9 @@ task Deploy -If (
|
|||
(-not ($env:APPVEYOR_PULL_REQUEST_NUMBER)) -and
|
||||
# Do not deploy if the commit contains the string "skip-deploy"
|
||||
# Meant for major/minor version publishes with a .0 build/patch version (like 2.1.0)
|
||||
$env:APPVEYOR_REPO_COMMIT_MESSAGE -notlike '*skip-deploy*'
|
||||
$env:APPVEYOR_REPO_COMMIT_MESSAGE -notlike '*skip-deploy*' -and
|
||||
# publish from one powershell version is enought
|
||||
$env:PShell -eq '5'
|
||||
) {
|
||||
Remove-Module SnipeitPS -ErrorAction SilentlyContinue
|
||||
}, PublishToGallery
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
function ConvertTo-GetParameter {
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Generate the GET parameter string for an URL from a hashtable
|
||||
|
|
@ -14,9 +15,11 @@ function ConvertTo-GetParameter {
|
|||
}
|
||||
|
||||
PROCESS {
|
||||
Add-Type -AssemblyName System.Web
|
||||
|
||||
Write-Verbose "[$($MyInvocation.MyCommand.Name)] Making HTTP get parameter string out of a hashtable"
|
||||
foreach ($key in $InputObject.Keys) {
|
||||
$parameters += "$key=$($InputObject[$key])&"
|
||||
$parameters += "$key=$([System.Web.HttpUtility]::UrlEncode($InputObject[$key]))&"
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
69
SnipeitPS/Private/Get-ParameterValue.ps1
Normal file
69
SnipeitPS/Private/Get-ParameterValue.ps1
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
function Get-ParameterValue {
|
||||
#.Synopsis
|
||||
# Get the actual values of parameters which have manually set (non-null) default values or values passed in the call
|
||||
#.Description
|
||||
# Unlike $PSBoundParameters, the hashtable returned from Get-ParameterValues includes non-empty default parameter values.
|
||||
# NOTE: Default values that are the same as the implied values are ignored (e.g.: empty strings, zero numbers, nulls).
|
||||
#.Example
|
||||
# function Test-Parameters {
|
||||
# [CmdletBinding()]
|
||||
# param(
|
||||
# $Name = $Env:UserName,
|
||||
# $Age
|
||||
# )
|
||||
# $Parameters = . Get-ParameterValues
|
||||
#
|
||||
# # This WILL ALWAYS have a value...
|
||||
# Write-Host $Parameters["Name"]
|
||||
#
|
||||
# # But this will NOT always have a value...
|
||||
# Write-Host $PSBoundParameters["Name"]
|
||||
# }
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
# Pass $MyInvocation.MyCommand.Parameters to function, powershell 7 seems to only populate variables with dot sourcing
|
||||
[parameter(mandatory = $true)]
|
||||
$Parameters
|
||||
,
|
||||
[parameter(mandatory = $true)]
|
||||
$BoundParameters,
|
||||
|
||||
[string[]]$DefaultExcludeParameter = @("id", "url", "apiKey", 'Debug', 'Verbose','RequestType','customfields')
|
||||
)
|
||||
|
||||
if ($MyInvocation.Line[($MyInvocation.OffsetInLine - 1)] -ne '.') {
|
||||
throw "Get-ParameterValue must be dot-sourced, like this: . Get-ParameterValues"
|
||||
}
|
||||
|
||||
|
||||
$ParameterValues = @{}
|
||||
foreach ($parameter in $Parameters.GetEnumerator()) {
|
||||
# gm -in $parameter.Value | Out-Default
|
||||
try {
|
||||
$key = $parameter.Key
|
||||
if ($key -notin $DefaultExcludeParameter) {
|
||||
#Fill in default parameters values
|
||||
if ($null -ne ($value = Get-Variable -Name $key -ValueOnly -ErrorAction Ignore )) {
|
||||
if ($value -ne ($null -as $parameter.Value.ParameterType)) {
|
||||
$ParameterValues[$key] = $value
|
||||
}
|
||||
}
|
||||
#Fill in all given parameters even empty
|
||||
if ($BoundParameters.ContainsKey($key)) {
|
||||
$ParameterValues[$key] = $BoundParameters[$key]
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
finally {}
|
||||
}
|
||||
|
||||
#Convert switch parameters to booleans so it converts nicely to json
|
||||
foreach ( $key in @($ParameterValues.Keys)) {
|
||||
if ($true -eq $ParameterValues[$key].IsPresent){
|
||||
$ParameterValues[$key]=$true;
|
||||
}
|
||||
}
|
||||
|
||||
return $ParameterValues
|
||||
}
|
||||
38
SnipeitPS/Private/Get-SnipeitAlias.ps1
Normal file
38
SnipeitPS/Private/Get-SnipeitAlias.ps1
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
Function Get-SnipeitAlias(){
|
||||
@{'Get-Asset' = 'Get-SnipeitAsset';
|
||||
'Get-AssetMaintenance' = 'Get-SnipeitAssetMaintenance';
|
||||
'Get-Category' = 'Get-SnipeitCategory';
|
||||
'Get-Company' = 'Get-SnipeitCompany';
|
||||
'Get-Component' = 'Get-SnipeitCompany';
|
||||
'Get-CustomField' = 'Get-SnipeitCustomField';
|
||||
'Get-Department' = 'Get-SnipeitDepartment';
|
||||
'Get-Fieldset' = 'Get-SnipeitFieldset';
|
||||
'Get-Manufacturer' = 'Get-SnipeitManufacturer';
|
||||
'Get-Model' = 'Get-SnipeitModel';
|
||||
'Get-Status' = 'Get-SnipeitStatus';
|
||||
'Get-Supplier' = 'Get-SnipeitSupplier';
|
||||
'Get-User' = 'Get-SnipeitUser';
|
||||
'New-Asset' = 'New-SnipeitAsset';
|
||||
'New-AssetMaintenance' = 'New-SnipeitAssetMaintenance';
|
||||
'New-Category' = 'New-SnipeitCategory';
|
||||
'New-Component' = 'New-SnipeitComponent';
|
||||
'New-CustomField' = 'New-SnipeitCustomField';
|
||||
'New-Department' = 'New-SnipeitDepartment';
|
||||
'New-License' = 'New-SnipeitLicense';
|
||||
'Set-License' = 'Set-SnipeitLicense';
|
||||
'New-Location' = 'New-SnipeitLocation';
|
||||
'New-Manufacturer' = 'New-SnipeitManufacturer';
|
||||
'New-Model' = 'New-SnipeitModel';
|
||||
'New-User' = 'New-SnipeitUser';
|
||||
'Set-Asset' = 'Set-SnipeitAsset';
|
||||
'Set-AssetOwner' = 'Set-SnipeitAssetOwner';
|
||||
'Set-Component' = 'Set-SnipeitComponent';
|
||||
'Set-Model' = 'Set-SnipeitModel';
|
||||
'Set-Info' = 'Set-SnipeitInfo';
|
||||
'Set-User' = 'Set-SnipeitUser';
|
||||
'New-Accessory' = 'New-SnipeitAccessory';
|
||||
'Set-Accessory' = 'Set-SnipeitAccessory';
|
||||
'Get-Accessory' = 'Get-SnipeitAccessory';
|
||||
'Remove-Asset' = 'Remove-SnipeitAsset';
|
||||
'Remove-User' = 'Remove-SnipeitUser';}
|
||||
}
|
||||
|
|
@ -1,32 +1,62 @@
|
|||
function Invoke-SnipeitMethod {
|
||||
<#
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Extracted invokation of the REST method to own function.
|
||||
#>
|
||||
Make api request to Snipe it
|
||||
|
||||
.PARAMETER Api
|
||||
Api part of url. prefix with slash ie. "/api/v1/hardware"
|
||||
|
||||
.PARAMETER Method
|
||||
Method of the invokation, one of following "GET", "POST", "PUT", "PATCH" or "DELETE"
|
||||
|
||||
.PARAMETER Body
|
||||
Request body as hashtable. Needed for post, put and patch
|
||||
|
||||
.PARAMETER GetParameters
|
||||
Get-Parameters as hastable.
|
||||
#>
|
||||
|
||||
function Invoke-SnipeitMethod {
|
||||
[OutputType(
|
||||
[PSObject]
|
||||
)]
|
||||
param (
|
||||
# REST API to invoke
|
||||
[Parameter(Mandatory = $true)]
|
||||
[Uri]$URi,
|
||||
|
||||
# Method of the invokation
|
||||
param (
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string]$Api,
|
||||
|
||||
[ValidateSet("GET", "POST", "PUT", "PATCH", "DELETE")]
|
||||
[string]$Method = "GET",
|
||||
|
||||
# Body of the request
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]$Body,
|
||||
[Hashtable]$Body,
|
||||
|
||||
[string] $Token,
|
||||
|
||||
# GET Parameters
|
||||
[Hashtable]$GetParameters
|
||||
|
||||
)
|
||||
|
||||
BEGIN {
|
||||
#use legacy per command based url and apikey
|
||||
if ( $null -ne $SnipeitPSSession.legacyUrl -and $null -ne $SnipeitPSSession.legacyApiKey ) {
|
||||
[string]$Url = $SnipeitPSSession.legacyUrl
|
||||
Write-Debug "Invoke-SnipeitMethod url: $Url"
|
||||
if($PSVersionTable.PSVersion -ge '7.0'){
|
||||
$Token = ConvertFrom-SecureString -AsPlainText -SecureString $SnipeitPSSession.legacyApiKey
|
||||
} else {
|
||||
#convert to plaintext via credential
|
||||
$Token = (New-Object PSCredential "user",$SnipeitPSSession.legacyApiKey).GetNetworkCredential().Password
|
||||
}
|
||||
} elseif ($null -ne $SnipeitPSSession.url -and $null -ne $SnipeitPSSession.apiKey) {
|
||||
[string]$Url = $SnipeitPSSession.url
|
||||
Write-Debug "Invoke-SnipeitMethod url: $Url"
|
||||
if($PSVersionTable.PSVersion -ge '7.0'){
|
||||
$Token = ConvertFrom-SecureString -AsPlainText -SecureString $SnipeitPSSession.apiKey
|
||||
} else {
|
||||
#convert to plaintext via credential
|
||||
$Token = (New-Object PSCredential "user",$SnipeitPSSession.apiKey).GetNetworkCredential().Password
|
||||
}
|
||||
} else {
|
||||
throw "Please use Connect-SnipeitPS to setup connection before any other commands."
|
||||
}
|
||||
|
||||
# Validation of parameters
|
||||
if (($Method -in ("POST", "PUT", "PATCH")) -and (!($Body))) {
|
||||
$message = "The following parameters are required when using the ${Method} parameter: Body."
|
||||
|
|
@ -34,42 +64,117 @@
|
|||
Throw $exception
|
||||
}
|
||||
|
||||
#Build request uri
|
||||
$apiUri = "$Url$Api"
|
||||
#To support images "image" property have be handled before this
|
||||
|
||||
$_headers = @{
|
||||
"Authorization" = "Bearer $($token)"
|
||||
"Authorization" = "Bearer $($Token)"
|
||||
'Content-Type' = 'application/json; charset=utf-8'
|
||||
"Accept" = "application/json"
|
||||
}
|
||||
}
|
||||
|
||||
Process {
|
||||
if ($GetParameters -and ($URi -notlike "*\?*"))
|
||||
{
|
||||
# This can be done using $Body, maybe some day - PetriAsi
|
||||
if ($GetParameters -and ($apiUri -notlike "*\?*")){
|
||||
Write-Debug "Using `$GetParameters: $($GetParameters | Out-String)"
|
||||
[string]$URI += (ConvertTo-GetParameter $GetParameters)
|
||||
[string]$apiUri = $apiUri + (ConvertTo-GetParameter $GetParameters)
|
||||
# Prevent recursive appends
|
||||
$GetParameters = $null
|
||||
}
|
||||
|
||||
# set mandatory parameters
|
||||
$splatParameters = @{
|
||||
Uri = $URi
|
||||
Uri = $apiUri
|
||||
Method = $Method
|
||||
Headers = $_headers
|
||||
UseBasicParsing = $true
|
||||
ErrorAction = 'SilentlyContinue'
|
||||
}
|
||||
|
||||
if ($Body) {$splatParameters["Body"] = [System.Text.Encoding]::UTF8.GetBytes($Body)}
|
||||
# Send image requests as multipart/form-data if supported
|
||||
if($null -ne $body -and $Body.Keys -contains 'image' ){
|
||||
if($PSVersionTable.PSVersion -ge '7.0'){
|
||||
$Body['image'] = get-item $body['image']
|
||||
# As multipart/form-data is always POST we need add
|
||||
# requested method for laravel named as '_method'
|
||||
$Body['_method'] = $Method
|
||||
$splatParameters["Method"] = 'POST'
|
||||
$splatParameters["Form"] = $Body
|
||||
} else {
|
||||
# use base64 encoded images for powershell version < 7
|
||||
Add-Type -AssemblyName "System.Web"
|
||||
$mimetype = [System.Web.MimeMapping]::GetMimeMapping($body['image'])
|
||||
$Body['image'] = 'data:@'+$mimetype+';base64,'+[Convert]::ToBase64String([IO.File]::ReadAllBytes($Body['image']))
|
||||
}
|
||||
}
|
||||
|
||||
if ($Body -and $splatParameters.Keys -notcontains 'Form') {
|
||||
$splatParameters["Body"] = [System.Text.Encoding]::UTF8.GetBytes(($Body | Convertto-Json))
|
||||
}
|
||||
|
||||
$script:PSDefaultParameterValues = $global:PSDefaultParameterValues
|
||||
|
||||
Write-Debug $Body
|
||||
Write-Debug "$($Body | ConvertTo-Json)"
|
||||
|
||||
#Check throttle limit
|
||||
if ($SnipeitPSSession.throttleLimit -gt 0) {
|
||||
Write-Verbose "Check for request throttling"
|
||||
Write-debug "ThrottleMode: $($SnipeitPSSession.throttleMode)"
|
||||
Write-debug "ThrottleLimit: $($SnipeitPSSession.throttleLimit)"
|
||||
Write-debug "ThrottlePeriod: $($SnipeitPSSession.throttlePeriod)"
|
||||
Write-debug "ThrottleThreshold: $($SnipeitPSSession.throttleThreshold)"
|
||||
Write-debug "Current count: $($SnipeitPSSession.throttledRequests.count)"
|
||||
|
||||
#current request timestamps in period
|
||||
$SnipeitPSSession.throttledRequests = ($SnipeitPSSession.throttledRequests).where({$_ -gt (get-date).AddMilliseconds( 0 - $SnipeitPSSession.throttlePeriod).ToFileTime()})
|
||||
|
||||
#make sure that we alway have list here
|
||||
if($null -eq $SnipeitPSSession.throttledRequests) {
|
||||
$SnipeitPSSession.throttledRequests = [System.Collections.ArrayList]::new()
|
||||
}
|
||||
|
||||
$naptime = 0
|
||||
switch ($SnipeitPSSession.throttleMode) {
|
||||
"Burst" {
|
||||
if ($SnipeitPSSession.throttledRequests.count -ge $SnipeitPSSession.throttleLimit) {
|
||||
$naptime = [Math]::Round(((get-date).ToFileTime() - ($SnipeitPSSession.throttledRequests[0]))/10000)
|
||||
}
|
||||
}
|
||||
|
||||
"Constant" {
|
||||
$prevrequesttime =[Math]::Round(((get-date).ToFileTime() - ($SnipeitPSSession.throttledRequests[$SnipeitPSSession.throttledRequests.count - 1]))/10000)
|
||||
$naptime = [Math]::Round($SnipeitPSSession.throttlePeriod / $SnipeitPSSession.throttleLimit) - $prevrequesttime
|
||||
}
|
||||
|
||||
"Adaptive" {
|
||||
$unThrottledRequests = $SnipeitPSSession.throttleLimit * ($SnipeitPSSession.throttleThreshold / 100)
|
||||
if($SnipeitPSSession.throttledRequests.count -ge $unThrottledRequests) {
|
||||
#calculate time left in throttlePeriod and devide it for remaining requests
|
||||
$remaining = $SnipeitPSSession.throttleLimit - $SnipeitPSSession.throttledRequests.count
|
||||
if ($remaining -lt 1) {
|
||||
$remaining = 1
|
||||
}
|
||||
$naptime = [Math]::Round((((get-date).ToFileTime() - ($SnipeitPSSession.throttledRequests[0]))/ 10000) / $remaining)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#Do we need a nap
|
||||
if ($naptime -gt 0) {
|
||||
Write-verbose "Throttling request for $naptime ms"
|
||||
Start-Sleep -Milliseconds $naptime
|
||||
}
|
||||
|
||||
$SnipeitPSSession.throttledRequests.Add((Get-Date).ToFileTime())
|
||||
}
|
||||
|
||||
# Invoke the API
|
||||
try {
|
||||
Write-Verbose "[$($MyInvocation.MyCommand.Name)] Invoking method $Method to URI $URi"
|
||||
Write-Debug "[$($MyInvocation.MyCommand.Name)] Invoke-WebRequest with: $($splatParameters | Out-String)"
|
||||
$webResponse = Invoke-WebRequest @splatParameters
|
||||
$webResponse = Invoke-RestMethod @splatParameters
|
||||
}
|
||||
catch {
|
||||
Write-Verbose "[$($MyInvocation.MyCommand.Name)] Failed to get an answer from the server"
|
||||
|
|
@ -81,33 +186,55 @@
|
|||
if ($webResponse) {
|
||||
Write-Verbose "[$($MyInvocation.MyCommand.Name)] Status code: $($webResponse.StatusCode)"
|
||||
|
||||
if ($webResponse.Content) {
|
||||
Write-Verbose $webResponse.Content
|
||||
if ($webResponse) {
|
||||
Write-Verbose $webResponse
|
||||
|
||||
# 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"
|
||||
# API returned a Content: lets work with it
|
||||
try{
|
||||
if ($webResponse.status -eq "error") {
|
||||
Write-Verbose "[$($MyInvocation.MyCommand.Name)] An error response was received ... resolving"
|
||||
# This could be handled nicely in an function such as:
|
||||
# ResolveError $response -WriteError
|
||||
Write-Error $($response.messages | Out-String)
|
||||
Write-Error $($webResponse.messages | Out-String)
|
||||
} elseif ( $webResponse.StatusCode -eq 'Unauthorized') {
|
||||
Write-Verbose "[$($MyInvocation.MyCommand.Name)] An Unauthorized response was received"
|
||||
Write-Error "Cannot connect to Snipe It: Unauthorized."
|
||||
return $false
|
||||
} else {
|
||||
#update operations return payload
|
||||
if ($webResponse.payload) {
|
||||
$result = $webResponse.payload
|
||||
}
|
||||
#Search operations return rows
|
||||
elseif ($webResponse.rows) {
|
||||
$result = $webResponse.rows
|
||||
}
|
||||
#Remove operations returns status and message
|
||||
elseif ($webResponse.status -eq 'success') {
|
||||
$result = $webResponse.payload
|
||||
}
|
||||
#Search and query result with no results
|
||||
elseif ($webResponse.total -eq 0){
|
||||
$result = $null
|
||||
}
|
||||
#get operations with id returns just one object
|
||||
else {
|
||||
$result = $response
|
||||
if (($response) -and ($response | Get-Member -Name payload))
|
||||
{
|
||||
$result = $response.payload
|
||||
}
|
||||
elseif (($response) -and ($response | Get-Member -Name rows)) {
|
||||
$result = $response.rows
|
||||
$result = $webResponse
|
||||
}
|
||||
|
||||
Write-Verbose "Status: $($webResponse.status)"
|
||||
Write-Verbose "Messages: $($webResponse.messages)"
|
||||
|
||||
$result
|
||||
}
|
||||
}
|
||||
catch {
|
||||
Write-Warning "Cannot parse server response. To debug try to add -Verbose with command."
|
||||
}
|
||||
|
||||
}
|
||||
elseif ($webResponse.StatusCode -eq "Unauthorized") {
|
||||
Write-Error "[$($MyInvocation.MyCommand.Name)] You are not Authorized to access the resource, check your token is correct"
|
||||
Write-Error "[$($MyInvocation.MyCommand.Name)] You are not Authorized to access the resource, check your apiKey is correct"
|
||||
}
|
||||
else {
|
||||
# No content, although statusCode < 400
|
||||
|
|
@ -125,3 +252,4 @@
|
|||
Write-Verbose "[$($MyInvocation.MyCommand.Name)] Function ended"
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
16
SnipeitPS/Private/Reset-SnipeitPSLegacyApi.ps1
Normal file
16
SnipeitPS/Private/Reset-SnipeitPSLegacyApi.ps1
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
function Reset-SnipeitPSLegacyApi {
|
||||
[CmdletBinding(
|
||||
SupportsShouldProcess = $true,
|
||||
ConfirmImpact = "Low"
|
||||
)]
|
||||
param(
|
||||
)
|
||||
process {
|
||||
Write-Verbose 'Reset-SnipeitPSLegacyApi'
|
||||
if ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
|
||||
$SnipeitPSSession.legacyUrl = $null
|
||||
$SnipeitPSSession.legacyApiKey = $null
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
18
SnipeitPS/Private/Set-SnipeitAlias.ps1
Normal file
18
SnipeitPS/Private/Set-SnipeitAlias.ps1
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
function Set-SnipeitAlias()
|
||||
{
|
||||
[CmdletBinding(
|
||||
SupportsShouldProcess = $true,
|
||||
ConfirmImpact = "Low"
|
||||
)]
|
||||
param()
|
||||
Write-Verbose "Setting compatibility aliases.. "
|
||||
Write-Verbose "All aliases are deprediated."
|
||||
$SnipeitAliases = get-SnipeitAlias
|
||||
ForEach ($key in $SnipeitAliases.Keys ) {
|
||||
New-Alias -Name $key -Value $($SnipeitAliases[$key]) -Scope 1
|
||||
Write-Verbose ("{0,5} -> {1}" -f $key,$($SnipeitAliases[$key]))
|
||||
}
|
||||
Write-Verbose "Please start using native 'Snipeit' prfixed functions instead."
|
||||
Get-Command -Module SnipeitPS -CommandType Alias | Select-Object -Property DisplayName,ResolvedCommand
|
||||
|
||||
}
|
||||
18
SnipeitPS/Private/Set-SnipeitPSLegacyApiKey.ps1
Normal file
18
SnipeitPS/Private/Set-SnipeitPSLegacyApiKey.ps1
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
function Set-SnipeitPSLegacyApiKey {
|
||||
[CmdletBinding(
|
||||
SupportsShouldProcess = $true,
|
||||
ConfirmImpact = "Low"
|
||||
)]
|
||||
param(
|
||||
[string]$apiKey
|
||||
)
|
||||
process {
|
||||
if ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
|
||||
if($PSVersionTable.PSVersion -ge '7.0'){
|
||||
$SnipeitPSSession.legacyApiKey = ConvertTo-SecureString -AsPlainText -String $apiKey
|
||||
} else {
|
||||
$SnipeitPSSession.legacyApiKey = ConvertTo-SecureString -Force -AsPlainText -String $apiKey
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
14
SnipeitPS/Private/Set-SnipeitPSLegacyUrl.ps1
Normal file
14
SnipeitPS/Private/Set-SnipeitPSLegacyUrl.ps1
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
function Set-SnipeitPSLegacyUrl {
|
||||
[CmdletBinding(
|
||||
SupportsShouldProcess = $true,
|
||||
ConfirmImpact = "Low"
|
||||
)]
|
||||
param(
|
||||
$url
|
||||
)
|
||||
process {
|
||||
if ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
|
||||
$SnipeitPSSession.legacyUrl = $url.TrimEnd('/')
|
||||
}
|
||||
}
|
||||
}
|
||||
15
SnipeitPS/Private/Test-SnipeitAlias.ps1
Normal file
15
SnipeitPS/Private/Test-SnipeitAlias.ps1
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
function Test-SnipeitAlias()
|
||||
{
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[parameter(mandatory = $true)]
|
||||
[string]$invocationName,
|
||||
[parameter(mandatory = $true)]
|
||||
[string]$commandName
|
||||
)
|
||||
if($invocationName -ne $commandName) {
|
||||
Write-Warning "$invocationName is still working, but it has been superceded by $commandName, please use it instead."
|
||||
Write-Warning 'To update your scripts you can use Update-SnipeitAlias helper function: '
|
||||
Write-Warning '"Get-Content [your-script.ps1] | Update-SnipeitAlias | Out-File [new-script-name.ps1]"'
|
||||
}
|
||||
}
|
||||
18
SnipeitPS/Private/Test-SnipeitPSConnection.ps1
Normal file
18
SnipeitPS/Private/Test-SnipeitPSConnection.ps1
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
function Test-SnipeitPSConnection {
|
||||
#test api connection
|
||||
$Parameters = @{
|
||||
Api = '/api/v1/statuslabels'
|
||||
Method = 'Get'
|
||||
GetParameters = @{'limit'=1}
|
||||
}
|
||||
Write-Verbose "Testing connection to $($SnipeitPSSession.url)."
|
||||
|
||||
$contest = Invoke-SnipeitMethod @Parameters
|
||||
|
||||
if ( $contest) {
|
||||
Write-Verbose "Connection to $($SnipeitPSSession.url) tested succesfully."
|
||||
return $true
|
||||
} else {
|
||||
return $false
|
||||
}
|
||||
}
|
||||
149
SnipeitPS/Public/Connect-SnipeitPS.ps1
Normal file
149
SnipeitPS/Public/Connect-SnipeitPS.ps1
Normal file
|
|
@ -0,0 +1,149 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Sets authetication information
|
||||
|
||||
.DESCRIPTION
|
||||
Sets apikey and url to connect Snipe-It system.
|
||||
Based on Set-SnipeitInfo command, what is now just compatibility wrapper
|
||||
and calls Connect-SnipeitPS
|
||||
|
||||
.PARAMETER url
|
||||
URL of Snipeit system.
|
||||
|
||||
.PARAMETER apiKey
|
||||
User's API Key for Snipeit.
|
||||
|
||||
.PARAMETER secureApiKey
|
||||
Snipe it Api key as securestring
|
||||
|
||||
.PARAMETER siteCred
|
||||
PSCredential where username shoul be snipe it url and password should be
|
||||
snipe it apikey.
|
||||
|
||||
.PARAMETER throttleLimit
|
||||
Throttle request rate to nro of requests per throttlePeriod. Defaults to 0 that means no requests are not throttled.
|
||||
|
||||
.PARAMETER throttlePeriod
|
||||
Throttle period time span in milliseconds defaults to 60 milliseconds.
|
||||
|
||||
.PARAMETER throttleThreshold
|
||||
Threshold percentage of used request on period after request are throttled.
|
||||
|
||||
.PARAMETER throttleMode
|
||||
RequestThrottling type. "Burst" allows all requests to be used in ThrottlePeriod without delays and then waits
|
||||
until there's new requests avalable. With "Contant" mode there always delay between requests. Delay is calculated
|
||||
by dividing throttlePeriod with throttleLimit. "Adaptive" mode allows throttleThreshold percentage of request to be
|
||||
used with out delay, after threshold limit is reached next requests are delayded by dividing available requests
|
||||
over throttlePeriod.
|
||||
|
||||
.EXAMPLE
|
||||
Connect-SnipeitPS -Url $url -apiKey $myapikey
|
||||
Connect to Snipe it api.
|
||||
|
||||
.EXAMPLE
|
||||
Connect-SnipeitPS -Url $url -SecureApiKey $myapikey
|
||||
Connects to Snipe it api with apikey stored to securestring
|
||||
|
||||
.EXAMPLE
|
||||
Connect-SnipeitPS -siteCred (Get-Credential -message "Use site url as username and apikey as password")
|
||||
Connect to Snipe It with PSCredential object.
|
||||
To use saved creadentials yu can use export-clixml and import-clixml commandlets.
|
||||
|
||||
.EXAMPLE
|
||||
Build credential with apikey value from secret vault (Microsoft.PowerShell.SecretManagement)
|
||||
$siteurl = "https://mysnipeitsite.url"
|
||||
$apikey = Get-SecretInfo -Name SnipeItApiKey
|
||||
$siteCred = New-Object -Type PSCredential -Argumentlist $siteurl,$spikey
|
||||
Connect-SnipeitPS -siteCred $siteCred
|
||||
|
||||
|
||||
|
||||
#>
|
||||
function Connect-SnipeitPS {
|
||||
[CmdletBinding(
|
||||
DefaultParameterSetName = 'Connect with url and apikey'
|
||||
)]
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseShouldProcessForStateChangingFunctions', '')]
|
||||
|
||||
param (
|
||||
[Parameter(ParameterSetName='Connect with url and apikey',Mandatory=$true)]
|
||||
[Parameter(ParameterSetName='Connect with url and secure apikey',Mandatory=$true)]
|
||||
[Uri]$url,
|
||||
|
||||
[Parameter(ParameterSetName='Connect with url and apikey',Mandatory=$true)]
|
||||
[String]$apiKey,
|
||||
|
||||
[Parameter(ParameterSetName='Connect with url and secure apikey',Mandatory=$true)]
|
||||
[SecureString]$secureApiKey,
|
||||
|
||||
[Parameter(ParameterSetName='Connect with credential',Mandatory=$true)]
|
||||
[PSCredential]$siteCred,
|
||||
|
||||
[Parameter(ParameterSetName='Connect with url and apikey',Mandatory=$false)]
|
||||
[Parameter(ParameterSetName='Connect with url and secure apikey',Mandatory=$false)]
|
||||
[Parameter(ParameterSetName='Connect with credential',Mandatory=$false)]
|
||||
[int]$throttleLimit,
|
||||
|
||||
[Parameter(ParameterSetName='Connect with url and apikey',Mandatory=$false)]
|
||||
[Parameter(ParameterSetName='Connect with url and secure apikey',Mandatory=$false)]
|
||||
[Parameter(ParameterSetName='Connect with credential',Mandatory=$false)]
|
||||
[int]$throttlePeriod,
|
||||
|
||||
[Parameter(ParameterSetName='Connect with url and apikey',Mandatory=$false)]
|
||||
[Parameter(ParameterSetName='Connect with url and secure apikey',Mandatory=$false)]
|
||||
[Parameter(ParameterSetName='Connect with credential',Mandatory=$false)]
|
||||
[int]$throttleThreshold,
|
||||
|
||||
[Parameter(ParameterSetName='Connect with url and apikey',Mandatory=$false)]
|
||||
[Parameter(ParameterSetName='Connect with url and secure apikey',Mandatory=$false)]
|
||||
[Parameter(ParameterSetName='Connect with credential',Mandatory=$false)]
|
||||
[ValidateSet("Burst","Constant","Adaptive")]
|
||||
[string]$throttleMode
|
||||
)
|
||||
|
||||
|
||||
PROCESS {
|
||||
switch ($PsCmdlet.ParameterSetName) {
|
||||
'Connect with url and apikey' {
|
||||
$SnipeitPSSession.url = $url.AbsoluteUri.TrimEnd('/')
|
||||
if($PSVersionTable.PSVersion -ge '7.0'){
|
||||
$SnipeitPSSession.apiKey = ConvertTo-SecureString -AsPlainText -String $apiKey
|
||||
} else {
|
||||
$SnipeitPSSession.apiKey = ConvertTo-SecureString -String $apiKey -AsPlainText -Force
|
||||
}
|
||||
}
|
||||
|
||||
'Connect with url and secure apikey' {
|
||||
$SnipeitPSSession.url = $url.AbsoluteUri.TrimEnd('/')
|
||||
$SnipeitPSSession.apiKey = $secureApiKey
|
||||
}
|
||||
|
||||
'Connect with credential' {
|
||||
$SnipeitPSSession.url = ($siteCred.GetNetworkCredential().UserName).TrimEnd('/')
|
||||
$SnipeitPSSession.apiKey = $siteCred.GetNetworkCredential().SecurePassword
|
||||
}
|
||||
}
|
||||
if($null -eq $throttleLimit) { $throttleLimit = 0}
|
||||
$SnipeitPSSession.throttleLimit = $throttleLimit
|
||||
|
||||
if($throttleThreshold -lt 1) { $throttleThreshold = 90}
|
||||
$SnipeitPSSession.throttleThreshold = $throttleThreshold
|
||||
|
||||
if('' -eq $throttleMode) { $throttleMode = "Burst"}
|
||||
$SnipeitPSSession.throttleMode = $throttleMode
|
||||
|
||||
if ($SnipeitPSSession.throttleLimit -gt 0) {
|
||||
if($null -eq $throttlePeriod) { $throttlePeriod = 60000}
|
||||
$SnipeitPSSession.throttlePeriod = $throttlePeriod
|
||||
|
||||
$SnipeitPSSession.throttledRequests = [System.Collections.ArrayList]::new()
|
||||
}
|
||||
|
||||
Write-Debug "Site-url $($SnipeitPSSession.url)"
|
||||
Write-Debug "Site apikey: $($SnipeitPSSession.apiKey)"
|
||||
|
||||
if (-not (Test-SnipeitPSConnection)) {
|
||||
throw "Cannot verify connection to snipe it. For the start try to check url and provided apikey or credential parameters"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,126 +0,0 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Gets a list of Snipe-it Assets
|
||||
|
||||
.PARAMETER search
|
||||
A text string to search the assets data
|
||||
|
||||
.PARAMETER order_number
|
||||
Optionally restrict asset results to this order number
|
||||
|
||||
.PARAMETER model_id
|
||||
Optionally restrict asset results to this asset model ID
|
||||
|
||||
.PARAMETER category_id
|
||||
Optionally restrict asset results to this category ID
|
||||
|
||||
.PARAMETER manufacturer_id
|
||||
Optionally restrict asset results to this manufacturer ID
|
||||
|
||||
.PARAMETER company_id
|
||||
Optionally restrict asset results to this company ID
|
||||
|
||||
.PARAMETER location_id
|
||||
Optionally restrict asset results to this location ID
|
||||
|
||||
.PARAMETER status
|
||||
Optionally restrict asset results to one of these status types: RTD, Deployed, Undeployable, Deleted, Archived, Requestable
|
||||
|
||||
.PARAMETER status_id
|
||||
Optionally restrict asset results to this status label ID
|
||||
|
||||
.PARAMETER sort
|
||||
Specify the column name you wish to sort by
|
||||
|
||||
.PARAMETER order
|
||||
Specify the order (asc or desc) you wish to order by on your sort column
|
||||
|
||||
.PARAMETER limit
|
||||
Specify the number of results you wish to return. Defaults to 50.
|
||||
|
||||
.PARAMETER offset
|
||||
Offset to use
|
||||
|
||||
.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.example.com" -token "token..."
|
||||
|
||||
.EXAMPLE
|
||||
Get-Asset -url "https://assets.example.com" -token "token..." | Where-Object {$_.name -eq "MyMachine" }
|
||||
#>
|
||||
function Get-Asset() {
|
||||
Param(
|
||||
[string]$search,
|
||||
|
||||
[int]$order_number,
|
||||
|
||||
[int]$model_id,
|
||||
|
||||
[int]$category_id,
|
||||
|
||||
[int]$manufacturer_id,
|
||||
|
||||
[int]$company_id,
|
||||
|
||||
[int]$location_id,
|
||||
|
||||
[string]$status,
|
||||
|
||||
[int]$status_id,
|
||||
|
||||
[string]$sort = "created_at",
|
||||
|
||||
[ValidateSet("asc", "desc")]
|
||||
[string]$order = "desc",
|
||||
|
||||
[int]$limit = 50,
|
||||
|
||||
[int]$offset,
|
||||
|
||||
[parameter(mandatory = $true)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $true)]
|
||||
[string]$apiKey
|
||||
)
|
||||
|
||||
$SearchParameter = @{
|
||||
sort = $sort
|
||||
order = $order
|
||||
limit = $limit
|
||||
offset = $offset
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('search')) { $SearchParameter.Add("search", $search) }
|
||||
if ($PSBoundParameters.ContainsKey('order_number')) { $SearchParameter.Add("order_number", $order_number) }
|
||||
if ($PSBoundParameters.ContainsKey('model_id')) { $SearchParameter.Add("model_id", $model_id) }
|
||||
if ($PSBoundParameters.ContainsKey('category_id')) { $SearchParameter.Add("category_id", $category_id) }
|
||||
if ($PSBoundParameters.ContainsKey('manufacturer_id')) { $SearchParameter.Add("manufacturer_id", $manufacturer_id) }
|
||||
if ($PSBoundParameters.ContainsKey('company_id')) { $SearchParameter.Add("company_id", $company_id) }
|
||||
if ($PSBoundParameters.ContainsKey('location_id')) { $SearchParameter.Add("location_id", $location_id) }
|
||||
if ($PSBoundParameters.ContainsKey('status_id')) { $SearchParameter.Add("status_id", $order_number) }
|
||||
if ($PSBoundParameters.ContainsKey('status')) { $SearchParameter.Add("status", $order_number) }
|
||||
if ($PSBoundParameters.ContainsKey('order_number')) { $SearchParameter.Add("order_number", $order_number) }
|
||||
|
||||
$Parameters = @{
|
||||
Uri = "$url/api/v1/hardware"
|
||||
Method = 'Get'
|
||||
GetParameters = $SearchParameter
|
||||
Token = $apiKey
|
||||
}
|
||||
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
|
||||
$result
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -1,57 +0,0 @@
|
|||
<#
|
||||
.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(
|
||||
[string]$search,
|
||||
|
||||
[ValidateSet("asc", "desc")]
|
||||
[string]$order = "desc",
|
||||
|
||||
[int]$limit = 50,
|
||||
|
||||
[int]$offset,
|
||||
|
||||
[parameter(mandatory = $true)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $true)]
|
||||
[string]$apiKey
|
||||
)
|
||||
|
||||
$SearchParameter = @{
|
||||
sort = $sort
|
||||
order = $order
|
||||
limit = $limit
|
||||
offset = $offset
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('search')) { $SearchParameter.Add("search", $search) }
|
||||
|
||||
$Parameters = @{
|
||||
Uri = "$url/api/v1/categories"
|
||||
Method = 'Get'
|
||||
Token = $apiKey
|
||||
GetParameters = $SearchParameter
|
||||
}
|
||||
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
|
||||
$result
|
||||
}
|
||||
|
|
@ -1,57 +0,0 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
# Gets a list of Snipe-it Companies
|
||||
|
||||
.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-Company -url "https://assets.example.com" -token "token..."
|
||||
|
||||
.EXAMPLE
|
||||
Get-Company -url "https://assets.example.com" -token "token..." | Where-Object {$_.name -eq "Company1" }
|
||||
|
||||
#>
|
||||
|
||||
function Get-Company()
|
||||
{
|
||||
Param(
|
||||
[string]$search,
|
||||
|
||||
[ValidateSet("asc", "desc")]
|
||||
[string]$order = "desc",
|
||||
|
||||
[int]$limit = 50,
|
||||
|
||||
[int]$offset,
|
||||
|
||||
[parameter(mandatory=$true)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory=$true)]
|
||||
[string]$apiKey
|
||||
)
|
||||
|
||||
$SearchParameter = @{
|
||||
sort = $sort
|
||||
order = $order
|
||||
limit = $limit
|
||||
offset = $offset
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('search')) { $SearchParameter.Add("search", $search) }
|
||||
|
||||
$Parameters = @{
|
||||
Uri = "$url/api/v1/companies"
|
||||
Method = 'Get'
|
||||
Token = $apiKey
|
||||
GetParameters = $SearchParameter
|
||||
}
|
||||
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
|
||||
$result
|
||||
}
|
||||
|
|
@ -1,62 +0,0 @@
|
|||
<#
|
||||
.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(
|
||||
[string]$search,
|
||||
|
||||
[int]$category_id,
|
||||
|
||||
[int]$company_id,
|
||||
|
||||
[ValidateSet("asc", "desc")]
|
||||
[string]$order = "desc",
|
||||
|
||||
[int]$limit = 50,
|
||||
|
||||
[int]$offset,
|
||||
|
||||
[parameter(mandatory = $true)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $true)]
|
||||
[string]$apiKey
|
||||
)
|
||||
|
||||
$SearchParameter = @{
|
||||
sort = $sort
|
||||
order = $order
|
||||
limit = $limit
|
||||
offset = $offset
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('search')) { $SearchParameter.Add("search", $search) }
|
||||
if ($PSBoundParameters.ContainsKey('category_id')) { $SearchParameter.Add("category_id", $category_id) }
|
||||
if ($PSBoundParameters.ContainsKey('company_id')) { $SearchParameter.Add("company_id", $company_id) }
|
||||
|
||||
$Parameters = @{
|
||||
Uri = "$url/api/v1/components"
|
||||
Method = 'Get'
|
||||
Token = $apiKey
|
||||
GetParameters = $SearchParameter
|
||||
}
|
||||
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
|
||||
$result
|
||||
}
|
||||
|
|
@ -1,58 +0,0 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
# Gets a list of Snipe-it Departments
|
||||
|
||||
.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-Department -url "https://assets.example.com" -token "token..."
|
||||
|
||||
.EXAMPLE
|
||||
Get-Department -url "https://assets.example.com" -token "token..." | Where-Object {$_.name -eq "Department1" }
|
||||
|
||||
#>
|
||||
|
||||
function Get-Department()
|
||||
{
|
||||
Param(
|
||||
[string]$search,
|
||||
|
||||
[ValidateSet("asc", "desc")]
|
||||
[string]$order = "desc",
|
||||
|
||||
[int]$limit = 50,
|
||||
|
||||
[int]$offset,
|
||||
|
||||
[parameter(mandatory = $true)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $true)]
|
||||
[string]$apiKey
|
||||
)
|
||||
|
||||
$SearchParameter = @{
|
||||
sort = $sort
|
||||
order = $order
|
||||
limit = $limit
|
||||
offset = $offset
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('search')) { $SearchParameter.Add("search", $search) }
|
||||
|
||||
$Parameters = @{
|
||||
Uri = "$url/api/v1/departments"
|
||||
Method = 'Get'
|
||||
Token = $apiKey
|
||||
GetParameters = $SearchParameter
|
||||
}
|
||||
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
|
||||
$result
|
||||
}
|
||||
|
||||
|
|
@ -1,87 +0,0 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
# Gets a list of Snipe-it Licenses
|
||||
|
||||
.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-License -url "https://assets.example.com" -token "token..."
|
||||
|
||||
.EXAMPLE
|
||||
Get-License -url "https://assets.example.com" -token "token..." | Where-Object {$_.name -eq "License" }
|
||||
|
||||
#>
|
||||
|
||||
function Get-License() {
|
||||
Param(
|
||||
[string]$search,
|
||||
|
||||
[string]$name,
|
||||
|
||||
[int] $company_id,
|
||||
|
||||
[string]$product_key,
|
||||
|
||||
[int]$order_number,
|
||||
|
||||
[string]$purchase_order,
|
||||
|
||||
[string]$license_name,
|
||||
|
||||
[string]$license_email,
|
||||
|
||||
[int]$manufacturer_id,
|
||||
|
||||
[int]$supplier_id,
|
||||
|
||||
[int]$depreciation_id,
|
||||
|
||||
[ValidateSet("asc", "desc")]
|
||||
[string]$order = "desc",
|
||||
|
||||
[int]$limit = 50,
|
||||
|
||||
[int]$offset,
|
||||
|
||||
[parameter(mandatory = $true)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $true)]
|
||||
[string]$apiKey
|
||||
)
|
||||
|
||||
$SearchParameter = @{
|
||||
sort = $sort
|
||||
order = $order
|
||||
limit = $limit
|
||||
offset = $offset
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('search')) { $SearchParameter.Add("search", $search) }
|
||||
if ($PSBoundParameters.ContainsKey('name')) { $SearchParameter.Add("name", $name) }
|
||||
if ($PSBoundParameters.ContainsKey('company_id')) { $SearchParameter.Add("company_id", $company_id) }
|
||||
if ($PSBoundParameters.ContainsKey('product_key')) { $SearchParameter.Add("product_key", $product_key) }
|
||||
if ($PSBoundParameters.ContainsKey('order_number')) { $SearchParameter.Add("order_number", $order_number) }
|
||||
if ($PSBoundParameters.ContainsKey('purchase_order')) { $SearchParameter.Add("purchase_order", $purchase_order) }
|
||||
if ($PSBoundParameters.ContainsKey('license_name')) { $SearchParameter.Add("license_name", $license_name) }
|
||||
if ($PSBoundParameters.ContainsKey('license_email')) { $SearchParameter.Add("license_email", $license_email) }
|
||||
if ($PSBoundParameters.ContainsKey('manufacturer_id')) { $SearchParameter.Add("manufacturer_id", $manufacturer_id) }
|
||||
if ($PSBoundParameters.ContainsKey('supplier_id')) { $SearchParameter.Add("supplier_id", $supplier_id) }
|
||||
if ($PSBoundParameters.ContainsKey('depreciation_id')) { $SearchParameter.Add("depreciation_id", $depreciation_id) }
|
||||
|
||||
$Parameters = @{
|
||||
Uri = "$url/api/v1/licenses"
|
||||
Method = 'Get'
|
||||
Token = $apiKey
|
||||
GetParameters = $SearchParameter
|
||||
}
|
||||
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
|
||||
$result
|
||||
}
|
||||
|
||||
|
|
@ -1,58 +0,0 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
# Gets a list of Snipe-it Locations
|
||||
|
||||
.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-Location -url "https://assets.example.com" -token "token..."
|
||||
|
||||
.EXAMPLE
|
||||
Get-Location -url "https://assets.example.com" -token "token..." | Where-Object {$_.name -eq "Location1" }
|
||||
|
||||
#>
|
||||
|
||||
function Get-Location()
|
||||
{
|
||||
Param(
|
||||
[string]$search,
|
||||
|
||||
[ValidateSet("asc", "desc")]
|
||||
[string]$order = "desc",
|
||||
|
||||
[int]$limit = 50,
|
||||
|
||||
[int]$offset,
|
||||
|
||||
[parameter(mandatory = $true)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $true)]
|
||||
[string]$apiKey
|
||||
)
|
||||
|
||||
$SearchParameter = @{
|
||||
sort = $sort
|
||||
order = $order
|
||||
limit = $limit
|
||||
offset = $offset
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('search')) { $SearchParameter.Add("search", $search) }
|
||||
|
||||
$Parameters = @{
|
||||
Uri = "$url/api/v1/locations"
|
||||
Method = 'Get'
|
||||
Token = $apiKey
|
||||
GetParameters = $SearchParameter
|
||||
}
|
||||
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
|
||||
$result
|
||||
}
|
||||
|
||||
|
|
@ -1,57 +0,0 @@
|
|||
<#
|
||||
.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(
|
||||
[string]$search,
|
||||
|
||||
[ValidateSet("asc", "desc")]
|
||||
[string]$order = "desc",
|
||||
|
||||
[int]$limit = 50,
|
||||
|
||||
[int]$offset,
|
||||
|
||||
[parameter(mandatory = $true)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $true)]
|
||||
[string]$apiKey
|
||||
)
|
||||
|
||||
$SearchParameter = @{
|
||||
sort = $sort
|
||||
order = $order
|
||||
limit = $limit
|
||||
offset = $offset
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('search')) { $SearchParameter.Add("search", $search) }
|
||||
|
||||
$Parameters = @{
|
||||
Uri = "$url/api/v1/manufacturers"
|
||||
Method = 'Get'
|
||||
Token = $apiKey
|
||||
GetParameters = $SearchParameter
|
||||
}
|
||||
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
|
||||
$result
|
||||
}
|
||||
|
|
@ -1,57 +0,0 @@
|
|||
<#
|
||||
.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(
|
||||
[string]$search,
|
||||
|
||||
[ValidateSet("asc", "desc")]
|
||||
[string]$order = "desc",
|
||||
|
||||
[int]$limit = 50,
|
||||
|
||||
[int]$offset,
|
||||
|
||||
[parameter(mandatory = $true)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $true)]
|
||||
[string]$apiKey
|
||||
)
|
||||
|
||||
$SearchParameter = @{
|
||||
sort = $sort
|
||||
order = $order
|
||||
limit = $limit
|
||||
offset = $offset
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('search')) { $SearchParameter.Add("search", $search) }
|
||||
|
||||
$Parameters = @{
|
||||
Uri = "$url/api/v1/models"
|
||||
Method = 'Get'
|
||||
Token = $apiKey
|
||||
GetParameters = $SearchParameter
|
||||
}
|
||||
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
|
||||
$result
|
||||
}
|
||||
165
SnipeitPS/Public/Get-SnipeitAccessory.ps1
Normal file
165
SnipeitPS/Public/Get-SnipeitAccessory.ps1
Normal file
|
|
@ -0,0 +1,165 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Gets a list of Snipe-it Accessories
|
||||
|
||||
.DESCRIPTION
|
||||
Gets a list of Snipe-it Accessories
|
||||
|
||||
.PARAMETER search
|
||||
A text string to search the Accessory data
|
||||
|
||||
.PARAMETER user_id
|
||||
Return Accessories checked out to user id
|
||||
|
||||
.PARAMETER id
|
||||
A id of specific Accessory
|
||||
|
||||
.PARAMETER company_id
|
||||
Optionally restrict Accessory results to this company_id field
|
||||
|
||||
.PARAMETER category_id
|
||||
Optionally restrict Accessory results to this category_id field
|
||||
|
||||
.PARAMETER manufacturer_id
|
||||
Optionally restrict Accessory results to this manufacturer_id field
|
||||
|
||||
.PARAMETER supplier_id
|
||||
Optionally restrict Accessory results to this supplier_id field
|
||||
|
||||
.PARAMETER limit
|
||||
Specify the number of results you wish to return. Defaults to 50. Defines batch size for -all
|
||||
|
||||
.PARAMETER offset
|
||||
Result offset to use
|
||||
|
||||
.PARAMETER all
|
||||
A return all results, works with -offset and other parameters
|
||||
|
||||
.PARAMETER url
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. URL of Snipeit system.
|
||||
|
||||
.PARAMETER apiKey
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. Users API Key for Snipeit.
|
||||
|
||||
.EXAMPLE
|
||||
Get-SnipeitAccessory -search Keyboard
|
||||
|
||||
.EXAMPLE
|
||||
Get-SnipeitAccessory -id 1
|
||||
|
||||
.EXAMPLE
|
||||
Get-SnipeitAccessory -user_id 1
|
||||
Get accessories checked out to user ID 1
|
||||
|
||||
#>
|
||||
|
||||
function Get-SnipeitAccessory() {
|
||||
[CmdletBinding(DefaultParameterSetName = 'Search')]
|
||||
Param(
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[string]$search,
|
||||
|
||||
[parameter(ParameterSetName='Get by ID')]
|
||||
[int]$id,
|
||||
|
||||
[parameter(ParameterSetName='Accessories checked out to user id')]
|
||||
[int]$user_id,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[int]$company_id,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[int]$category_id,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[int]$manufacturer_id,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[int]$supplier_id,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[string]$sort = "created_at",
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[ValidateSet("asc", "desc")]
|
||||
[string]$order = "desc",
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[int]$limit = 50,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[int]$offset,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[parameter(ParameterSetName='Accessories checked out to user id')]
|
||||
[switch]$all = $false,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$apiKey
|
||||
)
|
||||
begin {
|
||||
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
|
||||
|
||||
switch($PsCmdlet.ParameterSetName) {
|
||||
'Search' {$api = "/api/v1/accessories"}
|
||||
'Get by ID' {$api= "/api/v1/accessories/$id"}
|
||||
'Accessories checked out to user id' {$api = "/api/v1/users/$user_id/accessories"}
|
||||
}
|
||||
|
||||
$SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
|
||||
|
||||
$Parameters = @{
|
||||
Api = $api
|
||||
Method = 'Get'
|
||||
GetParameters = $SearchParameter
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyApiKey -apiKey $apikey
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url) {
|
||||
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyUrl -url $url
|
||||
}
|
||||
}
|
||||
|
||||
process {
|
||||
if ($all) {
|
||||
$offstart = $(if ($offset) {$offset} Else {0})
|
||||
$callargs = $SearchParameter
|
||||
$callargs.Remove('all')
|
||||
|
||||
while ($true) {
|
||||
$callargs['offset'] = $offstart
|
||||
$callargs['limit'] = $limit
|
||||
$res=Get-SnipeitAccessory @callargs
|
||||
$res
|
||||
if ($res.count -lt $limit) {
|
||||
break
|
||||
}
|
||||
$offstart = $offstart + $limit
|
||||
}
|
||||
} else {
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
$result
|
||||
}
|
||||
}
|
||||
|
||||
end {
|
||||
# reset legacy sessions
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url -or $PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Reset-SnipeitPSLegacyApi
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
64
SnipeitPS/Public/Get-SnipeitAccessoryOwner.ps1
Normal file
64
SnipeitPS/Public/Get-SnipeitAccessoryOwner.ps1
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Get list of checked out accessories
|
||||
.DESCRIPTION
|
||||
Get list of checked out accessories
|
||||
|
||||
.PARAMETER id
|
||||
Unique ID For accessory to list
|
||||
|
||||
.PARAMETER url
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. URL of Snipeit system.
|
||||
|
||||
.PARAMETER apiKey
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. User's API Key for Snipeit.
|
||||
|
||||
.EXAMPLE
|
||||
Get-SnipeitAccessoryOwner -id 1
|
||||
#>
|
||||
function Get-SnipeitAccessoryOwner() {
|
||||
[CmdletBinding(
|
||||
SupportsShouldProcess = $true,
|
||||
ConfirmImpact = "Medium"
|
||||
)]
|
||||
|
||||
Param(
|
||||
[parameter(mandatory = $true)]
|
||||
[int]$id,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$apiKey
|
||||
)
|
||||
begin {
|
||||
$Parameters = @{
|
||||
Api = "/api/v1/accessories/$id/checkedout"
|
||||
Method = 'GET'
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyApiKey -apiKey $apikey
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url) {
|
||||
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyUrl -url $url
|
||||
}
|
||||
}
|
||||
process {
|
||||
if ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
}
|
||||
$result
|
||||
}
|
||||
|
||||
end {
|
||||
# reset legacy sessions
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url -or $PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Reset-SnipeitPSLegacyApi
|
||||
}
|
||||
}
|
||||
}
|
||||
145
SnipeitPS/Public/Get-SnipeitActivity.ps1
Normal file
145
SnipeitPS/Public/Get-SnipeitActivity.ps1
Normal file
|
|
@ -0,0 +1,145 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Gets and search Snipe-it Activity history
|
||||
|
||||
.DESCRIPTION
|
||||
Gets a list of Snipe-it activity history
|
||||
|
||||
.PARAMETER search
|
||||
A text string to search the Activity history
|
||||
|
||||
.PARAMETER target_type
|
||||
Type of target. One from following list 'Accessory','Asset','AssetMaintenance','AssetModel','Category','Company','Component','Consumable','CustomField','Depreciable','Depreciation','Group','Licence','LicenseSeat','Location','Manufacturer','Statuslabel','Supplier','User'
|
||||
|
||||
.PARAMETER target_id
|
||||
Needed if target_type is specified
|
||||
|
||||
.PARAMETER item_type
|
||||
Type of target. One from following list 'Accessory','Asset','AssetMaintenance','AssetModel','Category','Company','Component','Consumable','CustomField','Depreciable','Depreciation','Group','Licence','LicenseSeat','Location','Manufacturer','Statuslabel','Supplier','User'
|
||||
|
||||
.PARAMETER item_id
|
||||
Needed if target_type is specified
|
||||
|
||||
.PARAMETER action_type
|
||||
Type of action. One from following list "add seats", "checkin from", 'checkout' or 'update'
|
||||
|
||||
.PARAMETER offset
|
||||
Result offset to use
|
||||
|
||||
.PARAMETER all
|
||||
A return all results, works with -offset and other parameters
|
||||
|
||||
.PARAMETER url
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. URL of Snipeit system.
|
||||
|
||||
.PARAMETER apiKey
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. Users API Key for Snipeit.
|
||||
|
||||
.EXAMPLE
|
||||
Get-SnipeitAccessory -search Keyboard
|
||||
|
||||
.EXAMPLE
|
||||
Get-SnipeitAccessory -id 1
|
||||
|
||||
#>
|
||||
|
||||
function Get-SnipeitActivity() {
|
||||
Param(
|
||||
|
||||
[string]$search,
|
||||
|
||||
[Parameter(Mandatory=$false)]
|
||||
[ValidateSet('Accessory','Asset','AssetMaintenance','AssetModel','Category','Company','Component','Consumable','CustomField','Depreciable','Depreciation','Group','Licence','LicenseSeat','Location','Manufacturer','Statuslabel','Supplier','User')]
|
||||
[string]$target_type,
|
||||
|
||||
[Parameter(Mandatory=$false)]
|
||||
[int]$target_id,
|
||||
|
||||
[Parameter(Mandatory=$false)]
|
||||
[ValidateSet('Accessory','Asset','AssetMaintenance','AssetModel','Category','Company','Component','Consumable','CustomField','Depreciable','Depreciation','Group','Licence','LicenseSeat','Location','Manufacturer','Statuslabel','Supplier','User')]
|
||||
[string]$item_type,
|
||||
|
||||
[Parameter(Mandatory=$false)]
|
||||
[int]$item_id,
|
||||
|
||||
[ValidateSet("add seats", "checkin from", 'checkout','update')]
|
||||
[string]$action_type ,
|
||||
|
||||
[int]$limit = 50,
|
||||
|
||||
[int]$offset,
|
||||
|
||||
[switch]$all = $false,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$apiKey
|
||||
)
|
||||
begin {
|
||||
if (($target_type -and -not $target_id) -or
|
||||
($target_id -and -not $target_type)) {
|
||||
throw "Please specify both target_type and target_id"
|
||||
}
|
||||
|
||||
if (($item_type -and -not $item_id) -or
|
||||
($item_id -and -not $item_type)) {
|
||||
throw "Please specify both item_type and item_id"
|
||||
}
|
||||
|
||||
$SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
|
||||
|
||||
|
||||
$Parameters = @{
|
||||
Api = "/api/v1/reports/activity"
|
||||
Method = 'Get'
|
||||
GetParameters = $SearchParameter
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyApiKey -apiKey $apikey
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url) {
|
||||
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyUrl -url $url
|
||||
}
|
||||
}
|
||||
|
||||
process {
|
||||
if ($all) {
|
||||
$offstart = $(if ($offset) {$offset} Else {0})
|
||||
$callargs = $SearchParameter
|
||||
$callargs.Remove('all')
|
||||
|
||||
while ($true) {
|
||||
$callargs['offset'] = $offstart
|
||||
$callargs['limit'] = $limit
|
||||
$res=Get-SnipeitActivity @callargs
|
||||
$res
|
||||
if ($res.count -lt $limit) {
|
||||
break
|
||||
}
|
||||
$offstart = $offstart + $limit
|
||||
}
|
||||
} else {
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
$result
|
||||
}
|
||||
}
|
||||
|
||||
end {
|
||||
# reset legacy sessions
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url -or $PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Reset-SnipeitPSLegacyApi
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
312
SnipeitPS/Public/Get-SnipeitAsset.ps1
Normal file
312
SnipeitPS/Public/Get-SnipeitAsset.ps1
Normal file
|
|
@ -0,0 +1,312 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Gets a list of Snipe-it Assets or specific asset
|
||||
|
||||
.PARAMETER search
|
||||
A text string to search the assets data
|
||||
|
||||
.PARAMETER id
|
||||
ID number of excact snipeit asset
|
||||
|
||||
.PARAMETER asset_tag
|
||||
Exact asset tag to query
|
||||
|
||||
.PARAMETER asset_serial
|
||||
Exact asset serialnumber to query
|
||||
|
||||
.PARAMETER audit_due
|
||||
Retrieve a list of assets that are due for auditing soon.
|
||||
|
||||
.PARAMETER audit_overdue
|
||||
Retrieve a list of assets that are overdue for auditing.
|
||||
|
||||
.PARAMETER user_id
|
||||
Retrieve a list of assets checked out to user id.
|
||||
|
||||
.PARAMETER component_id
|
||||
Retrieve a list of assets assigned this component id.
|
||||
|
||||
.PARAMETER name
|
||||
Optionally restrict asset results to this asset name
|
||||
|
||||
.PARAMETER order_number
|
||||
Optionally restrict asset results to this order number
|
||||
|
||||
.PARAMETER model_id
|
||||
Optionally restrict asset results to this asset model ID
|
||||
|
||||
.PARAMETER category_id
|
||||
Optionally restrict asset results to this category ID
|
||||
|
||||
.PARAMETER manufacturer_id
|
||||
Optionally restrict asset results to this manufacturer ID
|
||||
|
||||
.PARAMETER company_id
|
||||
Optionally restrict asset results to this company ID
|
||||
|
||||
.PARAMETER location_id
|
||||
Optionally restrict asset results to this location ID
|
||||
|
||||
.PARAMETER depreciation_id
|
||||
Optionally restrict asset results to this depreciation ID
|
||||
|
||||
.PARAMETER requestable
|
||||
Optionally restrict asset results to those set as requestable
|
||||
|
||||
.PARAMETER status
|
||||
Optionally restrict asset results to one of these status types: RTD, Deployed, Undeployable, Deleted, Archived, Requestable
|
||||
|
||||
.PARAMETER status_id
|
||||
Optionally restrict asset results to this status label ID
|
||||
|
||||
.PARAMETER customfields
|
||||
Hastable of custom fields and extra fields for searching assets in Snipe-It.
|
||||
Use internal field names from Snipe-It. You can use Get-CustomField to get internal field names.
|
||||
|
||||
.PARAMETER sort
|
||||
Specify the column name you wish to sort by
|
||||
|
||||
.PARAMETER order
|
||||
Specify the order (asc or desc) you wish to order by on your sort column
|
||||
|
||||
.PARAMETER limit
|
||||
Specify the number of results you wish to return. Defaults to 50. Defines batch size for -all
|
||||
|
||||
.PARAMETER offset
|
||||
Offset to use
|
||||
|
||||
.PARAMETER all
|
||||
A return all results, works with -offset and other parameters
|
||||
|
||||
.PARAMETER url
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. URL of Snipeit system.
|
||||
|
||||
.PARAMETER apiKey
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. Users API Key for Snipeit.
|
||||
|
||||
.EXAMPLE
|
||||
Get-SnipeitAsset -all
|
||||
Returens all assets
|
||||
|
||||
.EXAMPLE
|
||||
Get-SnipeitAsset -search "myMachine"
|
||||
Search for specific asset
|
||||
|
||||
.EXAMPLE
|
||||
Get-SnipeitAsset -id 3
|
||||
Get asset with id number 3
|
||||
|
||||
.EXAMPLE
|
||||
Get-SnipeitAsset -asset_tag snipe0003
|
||||
Get asset with asset tag snipe00033
|
||||
|
||||
.EXAMPLE
|
||||
Get-SnipeitAsset -serial 1234
|
||||
Get asset with searial number 1234
|
||||
|
||||
.EXAMPLE
|
||||
Get-SnipeitAsser -audit_due
|
||||
Get Assets due auditing soon
|
||||
|
||||
.EXAMPLE
|
||||
Get-SnipeitAsser -audit_overdue
|
||||
Get Assets overdue for auditing
|
||||
|
||||
.EXAMPLE
|
||||
Get-AnipeitAsset -user_id 4
|
||||
Get Assets checked out to user id 4
|
||||
|
||||
.EXAMPLE
|
||||
Get-SnipeitAsset -component_id 5
|
||||
Get Assets with component id 5
|
||||
|
||||
|
||||
#>
|
||||
|
||||
function Get-SnipeitAsset() {
|
||||
[CmdletBinding(DefaultParameterSetName = 'Search')]
|
||||
Param(
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[string]$search,
|
||||
|
||||
[parameter(ParameterSetName='Get with id')]
|
||||
[int]$id,
|
||||
|
||||
[parameter(ParameterSetName='Get with asset tag')]
|
||||
[string]$asset_tag,
|
||||
|
||||
[parameter(ParameterSetName='Get with serial')]
|
||||
[Alias('asset_serial')]
|
||||
[string]$serial,
|
||||
|
||||
[parameter(ParameterSetName='Assets due auditing soon')]
|
||||
[switch]$audit_due,
|
||||
|
||||
[parameter(ParameterSetName='Assets overdue for auditing')]
|
||||
[switch]$audit_overdue,
|
||||
|
||||
[parameter(ParameterSetName='Assets checked out to user id')]
|
||||
[int]$user_id,
|
||||
|
||||
[parameter(ParameterSetName='Assets with component id')]
|
||||
[int]$component_id,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[string]$name,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[string]$order_number,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[int]$model_id,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[int]$category_id,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[int]$manufacturer_id,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[int]$company_id,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[int]$location_id,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[int]$depreciation_id,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[bool]$requestable = $false,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[string]$status,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[int]$status_id,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[hashtable]$customfields,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[parameter(ParameterSetName='Assets due auditing soon')]
|
||||
[parameter(ParameterSetName='Assets overdue for auditing')]
|
||||
[parameter(ParameterSetName='Assets checked out to user id')]
|
||||
[parameter(ParameterSetName='Assets with component id')]
|
||||
[ValidateSet('id','created_at','asset_tag','serial','order_number','model_id','category_id','manufacturer_id','company_id','location_id','status','status_id')]
|
||||
[string]$sort,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[parameter(ParameterSetName='Assets due auditing soon')]
|
||||
[parameter(ParameterSetName='Assets overdue for auditing')]
|
||||
[parameter(ParameterSetName='Assets checked out to user id')]
|
||||
[parameter(ParameterSetName='Assets with component id')]
|
||||
[ValidateSet("asc", "desc")]
|
||||
[string]$order,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[parameter(ParameterSetName='Assets due auditing soon')]
|
||||
[parameter(ParameterSetName='Assets overdue for auditing')]
|
||||
[parameter(ParameterSetName='Assets checked out to user id')]
|
||||
[parameter(ParameterSetName='Assets with component id')]
|
||||
[int]$limit = 50,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[parameter(ParameterSetName='Assets due auditing soon')]
|
||||
[parameter(ParameterSetName='Assets overdue for auditing')]
|
||||
[parameter(ParameterSetName='Assets checked out to user id')]
|
||||
[parameter(ParameterSetName='Assets with component id')]
|
||||
[int]$offset,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[parameter(ParameterSetName='Assets due auditing soon')]
|
||||
[parameter(ParameterSetName='Assets overdue for auditing')]
|
||||
[parameter(ParameterSetName='Assets checked out to user id')]
|
||||
[parameter(ParameterSetName='Assets with component id')]
|
||||
[switch]$all = $false,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$apiKey
|
||||
)
|
||||
|
||||
begin {
|
||||
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
|
||||
|
||||
$SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
|
||||
|
||||
# Add in custom fields.
|
||||
if ($customfields.Count -gt 0) {
|
||||
foreach ($pair in $customfields.GetEnumerator()) {
|
||||
if (-Not $SearchParameter.ContainsKey($pair.Name)) {
|
||||
$SearchParameter.Add($pair.Name, $pair.Value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch ($PsCmdlet.ParameterSetName) {
|
||||
'Search' { $api = "/api/v1/hardware" }
|
||||
'Get with id' {$api= "/api/v1/hardware/$id"}
|
||||
'Get with asset tag' {$api= "/api/v1/hardware/bytag/$asset_tag"}
|
||||
'Get with serial' { $api= "/api/v1/hardware/byserial/$serial"}
|
||||
'Assets due auditing soon' {$api = "/api/v1/hardware/audit/due"}
|
||||
'Assets overdue for auditing' {$api = "/api/v1/hardware/audit/overdue"}
|
||||
'Assets checked out to user id'{$api = "/api/v1/users/$user_id/assets"}
|
||||
'Assets with component id' {$api = "/api/v1/components/$component_id/assets"}
|
||||
}
|
||||
|
||||
$Parameters = @{
|
||||
Api = $api
|
||||
Method = 'Get'
|
||||
GetParameters = $SearchParameter
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyApiKey -apiKey $apikey
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url) {
|
||||
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyUrl -url $url
|
||||
}
|
||||
}
|
||||
|
||||
process {
|
||||
if ($all) {
|
||||
$offstart = $(if ($offset) {$offset} Else {0})
|
||||
$callargs = $SearchParameter
|
||||
Write-Verbose "Callargs: $($callargs | convertto-json)"
|
||||
$callargs.Remove('all')
|
||||
|
||||
while ($true) {
|
||||
$callargs['offset'] = $offstart
|
||||
$callargs['limit'] = $limit
|
||||
$res=Get-SnipeitAsset @callargs
|
||||
$res
|
||||
if ( $res.count -lt $limit) {
|
||||
break
|
||||
}
|
||||
$offstart = $offstart + $limit
|
||||
}
|
||||
} else {
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
$result
|
||||
}
|
||||
}
|
||||
|
||||
end {
|
||||
# reset legacy sessions
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url -or $PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Reset-SnipeitPSLegacyApi
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
119
SnipeitPS/Public/Get-SnipeitAssetMaintenance.ps1
Normal file
119
SnipeitPS/Public/Get-SnipeitAssetMaintenance.ps1
Normal file
|
|
@ -0,0 +1,119 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Lists Snipe-it Assets Maintenances
|
||||
|
||||
.PARAMETER asset_id
|
||||
Asset ID of the asset you'd like to return maintenances for
|
||||
|
||||
.PARAMETER search
|
||||
Search string
|
||||
|
||||
.PARAMETER sort
|
||||
Specify the column name you wish to sort by
|
||||
|
||||
.PARAMETER order
|
||||
Specify the order (asc or desc) you wish to order by on your sort column
|
||||
|
||||
.PARAMETER limit
|
||||
Specify the number of results you wish to return. Defaults to 50. Defines batch size for -all
|
||||
|
||||
.PARAMETER offset
|
||||
Offset to use
|
||||
|
||||
.PARAMETER all
|
||||
A return all results, works with -offset and other parameters
|
||||
|
||||
.PARAMETER url
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. URL of Snipeit system.
|
||||
|
||||
.PARAMETER apiKey
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. Users API Key for Snipeit.
|
||||
|
||||
.EXAMPLE
|
||||
Get-SnipeitAssetMaintenances
|
||||
.EXAMPLE
|
||||
Get-SnipeitAssetMaintenances -search "myMachine"
|
||||
|
||||
.EXAMPLE
|
||||
Get-SnipeitAssetMaintenances -search "myMachine"
|
||||
#>
|
||||
function Get-SnipeitAssetMaintenance() {
|
||||
Param(
|
||||
[string]$search,
|
||||
|
||||
[int]$asset_id,
|
||||
|
||||
[string]$sort = "created_at",
|
||||
|
||||
[ValidateSet("asc", "desc")]
|
||||
[string]$order = "desc",
|
||||
|
||||
[int]$limit = 50,
|
||||
|
||||
[switch]$all = $false,
|
||||
|
||||
[int]$offset,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$apiKey
|
||||
)
|
||||
begin {
|
||||
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
|
||||
|
||||
$SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
|
||||
|
||||
$Parameters = @{
|
||||
Api = "/api/v1/maintenances"
|
||||
Method = 'Get'
|
||||
GetParameters = $SearchParameter
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyApiKey -apiKey $apikey
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url) {
|
||||
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyUrl -url $url
|
||||
}
|
||||
}
|
||||
|
||||
process {
|
||||
if ($all) {
|
||||
$offstart = $(if ($offset) {$offset} Else {0})
|
||||
$callargs = $SearchParameter
|
||||
$callargs.Remove('all')
|
||||
|
||||
while ($true) {
|
||||
$callargs['offset'] = $offstart
|
||||
$callargs['limit'] = $limit
|
||||
$res=Get-SnipeitAssetMaintenance @callargs
|
||||
$res
|
||||
if ($res.count -lt $limit) {
|
||||
break
|
||||
}
|
||||
$offstart = $offstart + $limit
|
||||
}
|
||||
} else {
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
$result
|
||||
}
|
||||
}
|
||||
|
||||
end {
|
||||
# reset legacy sessions
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url -or $PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Reset-SnipeitPSLegacyApi
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
128
SnipeitPS/Public/Get-SnipeitCategory.ps1
Normal file
128
SnipeitPS/Public/Get-SnipeitCategory.ps1
Normal file
|
|
@ -0,0 +1,128 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Gets a list of Snipe-it Categories
|
||||
|
||||
.PARAMETER search
|
||||
A text string to search the Categories data
|
||||
|
||||
.PARAMETER id
|
||||
A id of specific Category
|
||||
|
||||
.PARAMETER name
|
||||
Optionally restrict Category results to this Category name.
|
||||
|
||||
.PARAMETER limit
|
||||
Specify the number of results you wish to return. Defaults to 50. Defines batch size for -all
|
||||
|
||||
.PARAMETER offset
|
||||
Offset to use
|
||||
|
||||
.PARAMETER all
|
||||
A return all results, works with -offset and other parameters
|
||||
|
||||
.PARAMETER url
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. Url of Snipeit system.
|
||||
|
||||
.PARAMETER apiKey
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. Users API Key for Snipeit.
|
||||
|
||||
.EXAMPLE
|
||||
Get-SnipeitCategory -id 1
|
||||
|
||||
.EXAMPLE
|
||||
Get-SnipeitCategory -search "Laptop"
|
||||
|
||||
#>
|
||||
|
||||
function Get-SnipeitCategory() {
|
||||
[CmdletBinding(DefaultParameterSetName = 'Search')]
|
||||
Param(
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[string]$search,
|
||||
|
||||
[parameter(ParameterSetName='Get with ID')]
|
||||
[int]$id,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[string]$name,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[ValidateSet("asc", "desc")]
|
||||
[string]$order = "desc",
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[int]$limit = 50,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[int]$offset,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[switch]$all = $false,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$apiKey
|
||||
)
|
||||
|
||||
begin {
|
||||
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
|
||||
|
||||
$SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
|
||||
|
||||
$api = "/api/v1/categories"
|
||||
|
||||
if ($search -and $id ) {
|
||||
Throw "[$($MyInvocation.MyCommand.Name)] Please specify only -search or -id parameter , not both "
|
||||
}
|
||||
|
||||
if ($id) {
|
||||
$api= "/api/v1/categories/$id"
|
||||
}
|
||||
|
||||
$Parameters = @{
|
||||
Api = $api
|
||||
Method = 'Get'
|
||||
GetParameters = $SearchParameter
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyApiKey -apiKey $apikey
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url) {
|
||||
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyUrl -url $url
|
||||
}
|
||||
}
|
||||
process {
|
||||
if ($all) {
|
||||
$offstart = $(if ($offset) {$offset} Else {0})
|
||||
$callargs = $SearchParameter
|
||||
$callargs.Remove('all')
|
||||
|
||||
while ($true) {
|
||||
$callargs['offset'] = $offstart
|
||||
$callargs['limit'] = $limit
|
||||
$res=Get-SnipeitCategory @callargs
|
||||
$res
|
||||
if ($res.count -lt $limit) {
|
||||
break
|
||||
}
|
||||
$offstart = $offstart + $limit
|
||||
}
|
||||
} else {
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
$result
|
||||
}
|
||||
}
|
||||
|
||||
end {
|
||||
# reset legacy sessions
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url -or $PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Reset-SnipeitPSLegacyApi
|
||||
}
|
||||
}
|
||||
}
|
||||
129
SnipeitPS/Public/Get-SnipeitCompany.ps1
Normal file
129
SnipeitPS/Public/Get-SnipeitCompany.ps1
Normal file
|
|
@ -0,0 +1,129 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Gets a list of Snipe-it Companies
|
||||
|
||||
.PARAMETER search
|
||||
A text string to search the Companies data
|
||||
|
||||
.PARAMETER id
|
||||
A id of specific Company
|
||||
|
||||
.PARAMETER name
|
||||
Optionally restrict company results to this company name.
|
||||
|
||||
.PARAMETER limit
|
||||
Specify the number of results you wish to return. Defaults to 50. Defines batch size for -all
|
||||
|
||||
.PARAMETER offset
|
||||
Offset to use
|
||||
|
||||
.PARAMETER all
|
||||
A return all results, works with -offset and other parameters
|
||||
.PARAMETER url
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. URL of Snipeit system.
|
||||
|
||||
.PARAMETER apiKey
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. Users API Key for Snipeit.
|
||||
|
||||
.EXAMPLE
|
||||
Get-SnipeitCompany
|
||||
Gets all companies
|
||||
|
||||
.EXAMPLE
|
||||
Get-SnipeitCompany -id 1
|
||||
Gets specific company
|
||||
|
||||
#>
|
||||
|
||||
function Get-SnipeitCompany() {
|
||||
[CmdletBinding(DefaultParameterSetName = 'Search')]
|
||||
Param(
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[string]$search,
|
||||
|
||||
[parameter(ParameterSetName='Get with ID')]
|
||||
[int]$id,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[string]$name,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[ValidateSet("asc", "desc")]
|
||||
[string]$order = "desc",
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[int]$limit = 50,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[int]$offset,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[switch]$all = $false,
|
||||
|
||||
[parameter(mandatory=$false)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory=$false)]
|
||||
[string]$apiKey
|
||||
)
|
||||
|
||||
begin {
|
||||
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
|
||||
|
||||
$SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
|
||||
|
||||
$api = "/api/v1/companies"
|
||||
|
||||
if ($search -and $id ) {
|
||||
Throw "[$($MyInvocation.MyCommand.Name)] Please specify only -search or -id parameter , not both "
|
||||
}
|
||||
|
||||
if ($id) {
|
||||
$api= "/api/v1/companies/$id"
|
||||
}
|
||||
|
||||
$Parameters = @{
|
||||
Api = $api
|
||||
Method = 'Get'
|
||||
GetParameters = $SearchParameter
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyApiKey -apiKey $apikey
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url) {
|
||||
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyUrl -url $url
|
||||
}
|
||||
}
|
||||
process {
|
||||
if ($all) {
|
||||
$offstart = $(if ($offset) {$offset} Else {0})
|
||||
$callargs = $SearchParameter
|
||||
$callargs.Remove('all')
|
||||
|
||||
while ($true) {
|
||||
$callargs['offset'] = $offstart
|
||||
$callargs['limit'] = $limit
|
||||
$res=Get-SnipeitCompany @callargs
|
||||
$res
|
||||
if ($res.count -lt $limit) {
|
||||
break
|
||||
}
|
||||
$offstart = $offstart + $limit
|
||||
}
|
||||
} else {
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
$result
|
||||
}
|
||||
}
|
||||
|
||||
end {
|
||||
# reset legacy sessions
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url -or $PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Reset-SnipeitPSLegacyApi
|
||||
}
|
||||
}
|
||||
}
|
||||
156
SnipeitPS/Public/Get-SnipeitComponent.ps1
Normal file
156
SnipeitPS/Public/Get-SnipeitComponent.ps1
Normal file
|
|
@ -0,0 +1,156 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Gets a list of Snipe-it Components
|
||||
|
||||
.PARAMETER search
|
||||
A text string to search the Components data
|
||||
|
||||
.PARAMETER id
|
||||
A id of specific Component
|
||||
|
||||
.PARAMETER name
|
||||
Optionally restrict Component results to this name field
|
||||
|
||||
.PARAMETER company_id
|
||||
Optionally restrict Component results to this company_id field
|
||||
|
||||
.PARAMETER category_id
|
||||
Optionally restrict Component results to this category_id field
|
||||
|
||||
.PARAMETER location_id
|
||||
Optionally restrict Component results to this location_id field
|
||||
|
||||
.PARAMETER limit
|
||||
Specify the number of results you wish to return. Defaults to 50. Defines batch size for -all
|
||||
|
||||
.PARAMETER offset
|
||||
Offset to use
|
||||
|
||||
.PARAMETER all
|
||||
A return all results, works with -offset and other parameters
|
||||
|
||||
.PARAMETER url
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. URL of Snipeit system.
|
||||
|
||||
.PARAMETER apiKey
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. Users API Key for Snipeit.
|
||||
|
||||
.EXAMPLE
|
||||
Get-SnipeitComponent
|
||||
Returns all components
|
||||
|
||||
.EXAMPLE
|
||||
Get-SnipeitComponent -search display
|
||||
Returns search results containeing string display
|
||||
|
||||
.EXAMPLE
|
||||
Get-SnipeitComponent -id
|
||||
Returns specific component
|
||||
|
||||
#>
|
||||
function Get-SnipeitComponent() {
|
||||
[CmdletBinding(DefaultParameterSetName = 'Search')]
|
||||
Param(
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[string]$search,
|
||||
|
||||
[parameter(ParameterSetName='Get with ID')]
|
||||
[int]$id,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[string]$name,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[int]$category_id,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[int]$company_id,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[int]$location_id,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[ValidateSet("asc", "desc")]
|
||||
[string]$order = "desc",
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[ValidateSet('id', 'name', 'min_amt', 'order_number', 'serial', 'purchase_date', 'purchase_cost', 'company', 'category', 'qty', 'location', 'image', 'created_at')]
|
||||
[string]$sort = "created_at",
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[int]$limit = 50,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[int]$offset,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[switch]$all = $false,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$apiKey
|
||||
)
|
||||
|
||||
begin {
|
||||
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
|
||||
|
||||
$SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
|
||||
|
||||
$api = "/api/v1/components"
|
||||
|
||||
if ($search -and $id ) {
|
||||
Throw "[$($MyInvocation.MyCommand.Name)] Please specify only -search or -id parameter , not both "
|
||||
}
|
||||
|
||||
if ($id) {
|
||||
$api= "/api/v1/components/$id"
|
||||
}
|
||||
|
||||
$Parameters = @{
|
||||
Api = $api
|
||||
Method = 'Get'
|
||||
GetParameters = $SearchParameter
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyApiKey -apiKey $apikey
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url) {
|
||||
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyUrl -url $url
|
||||
}
|
||||
}
|
||||
|
||||
process {
|
||||
if ($all) {
|
||||
$offstart = $(if ($offset) {$offset} Else {0})
|
||||
$callargs = $SearchParameter
|
||||
$callargs.Remove('all')
|
||||
|
||||
while ($true) {
|
||||
$callargs['offset'] = $offstart
|
||||
$callargs['limit'] = $limit
|
||||
$res=Get-SnipeitComponent @callargs
|
||||
$res
|
||||
if ($res.count -lt $limit) {
|
||||
break
|
||||
}
|
||||
$offstart = $offstart + $limit
|
||||
}
|
||||
} else {
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
$result
|
||||
}
|
||||
}
|
||||
|
||||
end {
|
||||
# reset legacy sessions
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url -or $PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Reset-SnipeitPSLegacyApi
|
||||
}
|
||||
}
|
||||
}
|
||||
178
SnipeitPS/Public/Get-SnipeitConsumable.ps1
Normal file
178
SnipeitPS/Public/Get-SnipeitConsumable.ps1
Normal file
|
|
@ -0,0 +1,178 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Gets a list of Snipe-it consumables
|
||||
|
||||
.PARAMETER search
|
||||
A text string to search the consumables
|
||||
|
||||
.PARAMETER id
|
||||
A id of specific consumable
|
||||
|
||||
.PARAMETER name
|
||||
Optionally restrict consumable results to this name field
|
||||
|
||||
.PARAMETER company_id
|
||||
Id number of company
|
||||
|
||||
.PARAMETER category_id
|
||||
Id number of category
|
||||
|
||||
.PARAMETER manufacturer_id
|
||||
Id number of manufacturer
|
||||
|
||||
.PARAMETER sort
|
||||
Sort results by column
|
||||
|
||||
.PARAMETER order
|
||||
Specify the order (asc or desc) you wish to order by on your sort column
|
||||
|
||||
.PARAMETER expand
|
||||
Whether to include detailed information on categories, etc (true) or just the text name (false)
|
||||
|
||||
.PARAMETER limit
|
||||
Specify the number of results you wish to return. Defaults to 50. Defines batch size for -all
|
||||
|
||||
.PARAMETER offset
|
||||
Offset to use
|
||||
|
||||
.PARAMETER all
|
||||
A return all results
|
||||
|
||||
.PARAMETER url
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. URL of Snipeit system.
|
||||
|
||||
.PARAMETER apiKey
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. Users API Key for Snipeit.
|
||||
|
||||
.EXAMPLE
|
||||
Get-SnipeitConsumable -all
|
||||
Returns all consumables
|
||||
|
||||
.EXAMPLE
|
||||
Get-SnipeitConsumable -search paper
|
||||
Returns search results containeing string display
|
||||
|
||||
.EXAMPLE
|
||||
Get-Snipeitconsumable -id
|
||||
Returns specific consumable
|
||||
|
||||
#>
|
||||
function Get-SnipeitConsumable() {
|
||||
[CmdletBinding(DefaultParameterSetName = 'Search')]
|
||||
Param(
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[string]$search,
|
||||
|
||||
[parameter(ParameterSetName='Get with ID')]
|
||||
[int[]]$id,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[string]$name,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[int]$category_id,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[int]$company_id,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[int]$manufacturer_id,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[int]$location_id,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[ValidateSet("asc", "desc")]
|
||||
[string]$order = "desc",
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[ValidateSet('id', 'name', 'min_amt', 'order_number', 'serial', 'purchase_date', 'purchase_cost', 'company', 'category', 'qty', 'location', 'image', 'created_at')]
|
||||
[string]$sort = "created_at",
|
||||
|
||||
|
||||
[Parameter(ParameterSetName='Search')]
|
||||
[switch]$expand,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[int]$limit = 50,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[int]$offset,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[switch]$all = $false,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$apiKey
|
||||
)
|
||||
begin {
|
||||
|
||||
$SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyApiKey -apiKey $apikey
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url) {
|
||||
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyUrl -url $url
|
||||
}
|
||||
}
|
||||
|
||||
process {
|
||||
switch ($PSCmdlet.ParameterSetName) {
|
||||
'Search' {
|
||||
$Parameters = @{
|
||||
Api = "/api/v1/consumables"
|
||||
Method = 'Get'
|
||||
GetParameters = $SearchParameter
|
||||
}
|
||||
|
||||
if ($all) {
|
||||
$offstart = $(if ($offset) {$offset} Else {0})
|
||||
$callargs = $SearchParameter
|
||||
$callargs.Remove('all')
|
||||
|
||||
while ($true) {
|
||||
$callargs['offset'] = $offstart
|
||||
$callargs['limit'] = $limit
|
||||
$res=Get-Snipeitconsumable @callargs
|
||||
$res
|
||||
if ($res.count -ne $limit) {
|
||||
break
|
||||
}
|
||||
$offstart = $offstart + $limit
|
||||
}
|
||||
} else {
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
$result
|
||||
}
|
||||
}
|
||||
|
||||
'Get with ID' {
|
||||
foreach($consumable_id in $id) {
|
||||
$Parameters = @{
|
||||
Api = "$url/api/v1/consumables/$consumable_id"
|
||||
Method = 'Get'
|
||||
GetParameters = $SearchParameter
|
||||
}
|
||||
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
$result
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
end {
|
||||
# reset legacy sessions
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url -or $PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Reset-SnipeitPSLegacyApi
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
72
SnipeitPS/Public/Get-SnipeitCustomField.ps1
Normal file
72
SnipeitPS/Public/Get-SnipeitCustomField.ps1
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Returns specific Snipe-IT custom field or a list of all custom field
|
||||
|
||||
.PARAMETER id
|
||||
A id of specific field
|
||||
|
||||
.PARAMETER url
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. URL of Snipeit system.
|
||||
|
||||
.PARAMETER apiKey
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. Users API Key for Snipeit.
|
||||
|
||||
.EXAMPLE
|
||||
Get-SnipeitCustomField
|
||||
Get all custom fields
|
||||
|
||||
.EXAMPLE
|
||||
Get-SnipeitCustomField -id 1
|
||||
Get custom field with ID 1
|
||||
|
||||
|
||||
#>
|
||||
|
||||
function Get-SnipeitCustomField() {
|
||||
Param(
|
||||
[int]$id,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$apiKey
|
||||
)
|
||||
|
||||
begin {
|
||||
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
|
||||
|
||||
if ($id) {
|
||||
$api= "/api/v1/fields/$id"
|
||||
} else {
|
||||
$api = "/api/v1/fields"
|
||||
}
|
||||
|
||||
$Parameters = @{
|
||||
Api = $api
|
||||
Method = 'Get'
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyApiKey -apiKey $apikey
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url) {
|
||||
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyUrl -url $url
|
||||
}
|
||||
}
|
||||
|
||||
process {
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
$result
|
||||
}
|
||||
|
||||
end {
|
||||
# reset legacy sessions
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url -or $PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Reset-SnipeitPSLegacyApi
|
||||
}
|
||||
}
|
||||
}
|
||||
154
SnipeitPS/Public/Get-SnipeitDepartment.ps1
Normal file
154
SnipeitPS/Public/Get-SnipeitDepartment.ps1
Normal file
|
|
@ -0,0 +1,154 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Gets a list of Snipe-it Departments
|
||||
|
||||
.PARAMETER search
|
||||
A text string to search the Departments data
|
||||
|
||||
.PARAMETER id
|
||||
A id of specific Department
|
||||
|
||||
.PARAMETER name
|
||||
Optionally restrict department results to this department name.
|
||||
|
||||
.PARAMETER manager_id
|
||||
Optionally restrict department results to this manager ID.
|
||||
|
||||
.PARAMETER company_id
|
||||
Optionally restrict department results to this company ID.
|
||||
|
||||
.PARAMETER location_id
|
||||
Optionally restrict department results to this location ID.
|
||||
|
||||
.PARAMETER limit
|
||||
Specify the number of results you wish to return. Defaults to 50. Defines batch size for -all
|
||||
|
||||
.PARAMETER offset
|
||||
Offset to use
|
||||
|
||||
.PARAMETER all
|
||||
A return all results, works with -offset and other parameters
|
||||
|
||||
.PARAMETER url
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. URL of Snipeit system.
|
||||
|
||||
.PARAMETER apiKey
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. Users API Key for Snipeit.
|
||||
|
||||
.EXAMPLE
|
||||
Get-SnipeitDepartment
|
||||
|
||||
.EXAMPLE
|
||||
Get-SnipeitDepartment -search Department1
|
||||
|
||||
.EXAMPLE
|
||||
Get-SnipeitDepartment -id 1
|
||||
|
||||
#>
|
||||
|
||||
function Get-SnipeitDepartment() {
|
||||
[CmdletBinding(DefaultParameterSetName = 'Search')]
|
||||
Param(
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[string]$search,
|
||||
|
||||
[parameter(ParameterSetName='Get with ID')]
|
||||
[int]$id,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[string]$name,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[int]$manager_id,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[int]$company_id,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[int]$location_id,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[ValidateSet("asc", "desc")]
|
||||
[string]$order = "desc",
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[int]$limit = 50,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[int]$offset,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[switch]$all = $false,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[ValidateSet('id', 'name', 'image', 'users_count', 'created_at')]
|
||||
[string]$sort = "created_at",
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$apiKey
|
||||
)
|
||||
begin {
|
||||
|
||||
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
|
||||
|
||||
$SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
|
||||
|
||||
$api = "/api/v1/departments"
|
||||
|
||||
if ($search -and $id ) {
|
||||
Throw "[$($MyInvocation.MyCommand.Name)] Please specify only -search or -id parameter , not both "
|
||||
}
|
||||
|
||||
if ($id) {
|
||||
$api= "/api/v1/departments/$id"
|
||||
}
|
||||
|
||||
$Parameters = @{
|
||||
Api = $api
|
||||
Method = 'Get'
|
||||
GetParameters = $SearchParameter
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyApiKey -apiKey $apikey
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url) {
|
||||
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyUrl -url $url
|
||||
}
|
||||
}
|
||||
process {
|
||||
if ($all) {
|
||||
$offstart = $(if ($offset) {$offset} Else {0})
|
||||
$callargs = $SearchParameter
|
||||
$callargs.Remove('all')
|
||||
|
||||
while ($true) {
|
||||
$callargs['offset'] = $offstart
|
||||
$callargs['limit'] = $limit
|
||||
$res=Get-SnipeitDepartment @callargs
|
||||
$res
|
||||
if ($res.count -lt $limit) {
|
||||
break
|
||||
}
|
||||
$offstart = $offstart + $limit
|
||||
}
|
||||
} else {
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
$result
|
||||
}
|
||||
}
|
||||
|
||||
end {
|
||||
# reset legacy sessions
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url -or $PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Reset-SnipeitPSLegacyApi
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
69
SnipeitPS/Public/Get-SnipeitFieldset.ps1
Normal file
69
SnipeitPS/Public/Get-SnipeitFieldset.ps1
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Returns a fieldset or list of Snipe-it Fieldsets
|
||||
|
||||
.PARAMETER id
|
||||
A id of specific fieldset
|
||||
|
||||
.PARAMETER url
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. URL of Snipeit system.
|
||||
|
||||
.PARAMETER apiKey
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. Users API Key for Snipeit.
|
||||
|
||||
.EXAMPLE
|
||||
Get-SnipeitFieldset
|
||||
Get all fieldsets
|
||||
|
||||
.EXAMPLE
|
||||
Get-SnipeitFieldset | Where-Object {$_.name -eq "Windows" }
|
||||
Gets fieldset by name
|
||||
|
||||
#>
|
||||
|
||||
function Get-SnipeitFieldset() {
|
||||
Param(
|
||||
[int]$id,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$apiKey
|
||||
)
|
||||
begin {
|
||||
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
|
||||
|
||||
if ($id) {
|
||||
$api = "/api/v1/fieldsets/$id"
|
||||
} else {
|
||||
$api = "/api/v1/fieldsets"
|
||||
}
|
||||
|
||||
$Parameters = @{
|
||||
Api = $api
|
||||
Method = 'Get'
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyApiKey -apiKey $apikey
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url) {
|
||||
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyUrl -url $url
|
||||
}
|
||||
}
|
||||
process {
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
|
||||
$result
|
||||
}
|
||||
end {
|
||||
# reset legacy sessions
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url -or $PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Reset-SnipeitPSLegacyApi
|
||||
}
|
||||
}
|
||||
}
|
||||
165
SnipeitPS/Public/Get-SnipeitLicense.ps1
Normal file
165
SnipeitPS/Public/Get-SnipeitLicense.ps1
Normal file
|
|
@ -0,0 +1,165 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Gets a list of Snipe-it Licenses
|
||||
|
||||
.PARAMETER search
|
||||
A text string to search the Licenses data
|
||||
|
||||
.PARAMETER id
|
||||
A id of specific License
|
||||
|
||||
.PARAMETER limit
|
||||
Specify the number of results you wish to return. Defaults to 50. Defines batch size for -all
|
||||
|
||||
.PARAMETER offset
|
||||
Offset to use
|
||||
|
||||
.PARAMETER all
|
||||
A return all results, works with -offset and other parameters
|
||||
|
||||
|
||||
.PARAMETER url
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. URL of Snipeit system.
|
||||
|
||||
.PARAMETER apiKey
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. Users API Key for Snipeit.
|
||||
|
||||
.EXAMPLE
|
||||
Get-SnipeitLicense -search SomeLicense
|
||||
|
||||
.EXAMPLE
|
||||
Get-SnipeitLicense -id 1
|
||||
|
||||
#>
|
||||
|
||||
function Get-SnipeitLicense() {
|
||||
[CmdletBinding(DefaultParameterSetName = 'Search')]
|
||||
Param(
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[string]$search,
|
||||
|
||||
[parameter(ParameterSetName='Get with ID')]
|
||||
[int]$id,
|
||||
|
||||
[parameter(ParameterSetName='Get licenses checked out to user ID')]
|
||||
[int]$user_id,
|
||||
|
||||
[parameter(ParameterSetName='Get licenses checked out to asset ID')]
|
||||
[int]$asset_id,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[string]$name,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[int] $company_id,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[string]$product_key,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[string]$order_number,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[string]$purchase_order,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[string]$license_name,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[mailaddress]$license_email,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[int]$manufacturer_id,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[int]$supplier_id,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[int]$depreciation_id,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[int]$category_id,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[ValidateSet("asc", "desc")]
|
||||
[string]$order = "desc",
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[ValidateSet('created_at','id', 'name', 'purchase_cost', 'expiration_date', 'purchase_order', 'order_number', 'notes', 'purchase_date', 'serial', 'company', 'category', 'license_name', 'license_email', 'free_seats_count', 'seats', 'manufacturer', 'supplier')]
|
||||
[string]$sort = "created_at",
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[int]$limit = 50,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[int]$offset,
|
||||
[parameter(ParameterSetName='Get licenses checked out to user ID')]
|
||||
[parameter(ParameterSetName='Get licenses checked out to asset ID')]
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[switch]$all = $false,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$apiKey
|
||||
)
|
||||
begin {
|
||||
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
|
||||
|
||||
$SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
|
||||
|
||||
switch($PsCmdlet.ParameterSetName) {
|
||||
'Search' {$api = "/api/v1/licenses"}
|
||||
'Get with ID' {$api= "/api/v1/licenses/$id"}
|
||||
'Get licenses checked out to user ID' {$api= "/api/v1/users/$user_id/licenses"}
|
||||
'Get licenses checked out to asset ID' {$api= "/api/v1/hardware/$asset_id/licenses"}
|
||||
}
|
||||
|
||||
$Parameters = @{
|
||||
Api = $api
|
||||
Method = 'Get'
|
||||
GetParameters = $SearchParameter
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyApiKey -apiKey $apikey
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url) {
|
||||
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyUrl -url $url
|
||||
}
|
||||
}
|
||||
|
||||
process {
|
||||
if ($all) {
|
||||
$offstart = $(if ($offset) {$offset} Else {0})
|
||||
$callargs = $SearchParameter
|
||||
$callargs.Remove('all')
|
||||
|
||||
while ($true) {
|
||||
$callargs['offset'] = $offstart
|
||||
$callargs['limit'] = $limit
|
||||
$res=Get-SnipeitLicense @callargs
|
||||
$res
|
||||
if ($res.count -lt $limit) {
|
||||
break
|
||||
}
|
||||
$offstart = $offstart + $limit
|
||||
}
|
||||
} else {
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
$result
|
||||
}
|
||||
}
|
||||
|
||||
end {
|
||||
# reset legacy sessions
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url -or $PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Reset-SnipeitPSLegacyApi
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
114
SnipeitPS/Public/Get-SnipeitLicenseSeat.ps1
Normal file
114
SnipeitPS/Public/Get-SnipeitLicenseSeat.ps1
Normal file
|
|
@ -0,0 +1,114 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Gets a list of Snipe-it Licenses Seats or specific Seat
|
||||
|
||||
.PARAMETER search
|
||||
A text string to search the Licenses data
|
||||
|
||||
.PARAMETER id
|
||||
A id of specific License
|
||||
|
||||
.PARAMETER seat_id
|
||||
A id of specific seat
|
||||
|
||||
.PARAMETER limit
|
||||
Specify the number of results you wish to return. Defaults to 50. Defines batch size for -all
|
||||
|
||||
.PARAMETER offset
|
||||
Offset to use
|
||||
|
||||
.PARAMETER all
|
||||
A return all results, works with -offset and other parameters
|
||||
|
||||
|
||||
.PARAMETER url
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. URL of Snipeit system.
|
||||
|
||||
.PARAMETER apiKey
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. Users API Key for Snipeit.
|
||||
|
||||
.EXAMPLE
|
||||
Get-SnipeitLicenseSeat -id 1
|
||||
|
||||
|
||||
#>
|
||||
|
||||
function Get-SnipeitLicenseSeat() {
|
||||
Param(
|
||||
|
||||
[parameter(mandatory = $true)]
|
||||
[int]$id,
|
||||
|
||||
[int]$seat_id,
|
||||
|
||||
[int]$limit = 50,
|
||||
|
||||
[int]$offset,
|
||||
|
||||
[switch]$all = $false,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$apiKey
|
||||
)
|
||||
begin {
|
||||
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
|
||||
|
||||
$SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters -DefaultExcludeParameter 'url', 'apiKey', 'Debug', 'Verbose','RequestType'
|
||||
|
||||
$api = "/api/v1/licenses/$id/seats"
|
||||
|
||||
|
||||
if ($seat_id) {
|
||||
$api= "/api/v1/licenses/$id/seats/$seat_id"
|
||||
}
|
||||
|
||||
$Parameters = @{
|
||||
Api = $api
|
||||
Method = 'Get'
|
||||
GetParameters = $SearchParameter
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyApiKey -apiKey $apikey
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url) {
|
||||
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyUrl -url $url
|
||||
}
|
||||
}
|
||||
|
||||
process {
|
||||
if ($all) {
|
||||
$offstart = $(if ($offset) {$offset} Else {0})
|
||||
$callargs = $SearchParameter
|
||||
$callargs.Remove('all')
|
||||
|
||||
while ($true) {
|
||||
$callargs['offset'] = $offstart
|
||||
$callargs['limit'] = $limit
|
||||
$res=Get-SnipeitLicenseSeat @callargs
|
||||
$res
|
||||
if ($res.count -lt $limit) {
|
||||
break
|
||||
}
|
||||
$offstart = $offstart + $limit
|
||||
}
|
||||
} else {
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
$result
|
||||
}
|
||||
}
|
||||
|
||||
end {
|
||||
# reset legacy sessions
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url -or $PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Reset-SnipeitPSLegacyApi
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
159
SnipeitPS/Public/Get-SnipeitLocation.ps1
Normal file
159
SnipeitPS/Public/Get-SnipeitLocation.ps1
Normal file
|
|
@ -0,0 +1,159 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Gets a list of Snipe-it Locations
|
||||
|
||||
.PARAMETER search
|
||||
A text string to search the Locations data
|
||||
|
||||
.PARAMETER id
|
||||
A id of specific Location
|
||||
|
||||
.PARAMETER name
|
||||
Optionally restrict Location results to this Location name.
|
||||
|
||||
.PARAMETER address
|
||||
Optionally restrict Location results to this Location address.
|
||||
|
||||
.PARAMETER address2
|
||||
Optionally restrict Location results to this Location address2.
|
||||
|
||||
.PARAMETER city
|
||||
Optionally restrict Location results to this Location city.
|
||||
|
||||
.PARAMETER zip
|
||||
Optionally restrict Location results to this Location zip.
|
||||
|
||||
.PARAMETER country
|
||||
Optionally restrict Location results to this Location country.
|
||||
|
||||
.PARAMETER limit
|
||||
Specify the number of results you wish to return. Defaults to 50. Defines batch size for -all
|
||||
|
||||
.PARAMETER offset
|
||||
Offset to use
|
||||
|
||||
.PARAMETER all
|
||||
A return all results, works with -offset and other parameters
|
||||
|
||||
.PARAMETER url
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. URL of Snipeit system.
|
||||
|
||||
.PARAMETER apiKey
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. Users API Key for Snipeit.
|
||||
|
||||
.EXAMPLE
|
||||
Get-SnipeitLocation -search Location1
|
||||
|
||||
.EXAMPLE
|
||||
Get-SnipeitLocation -id 3
|
||||
|
||||
#>
|
||||
|
||||
function Get-SnipeitLocation() {
|
||||
[CmdletBinding(DefaultParameterSetName = 'Search')]
|
||||
Param(
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[string]$search,
|
||||
|
||||
[parameter(ParameterSetName='Get with ID')]
|
||||
[int]$id,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[string]$name,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[string]$address,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[string]$address2,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[string]$city,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[string]$zip,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[string]$country,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[ValidateSet("asc", "desc")]
|
||||
[string]$order = "desc",
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[int]$limit = 50,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[int]$offset,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[switch]$all = $false,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$apiKey
|
||||
)
|
||||
begin {
|
||||
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
|
||||
|
||||
$SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
|
||||
|
||||
$api = "/api/v1/locations"
|
||||
|
||||
if ($search -and $id ) {
|
||||
Throw "[$($MyInvocation.MyCommand.Name)] Please specify only -search or -id parameter , not both "
|
||||
}
|
||||
|
||||
if ($id) {
|
||||
$api= "/api/v1/locations/$id"
|
||||
}
|
||||
|
||||
$Parameters = @{
|
||||
Api = $api
|
||||
Method = 'Get'
|
||||
GetParameters = $SearchParameter
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyApiKey -apiKey $apikey
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url) {
|
||||
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyUrl -url $url
|
||||
}
|
||||
}
|
||||
|
||||
process {
|
||||
if ($all) {
|
||||
$offstart = $(if ($offset) {$offset} Else {0})
|
||||
$callargs = $SearchParameter
|
||||
$callargs.Remove('all')
|
||||
|
||||
while ($true) {
|
||||
$callargs['offset'] = $offstart
|
||||
$callargs['limit'] = $limit
|
||||
$res=Get-SnipeitLocation @callargs
|
||||
$res
|
||||
if ($res.count -lt $limit) {
|
||||
break
|
||||
}
|
||||
$offstart = $offstart + $limit
|
||||
}
|
||||
} else {
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
$result
|
||||
}
|
||||
}
|
||||
|
||||
end {
|
||||
# reset legacy sessions
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url -or $PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Reset-SnipeitPSLegacyApi
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
129
SnipeitPS/Public/Get-SnipeitManufacturer.ps1
Normal file
129
SnipeitPS/Public/Get-SnipeitManufacturer.ps1
Normal file
|
|
@ -0,0 +1,129 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
# Gets a list of Snipe-it Manufacturers
|
||||
|
||||
.PARAMETER search
|
||||
A text string to search the Manufactures data
|
||||
|
||||
.PARAMETER id
|
||||
A id of specific Manufactuter
|
||||
|
||||
.PARAMETER name
|
||||
Optionally restrict Manufacturer results to this name field
|
||||
|
||||
.PARAMETER limit
|
||||
Specify the number of results you wish to return. Defaults to 50. Defines batch size for -all
|
||||
|
||||
.PARAMETER offset
|
||||
Offset to use
|
||||
|
||||
.PARAMETER all
|
||||
A return all results, works with -offset and other parameters
|
||||
|
||||
.PARAMETER url
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. URL of Snipeit system.
|
||||
|
||||
.PARAMETER apiKey
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. Users API Key for Snipeit.
|
||||
|
||||
.EXAMPLE
|
||||
Get-SnipeitManufacturer -search HP
|
||||
Search all manufacturers for string HP
|
||||
|
||||
.EXAMPLE
|
||||
Get-SnipeitManufacturer -id 3
|
||||
Returns manufacturer with id 3
|
||||
|
||||
#>
|
||||
function Get-SnipeitManufacturer() {
|
||||
[CmdletBinding(DefaultParameterSetName = 'Search')]
|
||||
Param(
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[string]$search,
|
||||
|
||||
[parameter(ParameterSetName='Get with ID')]
|
||||
[int]$id,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[string]$name,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[ValidateSet("asc", "desc")]
|
||||
[string]$order = "desc",
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[int]$limit = 50,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[int]$offset,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[switch]$all = $false,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$apiKey
|
||||
)
|
||||
begin {
|
||||
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
|
||||
|
||||
$SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
|
||||
|
||||
$api = "/api/v1/manufacturers"
|
||||
|
||||
if ($search -and $id ) {
|
||||
Throw "[$($MyInvocation.MyCommand.Name)] Please specify only -search or -id parameter , not both "
|
||||
}
|
||||
|
||||
if ($id) {
|
||||
$api= "/api/v1/manufacturers/$id"
|
||||
}
|
||||
|
||||
$Parameters = @{
|
||||
Api = $api
|
||||
Method = 'Get'
|
||||
GetParameters = $SearchParameter
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyApiKey -apiKey $apikey
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url) {
|
||||
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyUrl -url $url
|
||||
}
|
||||
}
|
||||
|
||||
process {
|
||||
if ($all) {
|
||||
$offstart = $(if ($offset) {$offset} Else {0})
|
||||
$callargs = $SearchParameter
|
||||
$callargs.Remove('all')
|
||||
|
||||
while ($true) {
|
||||
$callargs['offset'] = $offstart
|
||||
$callargs['limit'] = $limit
|
||||
$res=Get-SnipeitManufacturer @callargs
|
||||
$res
|
||||
if ($res.count -lt $limit) {
|
||||
break
|
||||
}
|
||||
$offstart = $offstart + $limit
|
||||
}
|
||||
} else {
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
$result
|
||||
}
|
||||
}
|
||||
|
||||
end {
|
||||
# reset legacy sessions
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url -or $PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Reset-SnipeitPSLegacyApi
|
||||
}
|
||||
}
|
||||
}
|
||||
123
SnipeitPS/Public/Get-SnipeitModel.ps1
Normal file
123
SnipeitPS/Public/Get-SnipeitModel.ps1
Normal file
|
|
@ -0,0 +1,123 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Gets a list of Snipe-it Models
|
||||
|
||||
.PARAMETER search
|
||||
A text string to search the Models data
|
||||
|
||||
.PARAMETER id
|
||||
A id of specific model
|
||||
|
||||
.PARAMETER limit
|
||||
Specify the number of results you wish to return. Defaults to 50. Defines batch size for -all
|
||||
|
||||
.PARAMETER offset
|
||||
Offset to use
|
||||
|
||||
.PARAMETER all
|
||||
A return all results, works with -offset and other parameters
|
||||
|
||||
.PARAMETER url
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. URL of Snipeit system.
|
||||
|
||||
.PARAMETER apiKey
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. Users API Key for Snipeit.
|
||||
|
||||
.EXAMPLE
|
||||
Get-SnipeitModel -search "DL380"
|
||||
|
||||
.EXAMPLE
|
||||
Get-SnipeitModel -id 1
|
||||
|
||||
#>
|
||||
|
||||
function Get-SnipeitModel() {
|
||||
[CmdletBinding(DefaultParameterSetName = 'Search')]
|
||||
Param(
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[string]$search,
|
||||
|
||||
[parameter(ParameterSetName='Get with ID')]
|
||||
[int]$id,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[ValidateSet("asc", "desc")]
|
||||
[string]$order = "desc",
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[int]$limit = 50,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[int]$offset,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[switch]$all = $false,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$apiKey
|
||||
)
|
||||
|
||||
begin {
|
||||
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
|
||||
|
||||
$SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
|
||||
|
||||
$api = "/api/v1/models"
|
||||
|
||||
if ($search -and $id ) {
|
||||
Throw "[$($MyInvocation.MyCommand.Name)] Please specify only -search or -id parameter , not both "
|
||||
}
|
||||
|
||||
if ($id) {
|
||||
$api= "/api/v1/models/$id"
|
||||
}
|
||||
|
||||
$Parameters = @{
|
||||
Api = $api
|
||||
Method = 'Get'
|
||||
GetParameters = $SearchParameter
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyApiKey -apiKey $apikey
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url) {
|
||||
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyUrl -url $url
|
||||
}
|
||||
}
|
||||
|
||||
process {
|
||||
if ($all) {
|
||||
$offstart = $(if ($offset) {$offset} Else {0})
|
||||
$callargs = $SearchParameter
|
||||
$callargs.Remove('all')
|
||||
|
||||
while ($true) {
|
||||
$callargs['offset'] = $offstart
|
||||
$callargs['limit'] = $limit
|
||||
$res=Get-SnipeitModel @callargs
|
||||
$res
|
||||
if ($res.count -ne $limit ) {
|
||||
break
|
||||
}
|
||||
$offstart = $offstart + $limit
|
||||
}
|
||||
} else {
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
$result
|
||||
}
|
||||
}
|
||||
|
||||
end {
|
||||
# reset legacy sessions
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url -or $PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Reset-SnipeitPSLegacyApi
|
||||
}
|
||||
}
|
||||
}
|
||||
128
SnipeitPS/Public/Get-SnipeitStatus.ps1
Normal file
128
SnipeitPS/Public/Get-SnipeitStatus.ps1
Normal file
|
|
@ -0,0 +1,128 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Gets a list of Snipe-it Status Labels
|
||||
|
||||
.PARAMETER search
|
||||
A text string to search the Status Labels data
|
||||
|
||||
.PARAMETER id
|
||||
A id of specific Status Label
|
||||
|
||||
.PARAMETER name
|
||||
Optionally restrict Status Label results to this name field
|
||||
|
||||
.PARAMETER limit
|
||||
Specify the number of results you wish to return. Defaults to 50. Defines batch size for -all
|
||||
|
||||
.PARAMETER offset
|
||||
Offset to use
|
||||
|
||||
.PARAMETER all
|
||||
A return all results, works with -offset and other parameters
|
||||
|
||||
.PARAMETER url
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. URL of Snipeit system.
|
||||
|
||||
.PARAMETER apiKey
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. Users API Key for Snipeit.
|
||||
|
||||
.EXAMPLE
|
||||
Get-SnipeitStatus -search "Ready to Deploy"
|
||||
|
||||
.EXAMPLE
|
||||
Get-SnipeitStatus -id 3
|
||||
|
||||
#>
|
||||
|
||||
function Get-SnipeitStatus() {
|
||||
[CmdletBinding(DefaultParameterSetName = 'Search')]
|
||||
Param(
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[string]$search,
|
||||
|
||||
[parameter(ParameterSetName='Get with ID')]
|
||||
[int]$id,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[string]$name,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[ValidateSet("asc", "desc")]
|
||||
[string]$order = "desc",
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[int]$limit = 50,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[int]$offset,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[switch]$all = $false,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$apiKey
|
||||
)
|
||||
begin {
|
||||
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
|
||||
|
||||
$SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
|
||||
|
||||
$api = "/api/v1/statuslabels"
|
||||
|
||||
if ($search -and $id ) {
|
||||
Throw "[$($MyInvocation.MyCommand.Name)] Please specify only -search or -id parameter , not both "
|
||||
}
|
||||
|
||||
if ($id) {
|
||||
$api= "/api/v1/statuslabels/$id"
|
||||
}
|
||||
|
||||
$Parameters = @{
|
||||
Api = $api
|
||||
Method = 'Get'
|
||||
GetParameters = $SearchParameter
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyApiKey -apiKey $apikey
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url) {
|
||||
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyUrl -url $url
|
||||
}
|
||||
}
|
||||
|
||||
process {
|
||||
if ($all) {
|
||||
$offstart = $(if ($offset) {$offset} Else {0})
|
||||
$callargs = $SearchParameter
|
||||
$callargs.Remove('all')
|
||||
|
||||
while ($true) {
|
||||
$callargs['offset'] = $offstart
|
||||
$callargs['limit'] = $limit
|
||||
$res=Get-SnipeitStatus @callargs
|
||||
$res
|
||||
if ($res.count -lt $limit) {
|
||||
break
|
||||
}
|
||||
$offstart = $offstart + $limit
|
||||
}
|
||||
} else {
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
$result
|
||||
}
|
||||
}
|
||||
|
||||
end {
|
||||
# reset legacy sessions
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url -or $PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Reset-SnipeitPSLegacyApi
|
||||
}
|
||||
}
|
||||
}
|
||||
176
SnipeitPS/Public/Get-SnipeitSupplier.ps1
Normal file
176
SnipeitPS/Public/Get-SnipeitSupplier.ps1
Normal file
|
|
@ -0,0 +1,176 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
# Gets a list of Snipe-it Suppliers
|
||||
|
||||
.PARAMETER search
|
||||
A text string to search the Supliers data
|
||||
|
||||
.PARAMETER id
|
||||
A id of specific Suplier
|
||||
|
||||
.PARAMETER name
|
||||
Optionally restrict Supplier results to this Supplier name.
|
||||
|
||||
.PARAMETER address
|
||||
Optionally restrict Supplier results to this Supplier address.
|
||||
|
||||
.PARAMETER address2
|
||||
Optionally restrict Supplier results to this Supplier address2.
|
||||
|
||||
.PARAMETER city
|
||||
Optionally restrict Supplier results to this Supplier city.
|
||||
|
||||
.PARAMETER zip
|
||||
Optionally restrict Supplier results to this Supplier zip.
|
||||
|
||||
.PARAMETER country
|
||||
Optionally restrict Supplier results to this Supplier country.
|
||||
|
||||
.PARAMETER fax
|
||||
Optionally restrict Supplier results to this Supplier fax number.
|
||||
|
||||
.PARAMETER email
|
||||
Optionally restrict Supplier results to this Supplier email address.
|
||||
|
||||
.PARAMETER notes
|
||||
Optionally restrict Supplier results to this Supplier notes field.
|
||||
|
||||
.PARAMETER limit
|
||||
Specify the number of results you wish to return. Defaults to 50. Defines batch size for -all
|
||||
|
||||
.PARAMETER offset
|
||||
Offset to use
|
||||
|
||||
.PARAMETER all
|
||||
A return all results, works with -offset and other parameters
|
||||
|
||||
.PARAMETER url
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. URL of Snipeit system.
|
||||
|
||||
.PARAMETER apiKey
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. Users API Key for Snipeit.
|
||||
|
||||
.EXAMPLE
|
||||
Get-SnipeitSupplier -search MySupplier
|
||||
|
||||
.EXAMPLE
|
||||
Get-SnipeitSupplier -id 2
|
||||
|
||||
#>
|
||||
function Get-SnipeitSupplier() {
|
||||
[CmdletBinding(DefaultParameterSetName = 'Search')]
|
||||
Param(
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[string]$search,
|
||||
|
||||
[parameter(ParameterSetName='Get with ID')]
|
||||
[int]$id,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[ValidateSet("asc", "desc")]
|
||||
[string]$order = "desc",
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[string]$name,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[string]$address,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[string]$address2,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[string]$city,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[string]$zip,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[string]$country,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[string]$fax,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[string]$email,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[string]$notes,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[int]$limit = 50,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[int]$offset,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[switch]$all = $false,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$apiKey
|
||||
)
|
||||
|
||||
begin {
|
||||
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
|
||||
|
||||
$SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
|
||||
|
||||
$api = "/api/v1/suppliers"
|
||||
|
||||
if ($search -and $id ) {
|
||||
Throw "[$($MyInvocation.MyCommand.Name)] Please specify only -search or -id parameter , not both "
|
||||
}
|
||||
|
||||
if ($id) {
|
||||
$api= "/api/v1/suppliers/$id"
|
||||
}
|
||||
|
||||
$Parameters = @{
|
||||
Api = $api
|
||||
Method = 'Get'
|
||||
GetParameters = $SearchParameter
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyApiKey -apiKey $apikey
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url) {
|
||||
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyUrl -url $url
|
||||
}
|
||||
}
|
||||
|
||||
process {
|
||||
if ($all) {
|
||||
$offstart = $(if ($offset) {$offset} Else {0})
|
||||
$callargs = $SearchParameter
|
||||
$callargs.Remove('all')
|
||||
|
||||
while ($true) {
|
||||
$callargs['offset'] = $offstart
|
||||
$callargs['limit'] = $limit
|
||||
$res=Get-SnipeitSupplier @callargs
|
||||
$res
|
||||
if ($res.count -lt $limit) {
|
||||
break
|
||||
}
|
||||
$offstart = $offstart + $limit
|
||||
}
|
||||
} else {
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
$result
|
||||
}
|
||||
}
|
||||
end {
|
||||
# reset legacy sessions
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url -or $PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Reset-SnipeitPSLegacyApi
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
232
SnipeitPS/Public/Get-SnipeitUser.ps1
Normal file
232
SnipeitPS/Public/Get-SnipeitUser.ps1
Normal file
|
|
@ -0,0 +1,232 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
# Gets a list of Snipe-it Users
|
||||
|
||||
.PARAMETER search
|
||||
A text string to search the User data
|
||||
|
||||
.PARAMETER id
|
||||
A id of specific User
|
||||
|
||||
.PARAMETER accessory_id
|
||||
Get users a specific accessory id has been checked out to
|
||||
|
||||
.PARAMETER username
|
||||
Optionally restrict User results to this username field
|
||||
|
||||
.PARAMETER email
|
||||
Optionally restrict User results to this email field
|
||||
|
||||
.PARAMETER employee_num
|
||||
Optionally restrict User results to this employee_num field
|
||||
|
||||
.PARAMETER state
|
||||
Optionally restrict User results to this state field
|
||||
|
||||
.PARAMETER country
|
||||
Optionally restrict User results to this country field
|
||||
|
||||
.PARAMETER zip
|
||||
Optionally restrict User results to this zip field
|
||||
|
||||
.PARAMETER company_id
|
||||
Optionally restrict User results to this company_id field
|
||||
|
||||
.PARAMETER location_id
|
||||
Optionally restrict User results to this location_id field
|
||||
|
||||
.PARAMETER department_id
|
||||
Optionally restrict User results to this department_id field
|
||||
|
||||
.PARAMETER deleted
|
||||
Optionally restrict User results to deleted users only
|
||||
|
||||
.PARAMETER ldap_import
|
||||
Optionally restrict User results to those with specified ldap_import value
|
||||
|
||||
.PARAMETER remote
|
||||
Optionally restrict User results to those with specified remote worker value
|
||||
|
||||
.PARAMETER assets_count
|
||||
Optionally restrict User results to those with the specified assets count
|
||||
|
||||
.PARAMETER licenses_count
|
||||
Optionally restrict User results to those with the specified licenses count
|
||||
|
||||
.PARAMETER accessories_count
|
||||
Optionally restrict User results to those with the specified accessories count
|
||||
|
||||
.PARAMETER consumables_count
|
||||
Optionally restrict User results to those with the specified consumables count
|
||||
|
||||
.PARAMETER limit
|
||||
Specify the number of results you wish to return. Defaults to 50. Defines batch size for -all
|
||||
|
||||
.PARAMETER offset
|
||||
Offset to use
|
||||
|
||||
.PARAMETER all
|
||||
A return all results, works with -offset and other parameters
|
||||
|
||||
.PARAMETER url
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. URL of Snipeit system.
|
||||
|
||||
.PARAMETER apiKey
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. Users API Key for Snipeit.
|
||||
|
||||
.EXAMPLE
|
||||
Get-SnipeitUser -search SomeSurname
|
||||
|
||||
.EXAMPLE
|
||||
Get-SnipeitUser -id 3
|
||||
|
||||
.EXAMPLE
|
||||
Get-SnipeitUser -username someuser
|
||||
|
||||
.EXAMPLE
|
||||
Get-SnipeitUser -email user@somedomain.com
|
||||
|
||||
.EXAMPLE
|
||||
Get-SnipeitUser -accessory_id 3
|
||||
Get users with accessory id 3 has been checked out to
|
||||
#>
|
||||
|
||||
function Get-SnipeitUser() {
|
||||
[CmdletBinding(DefaultParameterSetName = 'Search')]
|
||||
Param(
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[string]$search,
|
||||
|
||||
[parameter(ParameterSetName='Get with ID')]
|
||||
[string]$id,
|
||||
|
||||
[parameter(ParameterSetName='Get users a specific accessory id has been checked out to')]
|
||||
[string]$accessory_id,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[int]$company_id,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[int]$location_id,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[int]$group_id,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[int]$department_id,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[string]$username,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[string]$email,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[string]$employee_num,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[string]$state,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[string]$zip,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[string]$country,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[Nullable[bool]]$deleted,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[Nullable[bool]]$ldap_import,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[Nullable[bool]]$remote,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[int]$assets_count,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[int]$licenses_count,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[int]$accessories_count,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[int]$consumables_count,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[ValidateSet("asc", "desc")]
|
||||
[string]$order = "desc",
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[int]$limit = 50,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[int]$offset,
|
||||
|
||||
[parameter(ParameterSetName='Search')]
|
||||
[parameter(ParameterSetName='Get users a specific accessory id has been checked out to')]
|
||||
[switch]$all = $false,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$apiKey
|
||||
)
|
||||
|
||||
begin {
|
||||
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
|
||||
|
||||
$SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
|
||||
switch ($PsCmdlet.ParameterSetName) {
|
||||
'Search' { $api = "/api/v1/users"}
|
||||
'Get with id' {$api= "/api/v1/users/$id"}
|
||||
'Get users a specific accessory id has been checked out to' {$api= "/api/v1/accessories/$accessory_id/checkedout"}
|
||||
}
|
||||
|
||||
$Parameters = @{
|
||||
Api = $api
|
||||
Method = 'Get'
|
||||
GetParameters = $SearchParameter
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyApiKey -apiKey $apikey
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url) {
|
||||
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyUrl -url $url
|
||||
}
|
||||
}
|
||||
process {
|
||||
if ($all) {
|
||||
$offstart = $(if ($offset) {$offset} Else {0})
|
||||
$callargs = $SearchParameter
|
||||
$callargs.Remove('all')
|
||||
|
||||
while ($true) {
|
||||
$callargs['offset'] = $offstart
|
||||
$callargs['limit'] = $limit
|
||||
$res=Get-SnipeitUser @callargs
|
||||
$res
|
||||
if ($res.count -lt $limit) {
|
||||
break
|
||||
}
|
||||
$offstart = $offstart + $limit
|
||||
}
|
||||
} else {
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
$result
|
||||
}
|
||||
}
|
||||
|
||||
end {
|
||||
# reset legacy sessions
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url -or $PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Reset-SnipeitPSLegacyApi
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,57 +0,0 @@
|
|||
<#
|
||||
.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(
|
||||
[string]$search,
|
||||
|
||||
[ValidateSet("asc", "desc")]
|
||||
[string]$order = "desc",
|
||||
|
||||
[int]$limit = 50,
|
||||
|
||||
[int]$offset,
|
||||
|
||||
[parameter(mandatory = $true)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $true)]
|
||||
[string]$apiKey
|
||||
)
|
||||
|
||||
$SearchParameter = @{
|
||||
sort = $sort
|
||||
order = $order
|
||||
limit = $limit
|
||||
offset = $offset
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('search')) { $SearchParameter.Add("search", $search) }
|
||||
|
||||
$Parameters = @{
|
||||
Uri = "$url/api/v1/statuslabels"
|
||||
Method = 'Get'
|
||||
Token = $apiKey
|
||||
GetParameters = $SearchParameter
|
||||
}
|
||||
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
|
||||
$result
|
||||
}
|
||||
|
|
@ -1,58 +0,0 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
# Gets a list of Snipe-it Suppliers
|
||||
|
||||
.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-Supplier -url "https://assets.example.com" -token "token..."
|
||||
|
||||
.EXAMPLE
|
||||
Get-Supplier -url "https://assets.example.com" -token "token..." | Where-Object {$_.name -eq "MySupplier" }
|
||||
|
||||
#>
|
||||
|
||||
function Get-Supplier()
|
||||
{
|
||||
Param(
|
||||
[string]$search,
|
||||
|
||||
[ValidateSet("asc", "desc")]
|
||||
[string]$order = "desc",
|
||||
|
||||
[int]$limit = 50,
|
||||
|
||||
[int]$offset,
|
||||
|
||||
[parameter(mandatory = $true)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $true)]
|
||||
[string]$apiKey
|
||||
)
|
||||
|
||||
$SearchParameter = @{
|
||||
sort = $sort
|
||||
order = $order
|
||||
limit = $limit
|
||||
offset = $offset
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('search')) { $SearchParameter.Add("search", $search) }
|
||||
|
||||
$Parameters = @{
|
||||
Uri = "$url/api/v1/suppliers"
|
||||
Method = 'Get'
|
||||
Token = $apiKey
|
||||
GetParameters = $SearchParameter
|
||||
}
|
||||
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
|
||||
$result
|
||||
}
|
||||
|
||||
|
|
@ -1,67 +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-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(
|
||||
[string]$search,
|
||||
|
||||
[int]$company_id,
|
||||
|
||||
[int]$location_id,
|
||||
|
||||
[int]$group_id,
|
||||
|
||||
[int]$department_id,
|
||||
|
||||
[ValidateSet("asc", "desc")]
|
||||
[string]$order = "desc",
|
||||
|
||||
[int]$limit = 50,
|
||||
|
||||
[int]$offset,
|
||||
|
||||
[parameter(mandatory = $true)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $true)]
|
||||
[string]$apiKey
|
||||
)
|
||||
|
||||
$SearchParameter = @{
|
||||
sort = $sort
|
||||
order = $order
|
||||
limit = $limit
|
||||
offset = $offset
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('search')) { $SearchParameter.Add("search", $search) }
|
||||
if ($PSBoundParameters.ContainsKey('company_id')) { $SearchParameter.Add("company_id", $company_id) }
|
||||
if ($PSBoundParameters.ContainsKey('location_id')) { $SearchParameter.Add("location_id", $location_id) }
|
||||
if ($PSBoundParameters.ContainsKey('group_id')) { $SearchParameter.Add("group_id", $group_id) }
|
||||
if ($PSBoundParameters.ContainsKey('department_id')) { $SearchParameter.Add("department_id", $department_id) }
|
||||
|
||||
$Parameters = @{
|
||||
Uri = "$url/api/v1/users"
|
||||
Method = 'Get'
|
||||
GetParameters = $SearchParameter
|
||||
Token = $apiKey
|
||||
}
|
||||
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
|
||||
$result
|
||||
}
|
||||
|
|
@ -1,95 +0,0 @@
|
|||
<#
|
||||
.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(
|
||||
SupportsShouldProcess = $true,
|
||||
ConfirmImpact = "Low"
|
||||
)]
|
||||
|
||||
Param(
|
||||
[string]$tag,
|
||||
|
||||
[parameter(mandatory = $true)]
|
||||
[string]$Name,
|
||||
|
||||
[parameter(mandatory = $true)]
|
||||
[int]$Status_id,
|
||||
|
||||
[parameter(mandatory = $true)]
|
||||
[int]$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
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('tag'))
|
||||
{
|
||||
$Values += @{"asset_tag" = $tag}
|
||||
}
|
||||
|
||||
if ($customfields)
|
||||
{
|
||||
$Values += $customfields
|
||||
}
|
||||
|
||||
$Body = $Values | ConvertTo-Json;
|
||||
|
||||
$Parameters = @{
|
||||
Uri = "$url/api/v1/hardware"
|
||||
Method = 'Post'
|
||||
Body = $Body
|
||||
Token = $apiKey
|
||||
}
|
||||
|
||||
If ($PSCmdlet.ShouldProcess("ShouldProcess?"))
|
||||
{
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
}
|
||||
|
||||
$result
|
||||
}
|
||||
|
|
@ -1,62 +0,0 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Short description
|
||||
|
||||
.DESCRIPTION
|
||||
Long description
|
||||
|
||||
.PARAMETER name
|
||||
Parameter description
|
||||
|
||||
.PARAMETER url
|
||||
Parameter description
|
||||
|
||||
.PARAMETER apiKey
|
||||
Parameter description
|
||||
|
||||
.EXAMPLE
|
||||
An example
|
||||
|
||||
.NOTES
|
||||
General notes
|
||||
#>
|
||||
|
||||
function New-Company()
|
||||
{
|
||||
[CmdletBinding(
|
||||
SupportsShouldProcess = $true,
|
||||
ConfirmImpact = "Low"
|
||||
)]
|
||||
|
||||
Param(
|
||||
[parameter(mandatory = $true)]
|
||||
[string]$name,
|
||||
|
||||
[parameter(mandatory = $true)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $true)]
|
||||
[string]$apiKey
|
||||
)
|
||||
|
||||
$Values = @{
|
||||
"name" = $name
|
||||
}
|
||||
|
||||
$Body = $Values | ConvertTo-Json;
|
||||
|
||||
$Parameters = @{
|
||||
Uri = "$url/api/v1/companies"
|
||||
Method = 'POST'
|
||||
Body = $Body
|
||||
Token = $apiKey
|
||||
}
|
||||
|
||||
If ($PSCmdlet.ShouldProcess("ShouldProcess?"))
|
||||
{
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
}
|
||||
|
||||
$result
|
||||
}
|
||||
|
||||
|
|
@ -1,76 +0,0 @@
|
|||
<#
|
||||
.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 = "Low"
|
||||
)]
|
||||
|
||||
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("ShouldProcess?"))
|
||||
{
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
}
|
||||
|
||||
$result
|
||||
}
|
||||
|
||||
|
|
@ -1,77 +0,0 @@
|
|||
<#
|
||||
.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-Department()
|
||||
{
|
||||
[CmdletBinding(
|
||||
SupportsShouldProcess = $true,
|
||||
ConfirmImpact = "Low"
|
||||
)]
|
||||
|
||||
Param(
|
||||
[parameter(mandatory = $true)]
|
||||
[string]$name,
|
||||
|
||||
[string]$company_id,
|
||||
|
||||
[string]$location_id,
|
||||
|
||||
[string]$manager_id,
|
||||
|
||||
[parameter(mandatory = $true)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $true)]
|
||||
[string]$apiKey
|
||||
)
|
||||
|
||||
$Values = @{
|
||||
"name" = $name
|
||||
"company_id" = $company_id
|
||||
"location_id" = $location_id
|
||||
"manager_id" = $manager_id
|
||||
}
|
||||
|
||||
$Body = $Values | ConvertTo-Json;
|
||||
|
||||
$Parameters = @{
|
||||
Uri = "$url/api/v1/departments"
|
||||
Method = 'POST'
|
||||
Body = $Body
|
||||
Token = $apiKey
|
||||
}
|
||||
|
||||
If ($PSCmdlet.ShouldProcess("ShouldProcess?"))
|
||||
{
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
}
|
||||
|
||||
$result
|
||||
}
|
||||
|
||||
|
|
@ -1,80 +0,0 @@
|
|||
<#
|
||||
.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-Location() {
|
||||
[CmdletBinding(
|
||||
SupportsShouldProcess = $true,
|
||||
ConfirmImpact = "Low"
|
||||
)]
|
||||
|
||||
Param(
|
||||
[parameter(mandatory = $true)]
|
||||
[string]$name,
|
||||
|
||||
[string]$address,
|
||||
|
||||
[string]$address2,
|
||||
|
||||
[string]$state,
|
||||
|
||||
[string]$country,
|
||||
|
||||
[string]$zip,
|
||||
|
||||
[parameter(mandatory = $true)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $true)]
|
||||
[string]$apiKey
|
||||
)
|
||||
|
||||
$Values = @{
|
||||
name = $name
|
||||
address = $address
|
||||
address2 = $address2
|
||||
state = $state
|
||||
country = $country
|
||||
zip = $zip
|
||||
}
|
||||
|
||||
$Body = $Values | ConvertTo-Json;
|
||||
|
||||
$Parameters = @{
|
||||
Uri = "$url/api/v1/locations"
|
||||
Method = 'post'
|
||||
Body = $Body
|
||||
Token = $apiKey
|
||||
}
|
||||
|
||||
If ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
}
|
||||
|
||||
$result
|
||||
}
|
||||
|
|
@ -1,60 +0,0 @@
|
|||
<#
|
||||
.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(
|
||||
SupportsShouldProcess = $true,
|
||||
ConfirmImpact = "Low"
|
||||
)]
|
||||
|
||||
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("ShouldProcess?"))
|
||||
{
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
}
|
||||
|
||||
$result
|
||||
}
|
||||
|
|
@ -1,79 +0,0 @@
|
|||
<#
|
||||
.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(
|
||||
SupportsShouldProcess = $true,
|
||||
ConfirmImpact = "Low"
|
||||
)]
|
||||
|
||||
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("ShouldProcess?"))
|
||||
{
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
}
|
||||
|
||||
$result
|
||||
}
|
||||
158
SnipeitPS/Public/New-SnipeitAccessory.ps1
Normal file
158
SnipeitPS/Public/New-SnipeitAccessory.ps1
Normal file
|
|
@ -0,0 +1,158 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Creates new accessory on Snipe-It system
|
||||
|
||||
.DESCRIPTION
|
||||
Creates new accessory on Snipe-It system
|
||||
|
||||
.PARAMETER name
|
||||
Accessory name
|
||||
|
||||
.PARAMETER notes
|
||||
Notes about the accessory
|
||||
|
||||
.PARAMETER qty
|
||||
Quantity of the accessory you have
|
||||
|
||||
.PARAMETER category_id
|
||||
ID number of the category the accessory belongs to
|
||||
|
||||
.PARAMETER company_id
|
||||
ID Number of the company the accessory is assigned to
|
||||
|
||||
.PARAMETER manufacturer_id
|
||||
ID number of the manufacturer for this accessory.
|
||||
|
||||
.PARAMETER model_number
|
||||
Model number for this accessory
|
||||
|
||||
.PARAMETER order_number
|
||||
Order number for this accessory.
|
||||
|
||||
.PARAMETER purchase_cost
|
||||
Cost of item being purchased.
|
||||
|
||||
.PARAMETER purchase_date
|
||||
Date accessory was purchased
|
||||
|
||||
.PARAMETER order_number
|
||||
Order number for this accessory.
|
||||
|
||||
.PARAMETER purchase_cost
|
||||
Cost of item being purchased.
|
||||
|
||||
.PARAMETER purchase_date
|
||||
Date accessory was purchased
|
||||
|
||||
.PARAMETER supplier_id
|
||||
ID number of the supplier for this accessory
|
||||
|
||||
.PARAMETER location_id
|
||||
ID number of the location the accessory is assigned to
|
||||
|
||||
.PARAMETER min_amt
|
||||
Min quantity of the accessory before alert is triggered
|
||||
|
||||
.PARAMETER image
|
||||
Accessory image fileame and path
|
||||
|
||||
.PARAMETER url
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. URL of Snipeit system.
|
||||
|
||||
.PARAMETER apiKey
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. Users API Key for Snipeit.
|
||||
|
||||
.EXAMPLE
|
||||
New-SnipeitAccessory -name "Accessory" -qty 3 -category_id 1
|
||||
|
||||
#>
|
||||
function New-SnipeitAccessory() {
|
||||
[CmdletBinding(
|
||||
SupportsShouldProcess = $true,
|
||||
ConfirmImpact = "Low"
|
||||
)]
|
||||
|
||||
Param(
|
||||
[parameter(mandatory = $true)]
|
||||
[ValidateLength(3, 255)]
|
||||
[string]$name,
|
||||
|
||||
[parameter(mandatory = $true)]
|
||||
[int]$qty,
|
||||
|
||||
[parameter(mandatory = $true)]
|
||||
[ValidateRange(1, [int]::MaxValue)]
|
||||
[int]$category_id,
|
||||
|
||||
[ValidateRange(1, [int]::MaxValue)]
|
||||
[int]$company_id,
|
||||
|
||||
[ValidateRange(1, [int]::MaxValue)]
|
||||
[int]$manufacturer_id,
|
||||
|
||||
[string]$order_number,
|
||||
|
||||
[string]$model_number,
|
||||
|
||||
[float]$purchase_cost,
|
||||
|
||||
[datetime]$purchase_date,
|
||||
|
||||
[int]$min_amt,
|
||||
|
||||
[ValidateRange(1, [int]::MaxValue)]
|
||||
[int]$supplier_id,
|
||||
|
||||
[ValidateRange(1, [int]::MaxValue)]
|
||||
[int]$location_id,
|
||||
|
||||
[ValidateScript({Test-Path $_})]
|
||||
[string]$image,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$apiKey
|
||||
)
|
||||
begin {
|
||||
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
|
||||
|
||||
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
|
||||
|
||||
if ($values['purchase_date']) {
|
||||
$values['purchase_date'] = $values['purchase_date'].ToString("yyyy-MM-dd")
|
||||
}
|
||||
|
||||
$Parameters = @{
|
||||
Api = "/api/v1/accessories"
|
||||
Method = 'POST'
|
||||
Body = $Values
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyApiKey -apiKey $apikey
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url) {
|
||||
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyUrl -url $url
|
||||
}
|
||||
}
|
||||
|
||||
process {
|
||||
if ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
}
|
||||
$result
|
||||
}
|
||||
|
||||
end {
|
||||
# reset legacy sessions
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url -or $PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Reset-SnipeitPSLegacyApi
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
208
SnipeitPS/Public/New-SnipeitAsset.ps1
Normal file
208
SnipeitPS/Public/New-SnipeitAsset.ps1
Normal file
|
|
@ -0,0 +1,208 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Add a new Asset to Snipe-it asset system
|
||||
|
||||
.DESCRIPTION
|
||||
Long description
|
||||
|
||||
|
||||
.PARAMETER status_id
|
||||
Required Status ID of the asset, this can be got using Get-Status
|
||||
|
||||
.PARAMETER model_id
|
||||
Required Model ID of the asset, this can be got using Get-Model
|
||||
|
||||
.PARAMETER name
|
||||
Optional Name of the Asset
|
||||
|
||||
.PARAMETER asset_tag
|
||||
Asset Tag for the Asset, not required when snipe asset_tag autogeneration is on.
|
||||
|
||||
.PARAMETER serial
|
||||
Optional Serial number of the Asset
|
||||
|
||||
.PARAMETER company_id
|
||||
Optional Company id
|
||||
|
||||
.PARAMETER order_number
|
||||
Optional Order number
|
||||
|
||||
.PARAMETER notes
|
||||
Optional Notes
|
||||
|
||||
.PARAMETER warranty_monhts
|
||||
Optional Warranty lenght of the Asset in months
|
||||
|
||||
.PARAMETER purchase_cost
|
||||
Optional Purchase cost of the Asset
|
||||
|
||||
.PARAMETER purchase_date
|
||||
Optional Purchase cost of the Asset
|
||||
|
||||
.PARAMETER supplier_id
|
||||
Optional Supplier id of the Asset
|
||||
|
||||
|
||||
.PARAMETER rtd_location_id
|
||||
Optional Default location id for the asset
|
||||
|
||||
.PARAMETER image
|
||||
Asset image filename and path
|
||||
|
||||
.PARAMETER assigned_id
|
||||
Id of target user , location or asset
|
||||
|
||||
.PARAMETER checkout_to_type
|
||||
Checkout asset when creating to one of following types user, location or asset.
|
||||
|
||||
.PARAMETER url
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. URL of Snipeit system.
|
||||
|
||||
.PARAMETER apiKey
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. Users API Key for Snipeit.
|
||||
|
||||
.PARAMETER customfields
|
||||
Hastable of custom fields and extra fields that need passing through to Snipeit.
|
||||
Use internal field names from snipeit .You can use Get-CustomField to get internal field names.
|
||||
|
||||
.EXAMPLE
|
||||
New-SnipeitAsset -status_id 1 -model_id 1 -name "Machine1"
|
||||
Create asset with automatic tag if tag genaration is enabled on snipe-it, other wise without tag
|
||||
|
||||
.EXAMPLE
|
||||
New-SnipeitAsset -status_id 1 -model_id 1 -name "Machine1" -asset_tag "DEV123"
|
||||
Specifying asset tag when creating asset
|
||||
|
||||
.EXAMPLE
|
||||
New-SnipeitAsset -status_id 1 -model_id 1 -name "Machine1" -customfields = @{ "_snipeit_os_5" = "Windows 10 Pro" }
|
||||
Using customfields when creating asset.
|
||||
#>
|
||||
|
||||
function New-SnipeitAsset() {
|
||||
[CmdletBinding(
|
||||
SupportsShouldProcess = $true,
|
||||
ConfirmImpact = "Low",
|
||||
DefaultParameterSetName = 'Create asset'
|
||||
)]
|
||||
|
||||
Param(
|
||||
|
||||
[parameter(ParameterSetName='Create asset',mandatory = $true)]
|
||||
[parameter(ParameterSetName='Checkout asset when creating',mandatory = $true)]
|
||||
[int]$status_id,
|
||||
|
||||
[parameter(mandatory = $true)]
|
||||
[int]$model_id,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$name,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[Alias('tag')]
|
||||
[string]$asset_tag,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$serial,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[int]$company_id,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$order_number,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$notes,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[int]$warranty_months,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$purchase_cost,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[datetime]$purchase_date,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[int]$supplier_id,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[int]$rtd_location_id,
|
||||
|
||||
[ValidateScript({Test-Path $_})]
|
||||
[string]$image,
|
||||
|
||||
[parameter(ParameterSetName='Checkout asset when creating',mandatory = $true)]
|
||||
[int]$assigned_id,
|
||||
|
||||
[parameter(ParameterSetName='Checkout asset when creating',mandatory = $true)]
|
||||
[ValidateSet("location","asset","user")]
|
||||
[string] $checkout_to_type = "user",
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$apiKey,
|
||||
|
||||
[Alias('CustomValues')]
|
||||
[hashtable] $customfields
|
||||
)
|
||||
|
||||
begin {
|
||||
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
|
||||
|
||||
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
|
||||
|
||||
if ($values['purchase_date']) {
|
||||
$values['purchase_date'] = $values['purchase_date'].ToString("yyyy-MM-dd")
|
||||
}
|
||||
|
||||
if ($customfields) {
|
||||
$Values += $customfields
|
||||
}
|
||||
|
||||
#Checkout asset when creating it
|
||||
if ($PsCmdlet.ParameterSetName -eq 'Checkout asset when creating') {
|
||||
switch ($checkout_to_type) {
|
||||
'location' { $Values += @{ "assigned_location" = $assigned_id } }
|
||||
'user' { $Values += @{ "assigned_user" = $assigned_id } }
|
||||
'asset' { $Values += @{ "assigned_asset" = $assigned_id } }
|
||||
}
|
||||
|
||||
#This are not needed for API
|
||||
if ($Values.ContainsKey('assigned_id')) {$Values.Remove('assigned_id')}
|
||||
if ($Values.ContainsKey('checkout_to_type')) {$Values.Remove('checkout_to_type')}
|
||||
}
|
||||
|
||||
$Parameters = @{
|
||||
Api = "/api/v1/hardware"
|
||||
Method = 'Post'
|
||||
Body = $Values
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyApiKey -apiKey $apikey
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url) {
|
||||
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyUrl -url $url
|
||||
}
|
||||
}
|
||||
|
||||
process {
|
||||
if ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
}
|
||||
|
||||
$result
|
||||
}
|
||||
|
||||
end {
|
||||
# reset legacy sessions
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url -or $PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Reset-SnipeitPSLegacyApi
|
||||
}
|
||||
}
|
||||
}
|
||||
124
SnipeitPS/Public/New-SnipeitAssetMaintenance.ps1
Normal file
124
SnipeitPS/Public/New-SnipeitAssetMaintenance.ps1
Normal file
|
|
@ -0,0 +1,124 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Add a new Asset maintenence to Snipe-it asset system
|
||||
|
||||
.DESCRIPTION
|
||||
Long description
|
||||
|
||||
|
||||
.PARAMETER title
|
||||
Required Title of maintenance
|
||||
|
||||
.PARAMETER asset_id
|
||||
Required ID of the asset, this can be got using Get-Asset
|
||||
|
||||
.PARAMETER supplier_id
|
||||
Required maintenance supplier
|
||||
|
||||
.PARAMETER start_date
|
||||
Required start date
|
||||
|
||||
.PARAMETER is_warranty
|
||||
Optional Maintenance done under warranty
|
||||
|
||||
.PARAMETER cost
|
||||
Optional cost
|
||||
|
||||
.PARAMETER comletion_date
|
||||
Optional completion date
|
||||
|
||||
.PARAMETER notes
|
||||
Optional cost
|
||||
|
||||
.PARAMETER url
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. URL of Snipeit system.
|
||||
|
||||
.PARAMETER apiKey
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. Users API Key for Snipeit.
|
||||
|
||||
.EXAMPLE
|
||||
New-SnipeitAssetMaintenence -asset_id 1 -supplier_id 1 -title "replace keyboard" -start_date 2021-01-01
|
||||
#>
|
||||
function New-SnipeitAssetMaintenance() {
|
||||
[CmdletBinding(
|
||||
SupportsShouldProcess = $true,
|
||||
ConfirmImpact = "Low"
|
||||
)]
|
||||
|
||||
Param(
|
||||
[parameter(mandatory = $true)]
|
||||
[int]$asset_id,
|
||||
|
||||
[parameter(mandatory = $true)]
|
||||
[int]$supplier_id,
|
||||
|
||||
[parameter(mandatory = $true)]
|
||||
[string]$asset_maintenance_type,
|
||||
|
||||
[parameter(mandatory = $true)]
|
||||
[string]$title,
|
||||
|
||||
[parameter(mandatory = $true)]
|
||||
[datetime]$start_date,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[datetime]$completion_date,
|
||||
|
||||
[bool]$is_warranty = $false,
|
||||
|
||||
[decimal]$cost,
|
||||
|
||||
[string]$notes,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$apiKey
|
||||
)
|
||||
begin {
|
||||
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
|
||||
|
||||
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
|
||||
|
||||
if ($Values['start_date']) {
|
||||
$Values['start_date'] = $Values['start_date'].ToString("yyyy-MM-dd")
|
||||
}
|
||||
|
||||
if ($Values['completion_date']) {
|
||||
$Values['completion_date'] = $Values['completion_date'].ToString("yyyy-MM-dd")
|
||||
}
|
||||
|
||||
|
||||
$Parameters = @{
|
||||
Api = "/api/v1/maintenances"
|
||||
Method = 'Post'
|
||||
Body = $Values
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyApiKey -apiKey $apikey
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url) {
|
||||
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyUrl -url $url
|
||||
}
|
||||
}
|
||||
|
||||
process {
|
||||
if ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
}
|
||||
|
||||
$result
|
||||
}
|
||||
|
||||
end {
|
||||
# reset legacy sessions
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url -or $PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Reset-SnipeitPSLegacyApi
|
||||
}
|
||||
}
|
||||
}
|
||||
90
SnipeitPS/Public/New-SnipeitAudit.ps1
Normal file
90
SnipeitPS/Public/New-SnipeitAudit.ps1
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Add a new Audit to Snipe-it asset system
|
||||
|
||||
.DESCRIPTION
|
||||
Long description
|
||||
|
||||
.PARAMETER Tag
|
||||
The asset tag of the asset you wish to audit
|
||||
|
||||
.PARAMETER next_audit_date
|
||||
Due date for the asset's next audit
|
||||
|
||||
.PARAMETER Location_id
|
||||
ID of the location you want to associate with the audit
|
||||
|
||||
.EXAMPLE
|
||||
New-SnipeitAudit -tag 1 -location_id 1
|
||||
|
||||
#>
|
||||
|
||||
function New-SnipeitAudit() {
|
||||
[CmdletBinding(
|
||||
SupportsShouldProcess = $true,
|
||||
ConfirmImpact = "Low"
|
||||
)]
|
||||
|
||||
Param(
|
||||
[parameter(mandatory = $true)]
|
||||
[string]$tag,
|
||||
|
||||
[int]$location_id,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[datetime]$next_audit_date,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$apiKey
|
||||
|
||||
)
|
||||
begin {
|
||||
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
|
||||
|
||||
$Values = @{
|
||||
"location_id" = $location_id
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('tag')) {
|
||||
$Values += @{"asset_tag" = $tag}
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('next_audit_date')) {
|
||||
$Values += @{"next_audit_date" = ($next_audit_date).ToString("yyyy-MM-dd")}
|
||||
}
|
||||
|
||||
$Parameters = @{
|
||||
Api = "/api/v1/hardware/audit"
|
||||
Method = 'Post'
|
||||
Body = $Values
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyApiKey -apiKey $apikey
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url) {
|
||||
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyUrl -url $url
|
||||
}
|
||||
}
|
||||
|
||||
process {
|
||||
if ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
}
|
||||
|
||||
$result
|
||||
}
|
||||
|
||||
end {
|
||||
# reset legacy sessions
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url -or $PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Reset-SnipeitPSLegacyApi
|
||||
}
|
||||
}
|
||||
}
|
||||
109
SnipeitPS/Public/New-SnipeitCategory.ps1
Normal file
109
SnipeitPS/Public/New-SnipeitCategory.ps1
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Create a new Snipe-IT Category
|
||||
|
||||
.PARAMETER name
|
||||
Name of new category to be created
|
||||
|
||||
.PARAMETER type
|
||||
Type of new category to be created (asset, accessory, consumable, component, license)
|
||||
|
||||
.PARAMETER eula_text
|
||||
This allows you to customize your EULAs for specific types of assets
|
||||
|
||||
.PARAMETER use_default_eula
|
||||
If switch is present, use the primary default EULA
|
||||
|
||||
.PARAMETER require_acceptance
|
||||
If switch is present, require users to confirm acceptance of assets in this category
|
||||
|
||||
.PARAMETER checkin_email
|
||||
If switch is present, send email to user on checkin/checkout
|
||||
|
||||
.PARAMETER image
|
||||
Category image filename and path
|
||||
|
||||
.PARAMETER url
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. URL of Snipeit system.
|
||||
|
||||
.PARAMETER apiKey
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. Users API Key API Key for Snipeit.
|
||||
|
||||
.EXAMPLE
|
||||
New-SnipeitCategory -name "Laptops" -category_type asset
|
||||
#>
|
||||
|
||||
function New-SnipeitCategory() {
|
||||
[CmdletBinding(
|
||||
SupportsShouldProcess = $true,
|
||||
ConfirmImpact = "Low"
|
||||
)]
|
||||
|
||||
Param(
|
||||
[parameter(mandatory = $true)]
|
||||
[string]$name,
|
||||
|
||||
[parameter(mandatory = $true)]
|
||||
[ValidateSet("asset", "accessory", "consumable", "component", "license")]
|
||||
[string]$category_type,
|
||||
|
||||
[string]$eula_text,
|
||||
|
||||
[switch]$use_default_eula,
|
||||
|
||||
[switch]$require_acceptance,
|
||||
|
||||
[switch]$checkin_email,
|
||||
|
||||
[ValidateScript({Test-Path $_})]
|
||||
[string]$image,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$apiKey
|
||||
|
||||
)
|
||||
begin {
|
||||
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
|
||||
|
||||
if ($eula_text -and $use_default_eula) {
|
||||
throw 'Dont use -use_defalt_eula if -eula_text is set'
|
||||
}
|
||||
|
||||
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
|
||||
}
|
||||
|
||||
process {
|
||||
|
||||
$Parameters = @{
|
||||
Api = "/api/v1/categories"
|
||||
Method = 'POST'
|
||||
Body = $Values
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyApiKey -apiKey $apikey
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url) {
|
||||
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyUrl -url $url
|
||||
}
|
||||
|
||||
if ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
}
|
||||
|
||||
$result
|
||||
}
|
||||
|
||||
end {
|
||||
# reset legacy sessions
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url -or $PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Reset-SnipeitPSLegacyApi
|
||||
}
|
||||
}
|
||||
}
|
||||
81
SnipeitPS/Public/New-SnipeitCompany.ps1
Normal file
81
SnipeitPS/Public/New-SnipeitCompany.ps1
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Creates a new Company
|
||||
|
||||
.DESCRIPTION
|
||||
Creates new company on Snipe-It system
|
||||
|
||||
.PARAMETER name
|
||||
Comapany name
|
||||
|
||||
.PARAMETER image
|
||||
Company image filename and path
|
||||
|
||||
.PARAMETER url
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. URL of Snipeit system.
|
||||
|
||||
.PARAMETER apiKey
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. Users API Key API Key for Snipeit.
|
||||
|
||||
.EXAMPLE
|
||||
New-SnipeitCompany -name "Acme Company"
|
||||
|
||||
#>
|
||||
|
||||
function New-SnipeitCompany() {
|
||||
[CmdletBinding(
|
||||
SupportsShouldProcess = $true,
|
||||
ConfirmImpact = "Low"
|
||||
)]
|
||||
|
||||
Param(
|
||||
[parameter(mandatory = $true)]
|
||||
[string]$name,
|
||||
|
||||
[ValidateScript({Test-Path $_})]
|
||||
[string]$image,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$apiKey
|
||||
)
|
||||
begin {
|
||||
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
|
||||
|
||||
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
|
||||
|
||||
$Parameters = @{
|
||||
Api = "/api/v1/companies"
|
||||
Method = 'POST'
|
||||
Body = $Values
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyApiKey -apiKey $apikey
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url) {
|
||||
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyUrl -url $url
|
||||
}
|
||||
}
|
||||
|
||||
process {
|
||||
if ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
}
|
||||
|
||||
$result
|
||||
}
|
||||
|
||||
end {
|
||||
# reset legacy sessions
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url -or $PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Reset-SnipeitPSLegacyApi
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
120
SnipeitPS/Public/New-SnipeitComponent.ps1
Normal file
120
SnipeitPS/Public/New-SnipeitComponent.ps1
Normal file
|
|
@ -0,0 +1,120 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Create a new component
|
||||
|
||||
.DESCRIPTION
|
||||
Createa new componen on Snipe-It system
|
||||
|
||||
.PARAMETER name
|
||||
Component name
|
||||
|
||||
.PARAMETER category_id
|
||||
ID number of category
|
||||
|
||||
.PARAMETER qty
|
||||
Quantity of the components you have
|
||||
|
||||
.PARAMETER location_id
|
||||
ID number of the location the accessory is assigned to
|
||||
|
||||
.PARAMETER order_number
|
||||
Order number of the component
|
||||
|
||||
.PARAMETER purchase_date
|
||||
Date accessory was purchased
|
||||
|
||||
.PARAMETER purchase_cost
|
||||
Cost of item being purchased.
|
||||
|
||||
.PARAMETER image
|
||||
Component image filename and path
|
||||
|
||||
.PARAMETER url
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. URL of Snipeit system.
|
||||
|
||||
.PARAMETER apiKey
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. Users API Key API Key for Snipeit.
|
||||
|
||||
.EXAMPLE
|
||||
New-SnipeitComponent -name 'Display adapter' -catecory_id 3 -qty 10
|
||||
|
||||
|
||||
#>
|
||||
|
||||
function New-SnipeitComponent() {
|
||||
[CmdletBinding(
|
||||
SupportsShouldProcess = $true,
|
||||
ConfirmImpact = "Low"
|
||||
)]
|
||||
|
||||
Param(
|
||||
[parameter(mandatory = $true)]
|
||||
[string]$name,
|
||||
|
||||
[parameter(mandatory = $true)]
|
||||
[int]$category_id,
|
||||
|
||||
[parameter(mandatory = $true)]
|
||||
[string]$qty,
|
||||
|
||||
[int]$company_id,
|
||||
|
||||
[int]$location_id,
|
||||
|
||||
[string]$order_number,
|
||||
|
||||
[datetime]$purchase_date,
|
||||
|
||||
[float]$purchase_cost,
|
||||
|
||||
[ValidateScript({Test-Path $_})]
|
||||
[string]$image,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$apiKey
|
||||
)
|
||||
begin {
|
||||
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
|
||||
|
||||
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
|
||||
|
||||
if ($Values['purchase_date']) {
|
||||
$Values['purchase_date'] = $Values['purchase_date'].ToString("yyyy-MM-dd")
|
||||
}
|
||||
|
||||
$Parameters = @{
|
||||
Api = "/api/v1/components"
|
||||
Method = 'POST'
|
||||
Body = $Values
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyApiKey -apiKey $apikey
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url) {
|
||||
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyUrl -url $url
|
||||
}
|
||||
}
|
||||
|
||||
process {
|
||||
if ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
}
|
||||
|
||||
$result
|
||||
}
|
||||
|
||||
end {
|
||||
# reset legacy sessions
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url -or $PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Reset-SnipeitPSLegacyApi
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
157
SnipeitPS/Public/New-SnipeitConsumable.ps1
Normal file
157
SnipeitPS/Public/New-SnipeitConsumable.ps1
Normal file
|
|
@ -0,0 +1,157 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Add a new Consumable to Snipe-it asset system
|
||||
|
||||
.DESCRIPTION
|
||||
Long description
|
||||
|
||||
.PARAMETER name
|
||||
Required Name of the Consumable
|
||||
|
||||
.PARAMETER qty
|
||||
Required Quantity of comsumable
|
||||
|
||||
.PARAMETER category_id
|
||||
Required Category ID of the Consumable, this can be got using Get-SnipeitCategory
|
||||
|
||||
.PARAMETER min_amt
|
||||
Optional minimum quantity of comsumable
|
||||
|
||||
.PARAMETER company_id
|
||||
Optional Company id
|
||||
|
||||
.PARAMETER order_number
|
||||
Optional Order number
|
||||
|
||||
.PARAMETER manufacturer_id
|
||||
Manufaturer id number of the consumable
|
||||
|
||||
.PARAMETER location_id
|
||||
Location id number of the consumable
|
||||
|
||||
.PARAMETER requestable
|
||||
Is consumable requestable?
|
||||
|
||||
.PARAMETER purchase_date
|
||||
Optional Purchase cost of the consumable
|
||||
|
||||
.PARAMETER purchase_cost
|
||||
Optional Purchase cost of the consumable
|
||||
|
||||
.PARAMETER model_number
|
||||
Model number of the consumable in months
|
||||
|
||||
.PARAMETER item_no
|
||||
Item number for the consumable
|
||||
|
||||
.PARAMETER image
|
||||
Consumable Image filename and path
|
||||
|
||||
.PARAMETER url
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. URL of Snipeit system.
|
||||
|
||||
.PARAMETER apiKey
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. Users API Key for Snipeit.
|
||||
|
||||
|
||||
.EXAMPLE
|
||||
New-Snipeitconsumable -name "Ink pack" -qty 20 -category_id 3 -min_amt 5
|
||||
Create consumable with stock count 20 , alert when stock is 5 or lower
|
||||
|
||||
#>
|
||||
|
||||
function New-SnipeitConsumable() {
|
||||
[CmdletBinding(
|
||||
SupportsShouldProcess = $true,
|
||||
ConfirmImpact = "Low"
|
||||
)]
|
||||
|
||||
Param(
|
||||
[parameter(mandatory = $true)]
|
||||
[string]$name,
|
||||
|
||||
[parameter(mandatory = $true)]
|
||||
[int]$qty,
|
||||
|
||||
[parameter(mandatory = $true)]
|
||||
[int]$category_id,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[int]$min_amt,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[int]$company_id,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$order_number,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[int]$manufacturer_id,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[int]$location_id,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[bool]$requestable,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[datetime]$purchase_date,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$purchase_cost,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$model_number,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$item_no,
|
||||
|
||||
[ValidateScript({Test-Path $_})]
|
||||
[string]$image,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$apiKey
|
||||
|
||||
)
|
||||
begin {
|
||||
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
|
||||
|
||||
if ($Values['purchase_date']) {
|
||||
$Values['purchase_date'] = $Values['purchase_date'].ToString("yyyy-MM-dd")
|
||||
}
|
||||
|
||||
$Parameters = @{
|
||||
Api = "/api/v1/consumables"
|
||||
Method = 'Post'
|
||||
Body = $Values
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyApiKey -apiKey $apikey
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url) {
|
||||
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyUrl -url $url
|
||||
}
|
||||
}
|
||||
|
||||
process {
|
||||
if ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
}
|
||||
|
||||
$result
|
||||
}
|
||||
|
||||
end {
|
||||
# reset legacy sessions
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url -or $PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Reset-SnipeitPSLegacyApi
|
||||
}
|
||||
}
|
||||
}
|
||||
115
SnipeitPS/Public/New-SnipeitCustomField.ps1
Normal file
115
SnipeitPS/Public/New-SnipeitCustomField.ps1
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Add a new Custom Field to Snipe-it asset system
|
||||
|
||||
.DESCRIPTION
|
||||
Add a new Custom Field to Snipe-it asset system
|
||||
|
||||
.PARAMETER name
|
||||
The field's name, which is also the form label
|
||||
|
||||
.PARAMETER element
|
||||
Form field type that should be displayed.
|
||||
|
||||
.PARAMETER field_values
|
||||
In the case of list boxes, etc, this should be a list of the options available
|
||||
|
||||
.PARAMETER show_in_email
|
||||
Whether or not to show the custom field in email notifications
|
||||
|
||||
.PARAMETER format
|
||||
How the field should be validated
|
||||
|
||||
.PARAMETER custom_format
|
||||
In the case of format 'CUSTOM REGEX', this should be validation regex this field
|
||||
|
||||
.PARAMETER field_encrypted
|
||||
Whether the field should be encrypted. (This can cause issues if you change it after the field was created.)
|
||||
|
||||
.PARAMETER help_text
|
||||
Any additional text you wish to display under the new form field to make it clearer what the gauges should be.
|
||||
|
||||
.PARAMETER url
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. URL of Snipeit system.
|
||||
|
||||
.PARAMETER apiKey
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. Users API Key for Snipeit.
|
||||
|
||||
.EXAMPLE
|
||||
New-SnipeitCustomField -Name "AntivirusInstalled" -Format "BOOLEAN" -HelpText "Is AntiVirus installed on Asset"
|
||||
#>
|
||||
|
||||
function New-SnipeitCustomField() {
|
||||
[CmdletBinding(
|
||||
SupportsShouldProcess = $true,
|
||||
ConfirmImpact = "Low"
|
||||
)]
|
||||
|
||||
Param(
|
||||
[parameter(mandatory = $true)]
|
||||
[string]$name,
|
||||
|
||||
[string]$help_text,
|
||||
|
||||
[parameter(mandatory = $true)]
|
||||
[ValidateSet('text','textarea','listbox','checkbox','radio')]
|
||||
[string]$element ,
|
||||
|
||||
[parameter(mandatory = $true)]
|
||||
[ValidateSet('ANY','CUSTOM REGEX','ALPHA','ALPHA-DASH','NUMERIC','ALPHA-NUMERIC','EMAIL','DATE','URL','IP','IPV4','IPV6','MAC','BOOLEAN')]
|
||||
[string]$format,
|
||||
|
||||
[string]$field_values,
|
||||
|
||||
[bool]$field_encrypted=$false,
|
||||
|
||||
[bool]$show_in_email=$false,
|
||||
|
||||
[string]$custom_format,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$apiKey
|
||||
)
|
||||
|
||||
begin {
|
||||
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
|
||||
if ($format -eq 'CUSTOM REGEX' -and (-not $custom_format)) {
|
||||
throw "Please specify regex validation with -custom_format when using -format 'CUSTOM REGEX'"
|
||||
}
|
||||
|
||||
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
|
||||
|
||||
$Parameters = @{
|
||||
Api = "/api/v1/fields"
|
||||
Method = 'post'
|
||||
Body = $Values
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Set-SnipeitPSLegacyApiKey -apiKey $apikey
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url) {
|
||||
Set-SnipeitPSLegacyUrl -url $url
|
||||
}
|
||||
}
|
||||
|
||||
process{
|
||||
if ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
}
|
||||
|
||||
$result
|
||||
}
|
||||
|
||||
end {
|
||||
# reset legacy sessions
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url -or $PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Reset-SnipeitPSLegacyApi
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
100
SnipeitPS/Public/New-SnipeitDepartment.ps1
Normal file
100
SnipeitPS/Public/New-SnipeitDepartment.ps1
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Creates a department
|
||||
|
||||
.DESCRIPTION
|
||||
Creates a new department on Snipe-It system
|
||||
|
||||
.PARAMETER name
|
||||
Department Name
|
||||
|
||||
.PARAMETER company_id
|
||||
ID number of company
|
||||
|
||||
.PARAMETER location_id
|
||||
ID number of location
|
||||
|
||||
.PARAMETER manager_id
|
||||
ID number of manager
|
||||
|
||||
.PARAMETER image
|
||||
Department Image filename and path
|
||||
|
||||
.PARAMETER url
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. URL of Snipeit system.
|
||||
|
||||
.PARAMETER apiKey
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. Users API Key for Snipeit.
|
||||
|
||||
.EXAMPLE
|
||||
New-SnipeitDepartment -name "Department1" -company_id 1 -localtion_id 1 -manager_id 3
|
||||
|
||||
#>
|
||||
|
||||
function New-SnipeitDepartment() {
|
||||
[CmdletBinding(
|
||||
SupportsShouldProcess = $true,
|
||||
ConfirmImpact = "Low"
|
||||
)]
|
||||
|
||||
Param(
|
||||
[parameter(mandatory = $true)]
|
||||
[string]$name,
|
||||
|
||||
[int]$company_id,
|
||||
|
||||
[int]$location_id,
|
||||
|
||||
[int]$manager_id,
|
||||
|
||||
[string]$notes,
|
||||
|
||||
[ValidateScript({Test-Path $_})]
|
||||
[string]$image,
|
||||
|
||||
[switch]$image_delete=$false,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$apiKey
|
||||
)
|
||||
begin {
|
||||
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
|
||||
|
||||
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
|
||||
|
||||
$Parameters = @{
|
||||
Api = "/api/v1/departments"
|
||||
Method = 'POST'
|
||||
Body = $Values
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyApiKey -apiKey $apikey
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url) {
|
||||
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyUrl -url $url
|
||||
}
|
||||
}
|
||||
|
||||
process {
|
||||
if ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
}
|
||||
|
||||
$result
|
||||
}
|
||||
|
||||
end {
|
||||
# reset legacy sessions
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url -or $PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Reset-SnipeitPSLegacyApi
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
174
SnipeitPS/Public/New-SnipeitLicense.ps1
Normal file
174
SnipeitPS/Public/New-SnipeitLicense.ps1
Normal file
|
|
@ -0,0 +1,174 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Creates a licence
|
||||
|
||||
.DESCRIPTION
|
||||
Creates a new licence on Snipe-It system
|
||||
|
||||
.PARAMETER name
|
||||
Name of license being created
|
||||
|
||||
.PARAMETER seats
|
||||
Number of license seats owned.
|
||||
|
||||
.PARAMETER company_id
|
||||
Id number of company license belongs to
|
||||
|
||||
.PARAMETER expiration_date
|
||||
Date of license expiration
|
||||
|
||||
.PARAMETER expiration_date
|
||||
Date of license expiration
|
||||
|
||||
.PARAMETER license_email
|
||||
Email address associated with license
|
||||
|
||||
.PARAMETER license_name
|
||||
Name of license contact person
|
||||
|
||||
.PARAMETER serial
|
||||
Serialnumber of license
|
||||
|
||||
.PARAMETER maintained
|
||||
Maintained status of license
|
||||
|
||||
.PARAMETER manufacturer_id
|
||||
ID number of manufacturer of license.
|
||||
|
||||
.PARAMETER notes
|
||||
License Notes
|
||||
|
||||
.PARAMETER order_number
|
||||
Order number of license purchase
|
||||
|
||||
.PARAMETER purchase_cost
|
||||
Cost of license
|
||||
|
||||
.PARAMETER purchase_date
|
||||
Date of license purchase
|
||||
|
||||
.PARAMETER reassignable
|
||||
Is license reassignable?
|
||||
|
||||
.PARAMETER supplier_id
|
||||
ID number of license supplier
|
||||
|
||||
.PARAMETER termination_date
|
||||
Termination date for license.
|
||||
|
||||
.PARAMETER url
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. URL of Snipeit system.
|
||||
|
||||
.PARAMETER apiKey
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. Users API Key for Snipeit.
|
||||
|
||||
.EXAMPLE
|
||||
New-SnipeitLicence -name "License" -seats 3 -company_id 1
|
||||
|
||||
#>
|
||||
|
||||
function New-SnipeitLicense() {
|
||||
[CmdletBinding(
|
||||
SupportsShouldProcess = $true,
|
||||
ConfirmImpact = "Low"
|
||||
)]
|
||||
|
||||
Param(
|
||||
[parameter(mandatory = $true)]
|
||||
[ValidateLength(3, 255)]
|
||||
[string]$name,
|
||||
|
||||
[parameter(mandatory = $true)]
|
||||
[int]$seats,
|
||||
|
||||
[ValidateRange(1, [int]::MaxValue)]
|
||||
[int]$category_id,
|
||||
|
||||
[ValidateRange(1, [int]::MaxValue)]
|
||||
[int]$company_id,
|
||||
|
||||
[datetime]$expiration_date,
|
||||
|
||||
[ValidateLength(1, 120)]
|
||||
[mailaddress]$license_email,
|
||||
|
||||
[ValidateLength(1, 100)]
|
||||
[string]$license_name,
|
||||
|
||||
[bool]$maintained,
|
||||
|
||||
[ValidateRange(1, [int]::MaxValue)]
|
||||
[int]$manufacturer_id,
|
||||
|
||||
[string]$notes,
|
||||
|
||||
[string]$order_number,
|
||||
|
||||
[float]$purchase_cost,
|
||||
|
||||
[datetime]$purchase_date,
|
||||
|
||||
[bool]$reassignable,
|
||||
|
||||
[string]$serial,
|
||||
|
||||
[ValidateRange(1, [int]::MaxValue)]
|
||||
[int]$supplier_id,
|
||||
|
||||
[datetime]$termination_date,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$apiKey
|
||||
)
|
||||
begin {
|
||||
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
|
||||
|
||||
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
|
||||
|
||||
if ($Values['expiration_date']) {
|
||||
$Values['expiration_date'] = $Values['expiration_date'].ToString("yyyy-MM-dd")
|
||||
}
|
||||
|
||||
if ($Values['purchase_date']) {
|
||||
$Values['purchase_date'] = $Values['purchase_date'].ToString("yyyy-MM-dd")
|
||||
}
|
||||
|
||||
if ($Values['termination_date']) {
|
||||
$Values['termination_date'] = $Values['termination_date'].ToString("yyyy-MM-dd")
|
||||
}
|
||||
|
||||
$Parameters = @{
|
||||
Api = "/api/v1/licenses"
|
||||
Method = 'POST'
|
||||
Body = $Values
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyApiKey -apiKey $apikey
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url) {
|
||||
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyUrl -url $url
|
||||
}
|
||||
}
|
||||
|
||||
process {
|
||||
if ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
}
|
||||
|
||||
$result
|
||||
}
|
||||
end {
|
||||
# reset legacy sessions
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url -or $PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Reset-SnipeitPSLegacyApi
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
132
SnipeitPS/Public/New-SnipeitLocation.ps1
Normal file
132
SnipeitPS/Public/New-SnipeitLocation.ps1
Normal file
|
|
@ -0,0 +1,132 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Add a new Location to Snipe-it asset system
|
||||
|
||||
.DESCRIPTION
|
||||
Long description
|
||||
|
||||
.PARAMETER name
|
||||
Name of the Location
|
||||
|
||||
.PARAMETER address
|
||||
Address line 1 of the location
|
||||
|
||||
.PARAMETER address2
|
||||
Address line 2 of the location
|
||||
|
||||
.PARAMETER state
|
||||
Address State of the location
|
||||
|
||||
.PARAMETER country
|
||||
Country of the location
|
||||
|
||||
.PARAMETER zip
|
||||
The zip code of the location
|
||||
|
||||
.PARAMETER ldap_ou
|
||||
The LDAP OU of the location
|
||||
|
||||
.PARAMETER parent_id
|
||||
Parent location ID for the location
|
||||
|
||||
.PARAMETER currency
|
||||
Currency used at the location
|
||||
|
||||
.PARAMETER city
|
||||
City of the location
|
||||
|
||||
.PARAMETER manager_id
|
||||
The manager ID of the location
|
||||
|
||||
.PARAMETER image
|
||||
Location Image filename and path
|
||||
|
||||
.PARAMETER url
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. URL of Snipeit system.
|
||||
|
||||
.PARAMETER apiKey
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. Users API Key for Snipeit.
|
||||
|
||||
.EXAMPLE
|
||||
New-SnipeitLocation -name "Room 1" -address "123 Asset Street" -parent_id 14
|
||||
#>
|
||||
|
||||
function New-SnipeitLocation() {
|
||||
[CmdletBinding(
|
||||
SupportsShouldProcess = $true,
|
||||
ConfirmImpact = "Low"
|
||||
)]
|
||||
|
||||
Param(
|
||||
[parameter(mandatory = $true)]
|
||||
[string]$name,
|
||||
|
||||
[string]$address,
|
||||
|
||||
[string]$address2,
|
||||
|
||||
[string]$city,
|
||||
|
||||
[string]$state,
|
||||
|
||||
[string]$country,
|
||||
|
||||
[string]$zip,
|
||||
|
||||
[string]$currency,
|
||||
|
||||
[int]$parent_id,
|
||||
|
||||
[int]$manager_id,
|
||||
|
||||
[string]$ldap_ou,
|
||||
|
||||
[ValidateScript({Test-Path $_})]
|
||||
[string]$image,
|
||||
|
||||
[switch]$image_delete=$false,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$apiKey
|
||||
)
|
||||
|
||||
begin {
|
||||
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
|
||||
|
||||
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
|
||||
|
||||
$Parameters = @{
|
||||
Api = "/api/v1/locations"
|
||||
Method = 'post'
|
||||
Body = $Values
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyApiKey -apiKey $apikey
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url) {
|
||||
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyUrl -url $url
|
||||
}
|
||||
}
|
||||
|
||||
process {
|
||||
if ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
}
|
||||
|
||||
$result
|
||||
}
|
||||
|
||||
end {
|
||||
# reset legacy sessions
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url -or $PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Reset-SnipeitPSLegacyApi
|
||||
}
|
||||
}
|
||||
}
|
||||
85
SnipeitPS/Public/New-SnipeitManufacturer.ps1
Normal file
85
SnipeitPS/Public/New-SnipeitManufacturer.ps1
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Add a new Manufacturer to Snipe-it asset system
|
||||
|
||||
.DESCRIPTION
|
||||
Long description
|
||||
|
||||
.PARAMETER Name
|
||||
Name of the Manufacturer
|
||||
|
||||
.PARAMETER image
|
||||
Manufacturer Image filename and path
|
||||
|
||||
.PARAMETER image_delete
|
||||
Remove current image
|
||||
|
||||
.PARAMETER url
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. URL of Snipeit system.
|
||||
|
||||
.PARAMETER apiKey
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. Users API Key for Snipeit.
|
||||
|
||||
.EXAMPLE
|
||||
New-SnipeitManufacturer -name "HP"
|
||||
#>
|
||||
|
||||
function New-SnipeitManufacturer() {
|
||||
[CmdletBinding(
|
||||
SupportsShouldProcess = $true,
|
||||
ConfirmImpact = "Low"
|
||||
)]
|
||||
|
||||
Param(
|
||||
[parameter(mandatory = $true)]
|
||||
[string]$Name,
|
||||
|
||||
[ValidateScript({Test-Path $_})]
|
||||
[string]$image,
|
||||
|
||||
[switch]$image_delete=$false,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$apiKey
|
||||
)
|
||||
|
||||
begin {
|
||||
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
|
||||
|
||||
$Values = @{
|
||||
"name" = $Name
|
||||
}
|
||||
|
||||
$Parameters = @{
|
||||
Api = "/api/v1/manufacturers"
|
||||
Method = 'post'
|
||||
Body = $Values
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyApiKey -apiKey $apikey
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url) {
|
||||
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyUrl -url $url
|
||||
}
|
||||
}
|
||||
process {
|
||||
if ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
}
|
||||
|
||||
$result
|
||||
}
|
||||
end {
|
||||
# reset legacy sessions
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url -or $PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Reset-SnipeitPSLegacyApi
|
||||
}
|
||||
}
|
||||
}
|
||||
114
SnipeitPS/Public/New-SnipeitModel.ps1
Normal file
114
SnipeitPS/Public/New-SnipeitModel.ps1
Normal file
|
|
@ -0,0 +1,114 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Add a new Model to Snipe-it asset system
|
||||
|
||||
.DESCRIPTION
|
||||
Long description
|
||||
|
||||
.PARAMETER name
|
||||
Name of the Asset Model
|
||||
|
||||
.PARAMETER model_number
|
||||
Model number 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 image
|
||||
Asset model Image filename and path
|
||||
|
||||
.PARAMETER url
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. URL of Snipeit system.
|
||||
|
||||
.PARAMETER apiKey
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. Users API Key for Snipeit.
|
||||
|
||||
.EXAMPLE
|
||||
New-SnipeitModel -name "DL380" -manufacturer_id 2 -fieldset_id 2 -category_id 1
|
||||
#>
|
||||
|
||||
function New-SnipeitModel() {
|
||||
[CmdletBinding(
|
||||
SupportsShouldProcess = $true,
|
||||
ConfirmImpact = "Low"
|
||||
)]
|
||||
|
||||
Param(
|
||||
[parameter(mandatory = $true)]
|
||||
[string]$name,
|
||||
|
||||
[string]$model_number,
|
||||
|
||||
[parameter(mandatory = $true)]
|
||||
[int]$category_id,
|
||||
|
||||
[parameter(mandatory = $true)]
|
||||
[int]$manufacturer_id,
|
||||
|
||||
[int]$eol,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[int]$fieldset_id,
|
||||
|
||||
[ValidateScript({Test-Path $_})]
|
||||
[string]$image,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$apiKey
|
||||
)
|
||||
|
||||
begin {
|
||||
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
|
||||
|
||||
$Values = @{
|
||||
name = $name
|
||||
category_id = $category_id
|
||||
manufacturer_id = $manufacturer_id
|
||||
fieldset_id = $fieldset_id
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('model_number')) { $Values.Add("model_number", $model_number) }
|
||||
if ($PSBoundParameters.ContainsKey('eol')) { $Values.Add("eol", $eol) }
|
||||
|
||||
|
||||
$Parameters = @{
|
||||
Api = "/api/v1/models"
|
||||
Method = 'post'
|
||||
Body = $Values
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyApiKey -apiKey $apikey
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url) {
|
||||
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyUrl -url $url
|
||||
}
|
||||
}
|
||||
|
||||
process {
|
||||
if ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
}
|
||||
|
||||
$result
|
||||
}
|
||||
|
||||
end {
|
||||
# reset legacy sessions
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url -or $PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Reset-SnipeitPSLegacyApi
|
||||
}
|
||||
}
|
||||
}
|
||||
136
SnipeitPS/Public/New-SnipeitSupplier.ps1
Normal file
136
SnipeitPS/Public/New-SnipeitSupplier.ps1
Normal file
|
|
@ -0,0 +1,136 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Creates a supplier
|
||||
|
||||
.DESCRIPTION
|
||||
Creates a new supplier on Snipe-It system
|
||||
|
||||
.PARAMETER name
|
||||
Department Name
|
||||
|
||||
.PARAMETER address
|
||||
Address line 1 of supplier
|
||||
|
||||
.PARAMETER address2
|
||||
Address line 1 of supplier
|
||||
|
||||
.PARAMETER city
|
||||
City
|
||||
|
||||
.PARAMETER state
|
||||
State
|
||||
|
||||
.PARAMETER country
|
||||
Country
|
||||
|
||||
.PARAMETER zip
|
||||
Zip code
|
||||
|
||||
.PARAMETER phone
|
||||
Phone number
|
||||
|
||||
.PARAMETER fax
|
||||
Fax number
|
||||
|
||||
.PARAMETER email
|
||||
Email address
|
||||
|
||||
.PARAMETER contact
|
||||
Contact person
|
||||
|
||||
.PARAMETER notes
|
||||
Email address
|
||||
|
||||
.PARAMETER image
|
||||
Image file name and path for item
|
||||
|
||||
.PARAMETER url
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. URL of Snipeit system.
|
||||
|
||||
.PARAMETER apiKey
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. Users API Key for Snipeit.
|
||||
|
||||
.EXAMPLE
|
||||
New-SnipeitDepartment -name "Department1" -company_id 1 -localtion_id 1 -manager_id 3
|
||||
|
||||
#>
|
||||
|
||||
function New-SnipeitSupplier() {
|
||||
[CmdletBinding(
|
||||
SupportsShouldProcess = $true,
|
||||
ConfirmImpact = "Low"
|
||||
)]
|
||||
|
||||
Param(
|
||||
[parameter(mandatory = $true)]
|
||||
[string]$name,
|
||||
|
||||
[string]$address,
|
||||
|
||||
[string]$address2,
|
||||
|
||||
[string]$city,
|
||||
|
||||
[string]$state,
|
||||
|
||||
[string]$country,
|
||||
|
||||
[string]$zip,
|
||||
|
||||
[string]$phone,
|
||||
|
||||
[string]$fax,
|
||||
|
||||
[string]$email,
|
||||
|
||||
[string]$contact,
|
||||
|
||||
[string]$notes,
|
||||
|
||||
[ValidateScript({Test-Path $_})]
|
||||
[string]$image,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$apiKey
|
||||
)
|
||||
begin {
|
||||
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
|
||||
|
||||
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
|
||||
|
||||
$Parameters = @{
|
||||
Api = "/api/v1/suppilers"
|
||||
Method = 'POST'
|
||||
Body = $Values
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyApiKey -apiKey $apikey
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url) {
|
||||
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyUrl -url $url
|
||||
}
|
||||
}
|
||||
|
||||
process {
|
||||
if ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
}
|
||||
|
||||
$result
|
||||
}
|
||||
|
||||
end {
|
||||
# reset legacy sessions
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url -or $PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Reset-SnipeitPSLegacyApi
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
164
SnipeitPS/Public/New-SnipeitUser.ps1
Normal file
164
SnipeitPS/Public/New-SnipeitUser.ps1
Normal file
|
|
@ -0,0 +1,164 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Creates a new user
|
||||
|
||||
.DESCRIPTION
|
||||
Creates a new user to Snipe-IT system
|
||||
|
||||
.PARAMETER first_name
|
||||
Users first name
|
||||
|
||||
.PARAMETER last_name
|
||||
Users last name
|
||||
|
||||
.PARAMETER username
|
||||
Username for user
|
||||
|
||||
.PARAMETER active
|
||||
Can user log in to snipe-it?
|
||||
|
||||
.PARAMETER password
|
||||
Password for user
|
||||
|
||||
.PARAMETER notes
|
||||
User Notes
|
||||
|
||||
.PARAMETER jobtitle
|
||||
Users job tittle
|
||||
|
||||
.PARAMETER email
|
||||
email address
|
||||
|
||||
.PARAMETER phone
|
||||
Phone number
|
||||
|
||||
.PARAMETER company_id
|
||||
ID number of company users belogs to
|
||||
|
||||
.PARAMETER location_id
|
||||
ID number of localtion
|
||||
|
||||
.PARAMETER department_id
|
||||
ID number of department
|
||||
|
||||
.PARAMETER manager_id
|
||||
ID number of manager
|
||||
|
||||
.PARAMETER groups
|
||||
ID numbers of groups
|
||||
|
||||
.PARAMETER employee_num
|
||||
Employeenumber
|
||||
|
||||
.PARAMETER ldap_import
|
||||
Mark user as import from ldap
|
||||
|
||||
.PARAMETER image
|
||||
User Image file name and path
|
||||
|
||||
.PARAMETER url
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. URL of Snipeit system.
|
||||
|
||||
.PARAMETER apiKey
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. User's API Key for Snipeit.
|
||||
|
||||
.EXAMPLE
|
||||
New-Snipeituser -fist_name It -lastname Snipe -username snipeit -activated $false -company_id 1 -location_id 1 -department_id 1
|
||||
Creates new a new user who can't login to system
|
||||
|
||||
.NOTES
|
||||
General notes
|
||||
#>
|
||||
function New-SnipeitUser() {
|
||||
|
||||
[CmdletBinding(
|
||||
SupportsShouldProcess = $true,
|
||||
ConfirmImpact = "Low"
|
||||
)]
|
||||
|
||||
Param(
|
||||
[parameter(mandatory = $true)]
|
||||
[string]$first_name,
|
||||
|
||||
[parameter(mandatory = $true)]
|
||||
[string]$last_name,
|
||||
|
||||
[parameter(mandatory = $true)]
|
||||
[string]$username,
|
||||
|
||||
[string]$password,
|
||||
|
||||
[bool]$activated = $false,
|
||||
|
||||
[string]$notes,
|
||||
|
||||
[string]$jobtitle,
|
||||
|
||||
[string]$email,
|
||||
|
||||
[string]$phone,
|
||||
|
||||
[int]$company_id,
|
||||
|
||||
[int]$location_id,
|
||||
|
||||
[int]$department_id,
|
||||
|
||||
[int]$manager_id,
|
||||
|
||||
[int[]]$groups,
|
||||
|
||||
[string]$employee_num,
|
||||
|
||||
[bool]$ldap_import = $false,
|
||||
|
||||
[ValidateScript({Test-Path $_})]
|
||||
[string]$image,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$apiKey
|
||||
)
|
||||
begin {
|
||||
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
|
||||
|
||||
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
|
||||
|
||||
if ($password ) {
|
||||
$Values['password_confirmation'] = $password
|
||||
}
|
||||
|
||||
$Parameters = @{
|
||||
Api = "/api/v1/users"
|
||||
Method = 'post'
|
||||
Body = $Values
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyApiKey -apiKey $apikey
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url) {
|
||||
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyUrl -url $url
|
||||
}
|
||||
}
|
||||
|
||||
process {
|
||||
if ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
}
|
||||
|
||||
$result
|
||||
}
|
||||
|
||||
end {
|
||||
# reset legacy sessions
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url -or $PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Reset-SnipeitPSLegacyApi
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,145 +0,0 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Short description
|
||||
|
||||
.DESCRIPTION
|
||||
Long description
|
||||
|
||||
.PARAMETER firstName
|
||||
Parameter description
|
||||
|
||||
.PARAMETER lastName
|
||||
Parameter description
|
||||
|
||||
.PARAMETER userName
|
||||
Parameter description
|
||||
|
||||
.PARAMETER jobTitle
|
||||
Parameter description
|
||||
|
||||
.PARAMETER email
|
||||
Parameter description
|
||||
|
||||
.PARAMETER phone
|
||||
Parameter description
|
||||
|
||||
.PARAMETER company_id
|
||||
Parameter description
|
||||
|
||||
.PARAMETER location_id
|
||||
Parameter description
|
||||
|
||||
.PARAMETER department_id
|
||||
Parameter description
|
||||
|
||||
.PARAMETER manager_id
|
||||
Parameter description
|
||||
|
||||
.PARAMETER employee_num
|
||||
Parameter description
|
||||
|
||||
.PARAMETER ldap_user
|
||||
Parameter description
|
||||
|
||||
.PARAMETER url
|
||||
Parameter description
|
||||
|
||||
.PARAMETER apiKey
|
||||
Parameter description
|
||||
|
||||
.EXAMPLE
|
||||
An example
|
||||
|
||||
.NOTES
|
||||
General notes
|
||||
#>
|
||||
function New-User() {
|
||||
|
||||
[CmdletBinding(
|
||||
SupportsShouldProcess = $true,
|
||||
ConfirmImpact = "Low"
|
||||
)]
|
||||
|
||||
Param(
|
||||
[parameter(mandatory = $true)]
|
||||
[string]$firstName,
|
||||
|
||||
[parameter(mandatory = $true)]
|
||||
[string]$lastName,
|
||||
|
||||
[parameter(mandatory = $true)]
|
||||
[string]$userName,
|
||||
|
||||
[string]$password,
|
||||
|
||||
[string]$jobTitle,
|
||||
|
||||
[string]$email,
|
||||
|
||||
[string]$phone,
|
||||
|
||||
[int]$company_id,
|
||||
|
||||
[int]$location_id,
|
||||
|
||||
[int]$department_id,
|
||||
|
||||
[int]$manager_id,
|
||||
|
||||
[string]$employee_num,
|
||||
|
||||
[bool]$ldap_user = $false,
|
||||
|
||||
[parameter(mandatory = $true)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $true)]
|
||||
[string]$apiKey
|
||||
)
|
||||
|
||||
$Values = @{
|
||||
first_name = $firstName
|
||||
last_name = $lastName
|
||||
username = $userName
|
||||
|
||||
email = $email
|
||||
phone = $phone
|
||||
company_id = $company_id
|
||||
location_id = $location_id
|
||||
department_id = $department_id
|
||||
manager_id = $manager_id
|
||||
jobtitle = $jobTitle
|
||||
employee_num = $employee_num
|
||||
notes = "Imported using SnipeitPS Script"
|
||||
activated = 1
|
||||
}
|
||||
|
||||
if ($ldap_user -eq $false) {
|
||||
$ldap = @{
|
||||
password = $password
|
||||
ldap_import = 0
|
||||
}
|
||||
$Values += $ldap
|
||||
}
|
||||
else {
|
||||
$ldap = @{
|
||||
ldap_import = 1
|
||||
}
|
||||
$Values += $ldap
|
||||
}
|
||||
|
||||
$Body = $Values | ConvertTo-Json;
|
||||
|
||||
$Parameters = @{
|
||||
Uri = "$url/api/v1/users"
|
||||
Method = 'post'
|
||||
Body = $Body
|
||||
Token = $apiKey
|
||||
}
|
||||
|
||||
If ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
}
|
||||
|
||||
$result
|
||||
}
|
||||
72
SnipeitPS/Public/Remove-SnipeitAccessory.ps1
Normal file
72
SnipeitPS/Public/Remove-SnipeitAccessory.ps1
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Removes Accessory from Snipe-it asset system
|
||||
.DESCRIPTION
|
||||
Removes Accessory or multiple Accessoriers from Snipe-it asset system
|
||||
.PARAMETER ID
|
||||
Unique ID For accessory to be removed
|
||||
.PARAMETER url
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. URL of Snipeit system.
|
||||
|
||||
.PARAMETER apiKey
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. User's API Key for Snipeit.
|
||||
|
||||
.EXAMPLE
|
||||
Remove-SnipeitAccessory -ID 44 -Verbose
|
||||
|
||||
.EXAMPLE
|
||||
Get-SnipeitAccessory -search needle | Remove-SnipeitAccessory
|
||||
#>
|
||||
|
||||
function Remove-SnipeitAccessory () {
|
||||
[CmdletBinding(
|
||||
SupportsShouldProcess = $true,
|
||||
ConfirmImpact = "Low"
|
||||
)]
|
||||
|
||||
Param(
|
||||
[parameter(mandatory = $true,ValueFromPipelineByPropertyName)]
|
||||
[int[]]$id,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$apiKey
|
||||
)
|
||||
|
||||
begin {
|
||||
}
|
||||
|
||||
process {
|
||||
foreach($accessory_id in $id) {
|
||||
$Parameters = @{
|
||||
Api = "/api/v1/accessories/$accessory_id"
|
||||
Method = 'Delete'
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyApiKey -apiKey $apikey
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url) {
|
||||
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyUrl -url $url
|
||||
}
|
||||
|
||||
if ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
}
|
||||
|
||||
$result
|
||||
}
|
||||
}
|
||||
|
||||
end {
|
||||
# reset legacy sessions
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url -or $PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Reset-SnipeitPSLegacyApi
|
||||
}
|
||||
}
|
||||
}
|
||||
73
SnipeitPS/Public/Remove-SnipeitAsset.ps1
Normal file
73
SnipeitPS/Public/Remove-SnipeitAsset.ps1
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Removes Asset from Snipe-it asset system
|
||||
.DESCRIPTION
|
||||
Removes asset or multiple assets from Snipe-it asset system
|
||||
.PARAMETER ID
|
||||
Unique ID For Asset to be removed
|
||||
.PARAMETER url
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. URL of Snipeit system.
|
||||
|
||||
.PARAMETER apiKey
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. User's API Key for Snipeit.
|
||||
|
||||
.EXAMPLE
|
||||
Remove-SnipeitAsset -ID 44 -Verbose
|
||||
|
||||
.EXAMPLE
|
||||
Get-SnipeitAsset -serial 123456789 | Remove-SnipeitAsset
|
||||
#>
|
||||
|
||||
function Remove-SnipeitAsset () {
|
||||
[CmdletBinding(
|
||||
SupportsShouldProcess = $true,
|
||||
ConfirmImpact = "Low"
|
||||
)]
|
||||
|
||||
Param(
|
||||
[parameter(mandatory = $true,ValueFromPipelineByPropertyName)]
|
||||
[int[]]$id,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$apiKey
|
||||
)
|
||||
|
||||
begin {
|
||||
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
|
||||
}
|
||||
|
||||
process {
|
||||
foreach($asset_id in $id) {
|
||||
$Parameters = @{
|
||||
Api = "/api/v1/hardware/$asset_id"
|
||||
Method = 'Delete'
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyApiKey -apiKey $apikey
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url) {
|
||||
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyUrl -url $url
|
||||
}
|
||||
|
||||
if ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
}
|
||||
|
||||
$result
|
||||
}
|
||||
}
|
||||
|
||||
end {
|
||||
# reset legacy sessions
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url -or $PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Reset-SnipeitPSLegacyApi
|
||||
}
|
||||
}
|
||||
}
|
||||
72
SnipeitPS/Public/Remove-SnipeitAssetMaintenance.ps1
Normal file
72
SnipeitPS/Public/Remove-SnipeitAssetMaintenance.ps1
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Remove asset maintenance from Snipe-it asset system
|
||||
|
||||
.DESCRIPTION
|
||||
Removes asset maintenance event or events from Snipe-it asset system by ID
|
||||
|
||||
.PARAMETER ID
|
||||
Unique ID of the asset maintenance to be removed
|
||||
|
||||
.PARAMETER url
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. URL of Snipeit system.
|
||||
.PARAMETER url
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. User's API Key for Snipeit.
|
||||
|
||||
.EXAMPLE
|
||||
Remove-SnipeitAssetMaintenance -ID 44
|
||||
#>
|
||||
function Remove-SnipeitAssetMaintenance {
|
||||
|
||||
[CmdletBinding(
|
||||
SupportsShouldProcess = $true,
|
||||
ConfirmImpact = "Low"
|
||||
)]
|
||||
param (
|
||||
[Parameter(Mandatory = $true,ValueFromPipelineByPropertyName)]
|
||||
[int[]]
|
||||
$id,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$apiKey
|
||||
)
|
||||
|
||||
begin {
|
||||
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
|
||||
}
|
||||
|
||||
process {
|
||||
foreach($maintenance_id in $id) {
|
||||
$Parameters = @{
|
||||
Api = "/api/v1/maintenances/$maintenance_id"
|
||||
Method = 'Delete'
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyApiKey -apiKey $apikey
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url) {
|
||||
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyUrl -url $url
|
||||
}
|
||||
|
||||
if ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
}
|
||||
|
||||
$result
|
||||
}
|
||||
}
|
||||
|
||||
end {
|
||||
# reset legacy sessions
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url -or $PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Reset-SnipeitPSLegacyApi
|
||||
}
|
||||
}
|
||||
}
|
||||
71
SnipeitPS/Public/Remove-SnipeitCategory.ps1
Normal file
71
SnipeitPS/Public/Remove-SnipeitCategory.ps1
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Removes category from Snipe-it asset system
|
||||
.DESCRIPTION
|
||||
Removes category or multiple categories from Snipe-it asset system
|
||||
.PARAMETER ID
|
||||
Unique ID For categoryto be removed
|
||||
.PARAMETER url
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. URL of Snipeit system.
|
||||
|
||||
.PARAMETER apiKey
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. User's API Key for Snipeit.
|
||||
|
||||
.EXAMPLE
|
||||
Remove-SnipeitCategory -ID 44
|
||||
|
||||
.EXAMPLE
|
||||
Get-SnipeitCategory -search something | Remove-SnipeitCategory
|
||||
#>
|
||||
|
||||
function Remove-SnipeitCategory () {
|
||||
[CmdletBinding(
|
||||
SupportsShouldProcess = $true,
|
||||
ConfirmImpact = "Low"
|
||||
)]
|
||||
|
||||
Param(
|
||||
[parameter(mandatory = $true,ValueFromPipelineByPropertyName)]
|
||||
[int[]]$id,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$apiKey
|
||||
|
||||
)
|
||||
begin {
|
||||
}
|
||||
process {
|
||||
foreach($category_id in $id) {
|
||||
$Parameters = @{
|
||||
Api = "/api/v1/categories/$category_id"
|
||||
Method = 'Delete'
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyApiKey -apiKey $apikey
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url) {
|
||||
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyUrl -url $url
|
||||
}
|
||||
|
||||
if ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
}
|
||||
|
||||
$result
|
||||
}
|
||||
}
|
||||
|
||||
end {
|
||||
# reset legacy sessions
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url -or $PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Reset-SnipeitPSLegacyApi
|
||||
}
|
||||
}
|
||||
}
|
||||
71
SnipeitPS/Public/Remove-SnipeitCompany.ps1
Normal file
71
SnipeitPS/Public/Remove-SnipeitCompany.ps1
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Removes Company from Snipe-it asset system
|
||||
.DESCRIPTION
|
||||
Removes Company or multiple Companies from Snipe-it asset system
|
||||
.PARAMETER ID
|
||||
Unique ID For Company to be removed
|
||||
.PARAMETER url
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. URL of Snipeit system.
|
||||
|
||||
.PARAMETER apiKey
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. User's API Key for Snipeit.
|
||||
|
||||
.EXAMPLE
|
||||
Remove-SnipeitCompany -ID 44
|
||||
|
||||
.EXAMPLE
|
||||
Get-SnipeitCompany | | Where-object {$_.name -like '*some*'} | Remove-SnipeitCompany
|
||||
#>
|
||||
|
||||
function Remove-SnipeitCompany () {
|
||||
[CmdletBinding(
|
||||
SupportsShouldProcess = $true,
|
||||
ConfirmImpact = "Low"
|
||||
)]
|
||||
|
||||
Param(
|
||||
[parameter(mandatory = $true,ValueFromPipelineByPropertyName)]
|
||||
[int[]]$id,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$apiKey
|
||||
|
||||
)
|
||||
begin {
|
||||
}
|
||||
process {
|
||||
foreach($company_id in $id) {
|
||||
$Parameters = @{
|
||||
Api = "/api/v1/companies/$company_id"
|
||||
Method = 'Delete'
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyApiKey -apiKey $apikey
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url) {
|
||||
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyUrl -url $url
|
||||
}
|
||||
|
||||
if ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
}
|
||||
|
||||
$result
|
||||
}
|
||||
}
|
||||
|
||||
end {
|
||||
# reset legacy sessions
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url -or $PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Reset-SnipeitPSLegacyApi
|
||||
}
|
||||
}
|
||||
}
|
||||
72
SnipeitPS/Public/Remove-SnipeitComponent.ps1
Normal file
72
SnipeitPS/Public/Remove-SnipeitComponent.ps1
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Removes component from Snipe-it asset system
|
||||
.DESCRIPTION
|
||||
Removes component or multiple components from Snipe-it asset system
|
||||
.PARAMETER IDs
|
||||
Unique ID For component to be removed
|
||||
.PARAMETER url
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. URL of Snipeit system.
|
||||
|
||||
.PARAMETER apiKey
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. User's API Key for Snipeit.
|
||||
|
||||
.EXAMPLE
|
||||
Remove-SnipeitComponent -ID 44
|
||||
|
||||
.EXAMPLE
|
||||
Get-SnipeitComponent -search 123456789 | Remove-SnipeitComponent
|
||||
#>
|
||||
|
||||
function Remove-SnipeitComponent () {
|
||||
[CmdletBinding(
|
||||
SupportsShouldProcess = $true,
|
||||
ConfirmImpact = "Low"
|
||||
)]
|
||||
|
||||
Param(
|
||||
[parameter(mandatory = $true,ValueFromPipelineByPropertyName)]
|
||||
[int[]]$id,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$apiKey
|
||||
)
|
||||
|
||||
begin {
|
||||
}
|
||||
|
||||
process {
|
||||
foreach($component_id in $id) {
|
||||
$Parameters = @{
|
||||
Api = "/api/v1/components/$component_id"
|
||||
Method = 'Delete'
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyApiKey -apiKey $apikey
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url) {
|
||||
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyUrl -url $url
|
||||
}
|
||||
|
||||
if ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
}
|
||||
|
||||
$result
|
||||
}
|
||||
}
|
||||
|
||||
end {
|
||||
# reset legacy sessions
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url -or $PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Reset-SnipeitPSLegacyApi
|
||||
}
|
||||
}
|
||||
}
|
||||
73
SnipeitPS/Public/Remove-SnipeitConsumable.ps1
Normal file
73
SnipeitPS/Public/Remove-SnipeitConsumable.ps1
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Removes consumable from Snipe-it asset system
|
||||
.DESCRIPTION
|
||||
Removes consumable or multiple consumables from Snipe-it asset system
|
||||
.PARAMETER ID
|
||||
Unique ID For consumable to be removed
|
||||
|
||||
.PARAMETER url
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. URL of Snipeit system.
|
||||
|
||||
.PARAMETER apiKey
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. User's API Key for Snipeit.
|
||||
|
||||
.EXAMPLE
|
||||
Remove-SnipeitConsumable -ID 44
|
||||
|
||||
.EXAMPLE
|
||||
Get-SnipeitConsumable -search "paper" | Remove-SnipeitConsumable
|
||||
#>
|
||||
|
||||
function Remove-SnipeitConsumable () {
|
||||
[CmdletBinding(
|
||||
SupportsShouldProcess = $true,
|
||||
ConfirmImpact = "Low"
|
||||
)]
|
||||
|
||||
Param(
|
||||
[parameter(mandatory = $true,ValueFromPipelineByPropertyName)]
|
||||
[int[]]$id,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$apiKey
|
||||
)
|
||||
|
||||
begin {
|
||||
}
|
||||
|
||||
process {
|
||||
foreach($consumable_id in $id) {
|
||||
$Parameters = @{
|
||||
Api = "/api/v1/consumables/$consumable_id"
|
||||
Method = 'Delete'
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyApiKey -apiKey $apikey
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url) {
|
||||
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyUrl -url $url
|
||||
}
|
||||
|
||||
if ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
}
|
||||
|
||||
$result
|
||||
}
|
||||
}
|
||||
|
||||
end {
|
||||
# reset legacy sessions
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url -or $PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Reset-SnipeitPSLegacyApi
|
||||
}
|
||||
}
|
||||
}
|
||||
70
SnipeitPS/Public/Remove-SnipeitCustomField.ps1
Normal file
70
SnipeitPS/Public/Remove-SnipeitCustomField.ps1
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Removes custom field from Snipe-it asset system
|
||||
.DESCRIPTION
|
||||
Removes custom field or multiple fields from Snipe-it asset system
|
||||
.PARAMETER ID
|
||||
Unique ID For field to be removed
|
||||
.PARAMETER url
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. URL of Snipeit system.
|
||||
|
||||
.PARAMETER apiKey
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. User's API Key for Snipeit.
|
||||
|
||||
.EXAMPLE
|
||||
Remove-SnipeitCustomField -ID 44 -Verbose
|
||||
|
||||
.EXAMPLE
|
||||
Get-SnipeitCustomField | Where-object {$_.name -like '*address*'} | Remove-SnipeitCustomField
|
||||
#>
|
||||
|
||||
function Remove-SnipeitCustomField () {
|
||||
[CmdletBinding(
|
||||
SupportsShouldProcess = $true,
|
||||
ConfirmImpact = "Low"
|
||||
)]
|
||||
|
||||
Param(
|
||||
[parameter(mandatory = $true,ValueFromPipelineByPropertyName)]
|
||||
[int[]]$id,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$apiKey
|
||||
)
|
||||
begin {
|
||||
}
|
||||
process {
|
||||
foreach($field_id in $id) {
|
||||
$Parameters = @{
|
||||
Api = "/api/v1/fields/$field_id"
|
||||
Method = 'Delete'
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyApiKey -apiKey $apikey
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url) {
|
||||
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyUrl -url $url
|
||||
}
|
||||
|
||||
if ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
}
|
||||
|
||||
$result
|
||||
}
|
||||
}
|
||||
|
||||
end {
|
||||
# reset legacy sessions
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url -or $PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Reset-SnipeitPSLegacyApi
|
||||
}
|
||||
}
|
||||
}
|
||||
71
SnipeitPS/Public/Remove-SnipeitDepartment.ps1
Normal file
71
SnipeitPS/Public/Remove-SnipeitDepartment.ps1
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Removes department from Snipe-it asset system
|
||||
.DESCRIPTION
|
||||
Removes department or multiple departments from Snipe-it asset system
|
||||
.PARAMETER ID
|
||||
Unique ID For department to be removed
|
||||
.PARAMETER url
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. URL of Snipeit system.
|
||||
|
||||
.PARAMETER apiKey
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. User's API Key for Snipeit.
|
||||
|
||||
.EXAMPLE
|
||||
Remove-SnipeitDepartment -ID 44
|
||||
|
||||
.EXAMPLE
|
||||
Get-SnipeitDepartment | Where-object {$_.name -like '*head*'} | Remove-SnipeitDepartment
|
||||
#>
|
||||
|
||||
function Remove-SnipeitDepartment () {
|
||||
[CmdletBinding(
|
||||
SupportsShouldProcess = $true,
|
||||
ConfirmImpact = "Low"
|
||||
)]
|
||||
|
||||
Param(
|
||||
[parameter(mandatory = $true,ValueFromPipelineByPropertyName)]
|
||||
[int[]]$id,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$apiKey
|
||||
|
||||
)
|
||||
begin {
|
||||
}
|
||||
process {
|
||||
foreach($department_id in $id) {
|
||||
$Parameters = @{
|
||||
Api = "/api/v1/departments/$department_id"
|
||||
Method = 'Delete'
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyApiKey -apiKey $apikey
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url) {
|
||||
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyUrl -url $url
|
||||
}
|
||||
|
||||
if ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
}
|
||||
|
||||
$result
|
||||
}
|
||||
}
|
||||
|
||||
end {
|
||||
# reset legacy sessions
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url -or $PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Reset-SnipeitPSLegacyApi
|
||||
}
|
||||
}
|
||||
}
|
||||
72
SnipeitPS/Public/Remove-SnipeitLicense.ps1
Normal file
72
SnipeitPS/Public/Remove-SnipeitLicense.ps1
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Removes licence from Snipe-it asset system
|
||||
.DESCRIPTION
|
||||
Removes licence or multiple licenses from Snipe-it asset system
|
||||
.PARAMETER ID
|
||||
Unique ID For licence to be removed
|
||||
.PARAMETER url
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. URL of Snipeit system.
|
||||
|
||||
.PARAMETER apiKey
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. User's API Key for Snipeit.
|
||||
|
||||
.EXAMPLE
|
||||
Remove-SnipeitLicence -ID 44
|
||||
|
||||
.EXAMPLE
|
||||
Get-SnipeitLicence -product_key 123456789 | Remove-SnipeitLicense
|
||||
#>
|
||||
|
||||
function Remove-SnipeitLicense () {
|
||||
[CmdletBinding(
|
||||
SupportsShouldProcess = $true,
|
||||
ConfirmImpact = "Low"
|
||||
)]
|
||||
|
||||
Param(
|
||||
[parameter(mandatory = $true,ValueFromPipelineByPropertyName)]
|
||||
[int[]]$id,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$apiKey
|
||||
)
|
||||
|
||||
begin {
|
||||
}
|
||||
|
||||
process {
|
||||
foreach($license_id in $id) {
|
||||
$Parameters = @{
|
||||
Api = "/api/v1/licenses/$license_id"
|
||||
Method = 'Delete'
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyApiKey -apiKey $apikey
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url) {
|
||||
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyUrl -url $url
|
||||
}
|
||||
|
||||
if ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
}
|
||||
|
||||
$result
|
||||
}
|
||||
}
|
||||
|
||||
end {
|
||||
# reset legacy sessions
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url -or $PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Reset-SnipeitPSLegacyApi
|
||||
}
|
||||
}
|
||||
}
|
||||
72
SnipeitPS/Public/Remove-SnipeitLocation.ps1
Normal file
72
SnipeitPS/Public/Remove-SnipeitLocation.ps1
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Removes Location from Snipe-it asset system
|
||||
.DESCRIPTION
|
||||
Removes localtion or multiple locations from Snipe-it asset system
|
||||
.PARAMETER ID
|
||||
Unique ID For location to be removed
|
||||
.PARAMETER url
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. URL of Snipeit system.
|
||||
|
||||
.PARAMETER apiKey
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. User's API Key for Snipeit.
|
||||
|
||||
.EXAMPLE
|
||||
Remove-SnipeitLocation -ID 44
|
||||
|
||||
.EXAMPLE
|
||||
Get-SnipeitLocation -city Arkham | Remove-SnipeitLocation
|
||||
#>
|
||||
|
||||
function Remove-SnipeitLocation () {
|
||||
[CmdletBinding(
|
||||
SupportsShouldProcess = $true,
|
||||
ConfirmImpact = "Low"
|
||||
)]
|
||||
|
||||
Param(
|
||||
[parameter(mandatory = $true,ValueFromPipelineByPropertyName)]
|
||||
[int[]]$id,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$apiKey
|
||||
)
|
||||
|
||||
begin {
|
||||
}
|
||||
|
||||
process {
|
||||
foreach($location_id in $id) {
|
||||
$Parameters = @{
|
||||
Api = "/api/v1/locations/$asset_id"
|
||||
Method = 'Delete'
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyApiKey -apiKey $apikey
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url) {
|
||||
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyUrl -url $url
|
||||
}
|
||||
|
||||
if ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
}
|
||||
|
||||
$result
|
||||
}
|
||||
}
|
||||
|
||||
end {
|
||||
# reset legacy sessions
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url -or $PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Reset-SnipeitPSLegacyApi
|
||||
}
|
||||
}
|
||||
}
|
||||
73
SnipeitPS/Public/Remove-SnipeitManufacturer.ps1
Normal file
73
SnipeitPS/Public/Remove-SnipeitManufacturer.ps1
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Removes manufacturer from Snipe-it asset system
|
||||
.DESCRIPTION
|
||||
Removes manufacturer or multiple manufacturers from Snipe-it asset system
|
||||
.PARAMETER ID
|
||||
Unique ID For manufacturer to be removed
|
||||
.PARAMETER url
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. URL of Snipeit system.
|
||||
|
||||
.PARAMETER apiKey
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. User's API Key for Snipeit.
|
||||
|
||||
.EXAMPLE
|
||||
Remove-SnipeitManufacturer -ID 44
|
||||
|
||||
.EXAMPLE
|
||||
Get-SnipeitManufacturer | Where-object {$_.name -like '*something*'} | Remove-SnipeitManufacturer
|
||||
#>
|
||||
|
||||
function Remove-SnipeitManufacturer () {
|
||||
[CmdletBinding(
|
||||
SupportsShouldProcess = $true,
|
||||
ConfirmImpact = "Low"
|
||||
)]
|
||||
|
||||
Param(
|
||||
[parameter(mandatory = $true,ValueFromPipelineByPropertyName)]
|
||||
[int[]]$id,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$apiKey
|
||||
)
|
||||
|
||||
begin {
|
||||
}
|
||||
|
||||
process {
|
||||
foreach($manufacturer_id in $id) {
|
||||
$Parameters = @{
|
||||
Api = "/api/v1/manufacturers/$manufacturer_id"
|
||||
Method = 'Delete'
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyApiKey -apiKey $apikey
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url) {
|
||||
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyUrl -url $url
|
||||
}
|
||||
|
||||
if ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
}
|
||||
|
||||
$result
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
end {
|
||||
# reset legacy sessions
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url -or $PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Reset-SnipeitPSLegacyApi
|
||||
}
|
||||
}
|
||||
}
|
||||
72
SnipeitPS/Public/Remove-SnipeitModel.ps1
Normal file
72
SnipeitPS/Public/Remove-SnipeitModel.ps1
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Removes Asset model from Snipe-it asset system
|
||||
.DESCRIPTION
|
||||
Removes asset model or multiple assets models from Snipe-it asset system
|
||||
.PARAMETER ID
|
||||
Unique ID For Model to be removed
|
||||
.PARAMETER url
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. URL of Snipeit system.
|
||||
|
||||
.PARAMETER apiKey
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. User's API Key for Snipeit.
|
||||
|
||||
.EXAMPLE
|
||||
Remove-SnipeitModel -ID 44
|
||||
|
||||
.EXAMPLE
|
||||
Get-SnipeitModel -search needle | Remove-SnipeitModel
|
||||
#>
|
||||
|
||||
function Remove-SnipeitModel () {
|
||||
[CmdletBinding(
|
||||
SupportsShouldProcess = $true,
|
||||
ConfirmImpact = "Low"
|
||||
)]
|
||||
|
||||
Param(
|
||||
[parameter(mandatory = $true,ValueFromPipelineByPropertyName)]
|
||||
[int[]]$id,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$apiKey
|
||||
)
|
||||
|
||||
begin {
|
||||
}
|
||||
|
||||
process {
|
||||
foreach($model_id in $id) {
|
||||
$Parameters = @{
|
||||
Api = "/api/v1/models/$model_id"
|
||||
Method = 'Delete'
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyApiKey -apiKey $apikey
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url) {
|
||||
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyUrl -url $url
|
||||
}
|
||||
|
||||
if ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
}
|
||||
|
||||
$result
|
||||
}
|
||||
}
|
||||
|
||||
end {
|
||||
# reset legacy sessions
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url -or $PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Reset-SnipeitPSLegacyApi
|
||||
}
|
||||
}
|
||||
}
|
||||
72
SnipeitPS/Public/Remove-SnipeitSupplier.ps1
Normal file
72
SnipeitPS/Public/Remove-SnipeitSupplier.ps1
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Removes supplier from Snipe-it asset system
|
||||
.DESCRIPTION
|
||||
Removes supplier or multiple manufacturers from Snipe-it asset system
|
||||
.PARAMETER ID
|
||||
Unique ID For supplier to be removed
|
||||
.PARAMETER url
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. URL of Snipeit system.
|
||||
|
||||
.PARAMETER apiKey
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. User's API Key for Snipeit.
|
||||
|
||||
.EXAMPLE
|
||||
Remove-SnipeitSupplier -ID 44
|
||||
|
||||
.EXAMPLE
|
||||
Get-SnipeitSupplier | Where-object {$_.name -like '*something*'} | Remove-SnipeitSupplier
|
||||
#>
|
||||
|
||||
function Remove-SnipeitSupplier () {
|
||||
[CmdletBinding(
|
||||
SupportsShouldProcess = $true,
|
||||
ConfirmImpact = "Low"
|
||||
)]
|
||||
|
||||
Param(
|
||||
[parameter(mandatory = $true,ValueFromPipelineByPropertyName)]
|
||||
[int[]]$id,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$apiKey
|
||||
)
|
||||
|
||||
begin {
|
||||
}
|
||||
|
||||
process {
|
||||
foreach($suppliers_id in $id) {
|
||||
$Parameters = @{
|
||||
Api = "/api/v1/suppliers/$supplier_id"
|
||||
Method = 'Delete'
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyApiKey -apiKey $apikey
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url) {
|
||||
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyUrl -url $url
|
||||
}
|
||||
|
||||
if ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
}
|
||||
|
||||
$result
|
||||
}
|
||||
}
|
||||
|
||||
end {
|
||||
# reset legacy sessions
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url -or $PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Reset-SnipeitPSLegacyApi
|
||||
}
|
||||
}
|
||||
}
|
||||
71
SnipeitPS/Public/Remove-SnipeitUser.ps1
Normal file
71
SnipeitPS/Public/Remove-SnipeitUser.ps1
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Removes User from Snipe-it asset system
|
||||
.DESCRIPTION
|
||||
Removes Uuser or users from Snipe-it asset system
|
||||
.PARAMETER ID
|
||||
Unique ID For User to be removed
|
||||
|
||||
.PARAMETER url
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. URL of Snipeit system.
|
||||
|
||||
.PARAMETER apiKey
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. User's API Key for Snipeit.
|
||||
|
||||
.EXAMPLE
|
||||
Remove-SnipeitUser -ID 44 -url $url -apiKey $secret -Verbose
|
||||
#>
|
||||
|
||||
function Remove-SnipeitUser () {
|
||||
[CmdletBinding(
|
||||
SupportsShouldProcess = $true,
|
||||
ConfirmImpact = "Low"
|
||||
)]
|
||||
|
||||
Param(
|
||||
[parameter(mandatory = $true,ValueFromPipelineByPropertyName)]
|
||||
[int[]]$id,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$apiKey
|
||||
)
|
||||
|
||||
begin{
|
||||
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
|
||||
}
|
||||
|
||||
process {
|
||||
foreach($user_id in $id) {
|
||||
$Parameters = @{
|
||||
Api = "/api/v1/users/$user_id"
|
||||
Method = 'Delete'
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyApiKey -apiKey $apikey
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url) {
|
||||
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyUrl -url $url
|
||||
}
|
||||
|
||||
if ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
}
|
||||
|
||||
$result
|
||||
}
|
||||
}
|
||||
|
||||
end {
|
||||
# reset legacy sessions
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url -or $PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Reset-SnipeitPSLegacyApi
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,45 +0,0 @@
|
|||
function Reset-AssetOwner() {
|
||||
[CmdletBinding(
|
||||
SupportsShouldProcess = $true,
|
||||
ConfirmImpact = "Medium"
|
||||
)]
|
||||
|
||||
Param(
|
||||
[parameter(mandatory = $true)]
|
||||
[int]$id,
|
||||
|
||||
[int]$status_id,
|
||||
|
||||
[int]$location_id,
|
||||
|
||||
[string]$notes,
|
||||
|
||||
[parameter(mandatory = $true)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $true)]
|
||||
[string]$apiKey
|
||||
)
|
||||
|
||||
$Values = @{
|
||||
"notes" = $notes
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('location_id')) { $Values.Add("location_id", $location_id) }
|
||||
if ($PSBoundParameters.ContainsKey('status_id')) { $Values.Add("status_id", $status_id) }
|
||||
|
||||
$Body = $Values | ConvertTo-Json;
|
||||
|
||||
$Parameters = @{
|
||||
Uri = "$url/api/v1/hardware/$id/checkin"
|
||||
Method = 'POST'
|
||||
Body = $Body
|
||||
Token = $apiKey
|
||||
}
|
||||
|
||||
If ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
}
|
||||
|
||||
return $result
|
||||
}
|
||||
72
SnipeitPS/Public/Reset-SnipeitAccessoryOwner.ps1
Normal file
72
SnipeitPS/Public/Reset-SnipeitAccessoryOwner.ps1
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Checkin accessories
|
||||
|
||||
.DESCRIPTION
|
||||
Checkin accessories
|
||||
|
||||
.PARAMETER assigned_pivot_id
|
||||
This is the assigned_pivot_id of the accessory+user relationships in the accessories_users table
|
||||
Use Get-SnipeitAccessoryOwner to find out nooded value
|
||||
|
||||
.PARAMETER url
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. URL of Snipeit system.
|
||||
|
||||
.PARAMETER apiKey
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. User's API Key for Snipeit.
|
||||
|
||||
.EXAMPLE
|
||||
To get the accessories_users table for specific accessory id number
|
||||
|
||||
Get-SnipeitAccessoryOwner -id 1
|
||||
|
||||
Thenselect assigned_pivot_id for userid you like check in
|
||||
|
||||
Get-SnipeitAccessoryOwner -assigned_pivot_id xxx
|
||||
|
||||
#>
|
||||
function Reset-SnipeitAccessoryOwner() {
|
||||
[CmdletBinding(
|
||||
SupportsShouldProcess = $true,
|
||||
ConfirmImpact = "Medium"
|
||||
)]
|
||||
|
||||
Param(
|
||||
[parameter(mandatory = $true)]
|
||||
[int]$assigned_pivot_id,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$apiKey
|
||||
)
|
||||
|
||||
$Parameters = @{
|
||||
Api = "/api/v1/accessories/$assigned_pivot_id/checkin"
|
||||
Method = 'Post'
|
||||
Body = @{}
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyApiKey -apiKey $apikey
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url) {
|
||||
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyUrl -url $url
|
||||
}
|
||||
|
||||
if ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
}
|
||||
|
||||
# reset legacy sessions
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url -or $PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Reset-SnipeitPSLegacyApi
|
||||
}
|
||||
|
||||
return $result
|
||||
|
||||
}
|
||||
84
SnipeitPS/Public/Reset-SnipeitAssetOwner.ps1
Normal file
84
SnipeitPS/Public/Reset-SnipeitAssetOwner.ps1
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Checkin asset
|
||||
.DESCRIPTION
|
||||
Checks asset in from current user/localtion/asset
|
||||
|
||||
.PARAMETER ID
|
||||
Unique ID For asset to checkin
|
||||
|
||||
.PARAMETER status_id
|
||||
Change asset status to
|
||||
|
||||
.PARAMETER location_id
|
||||
Location id to change asset location to
|
||||
|
||||
.PARAMETER note
|
||||
Notes about checkin
|
||||
|
||||
.PARAMETER url
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. URL of Snipeit system.
|
||||
.PARAMETER apiKey
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. User's API Key for Snipeit.
|
||||
.EXAMPLE
|
||||
Remove-SnipeitUser -ID 44
|
||||
#>
|
||||
function Reset-SnipeitAssetOwner() {
|
||||
[CmdletBinding(
|
||||
SupportsShouldProcess = $true,
|
||||
ConfirmImpact = "Medium"
|
||||
)]
|
||||
|
||||
Param(
|
||||
[parameter(mandatory = $true)]
|
||||
[int]$id,
|
||||
|
||||
[int]$status_id,
|
||||
|
||||
[int]$location_id,
|
||||
|
||||
[string]$note,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$apiKey
|
||||
)
|
||||
|
||||
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
|
||||
|
||||
$Values = @{
|
||||
"note" = $note
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('location_id')) { $Values.Add("location_id", $location_id) }
|
||||
if ($PSBoundParameters.ContainsKey('status_id')) { $Values.Add("status_id", $status_id) }
|
||||
|
||||
$Parameters = @{
|
||||
Api = "/api/v1/hardware/$id/checkin"
|
||||
Method = 'POST'
|
||||
Body = $Values
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyApiKey -apiKey $apikey
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url) {
|
||||
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyUrl -url $url
|
||||
}
|
||||
|
||||
if ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
}
|
||||
|
||||
# reset legacy sessions
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url -or $PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Reset-SnipeitPSLegacyApi
|
||||
}
|
||||
|
||||
return $result
|
||||
}
|
||||
|
|
@ -1,88 +0,0 @@
|
|||
<#
|
||||
.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(
|
||||
SupportsShouldProcess = $true,
|
||||
ConfirmImpact = "Medium"
|
||||
)]
|
||||
|
||||
Param(
|
||||
[parameter(mandatory = $true)]
|
||||
[int]$id,
|
||||
|
||||
[string]$Name,
|
||||
|
||||
[string]$Status_id,
|
||||
|
||||
[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
|
||||
}
|
||||
|
||||
if ($customfields)
|
||||
{
|
||||
$Values += $customfields
|
||||
}
|
||||
|
||||
$Body = $Values | ConvertTo-Json;
|
||||
|
||||
$Parameters = @{
|
||||
Uri = "$url/api/v1/hardware/$id"
|
||||
Method = 'Put'
|
||||
Body = $Body
|
||||
Token = $apiKey
|
||||
}
|
||||
|
||||
If ($PSCmdlet.ShouldProcess("ShouldProcess?"))
|
||||
{
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
}
|
||||
|
||||
$result
|
||||
}
|
||||
|
|
@ -1,52 +0,0 @@
|
|||
function Set-AssetOwner()
|
||||
{
|
||||
[CmdletBinding(
|
||||
SupportsShouldProcess = $true,
|
||||
ConfirmImpact = "Medium"
|
||||
)]
|
||||
|
||||
Param(
|
||||
[parameter(mandatory = $true)]
|
||||
[int]$id,
|
||||
|
||||
[parameter(mandatory = $true)]
|
||||
[int]$assigned_id,
|
||||
|
||||
[ValidateSet("location","asset","user")]
|
||||
[string] $checkout_to_type = "user",
|
||||
|
||||
[parameter(mandatory = $true)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $true)]
|
||||
[string]$apiKey
|
||||
)
|
||||
|
||||
$Values = @{
|
||||
"id" = $assigned_id
|
||||
"checkout_to_type" = $checkout_to_type
|
||||
}
|
||||
|
||||
switch ($checkout_to_type)
|
||||
{
|
||||
'location' { $Values += @{ "assigned_location" = $assigned_id } }
|
||||
'user' { $Values += @{ "assigned_user" = $assigned_id } }
|
||||
'asset' { $Values += @{ "assigned_asset" = $assigned_id } }
|
||||
}
|
||||
|
||||
$Body = $Values | ConvertTo-Json;
|
||||
|
||||
$Parameters = @{
|
||||
Uri = "$url/api/v1/hardware/$id/checkout"
|
||||
Method = 'POST'
|
||||
Body = $Body
|
||||
Token = $apiKey
|
||||
}
|
||||
|
||||
If ($PSCmdlet.ShouldProcess("ShouldProcess?"))
|
||||
{
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
}
|
||||
|
||||
return $result
|
||||
}
|
||||
|
|
@ -1,41 +0,0 @@
|
|||
function Set-Component()
|
||||
{
|
||||
[CmdletBinding(
|
||||
SupportsShouldProcess = $true,
|
||||
ConfirmImpact = "Medium"
|
||||
)]
|
||||
|
||||
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("ShouldProcess?"))
|
||||
{
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
}
|
||||
|
||||
$result
|
||||
}
|
||||
|
|
@ -1,50 +0,0 @@
|
|||
function Set-Info {
|
||||
[CmdletBinding()]
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseShouldProcessForStateChangingFunctions', '')]
|
||||
param (
|
||||
[Uri]$url,
|
||||
|
||||
[String]$apiKey
|
||||
)
|
||||
|
||||
BEGIN {
|
||||
|
||||
function Add-DefaultParameter {
|
||||
param(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string]$Command,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string]$Parameter,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
$Value
|
||||
)
|
||||
|
||||
PROCESS {
|
||||
#Write-Verbose "[$($MyInvocation.MyCommand.Name)] Setting [$command : $parameter] = $value"
|
||||
|
||||
# Needs to set both global and module scope for the private functions:
|
||||
# http://stackoverflow.com/questions/30427110/set-psdefaultparametersvalues-for-use-within-module-scope
|
||||
$PSDefaultParameterValues["${command}:${parameter}"] = $Value
|
||||
$global:PSDefaultParameterValues["${command}:${parameter}"] = $Value
|
||||
}
|
||||
}
|
||||
|
||||
$moduleCommands = Get-Command -Module SnipeitPS
|
||||
}
|
||||
|
||||
PROCESS {
|
||||
foreach ($command in $moduleCommands) {
|
||||
$parameter = "url"
|
||||
if ($url -and ($command.Parameters.Keys -contains $parameter)) {
|
||||
Add-DefaultParameter -Command $command -Parameter $parameter -Value ($url.AbsoluteUri.TrimEnd('/'))
|
||||
}
|
||||
|
||||
$parameter = "apiKey"
|
||||
if ($apiKey -and ($command.Parameters.Keys -contains $parameter)) {
|
||||
Add-DefaultParameter -Command $command -Parameter $parameter -Value $apiKey
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
160
SnipeitPS/Public/Set-SnipeitAccessory.ps1
Normal file
160
SnipeitPS/Public/Set-SnipeitAccessory.ps1
Normal file
|
|
@ -0,0 +1,160 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Updates accessory on Snipe-It system
|
||||
|
||||
.DESCRIPTION
|
||||
Updates accessory on Snipe-It system
|
||||
|
||||
.PARAMETER name
|
||||
ID number of Accessory or array of IDs on Snipe-It system
|
||||
|
||||
.PARAMETER notes
|
||||
Notes about the accessory
|
||||
|
||||
.PARAMETER qty
|
||||
Quantity of the accessory you have
|
||||
|
||||
.PARAMETER min_amt
|
||||
Minimum amount of the accessory, before alert is triggered
|
||||
|
||||
.PARAMETER category_id
|
||||
ID number of the category the accessory belongs to
|
||||
|
||||
.PARAMETER company_id
|
||||
ID Number of the company the accessory is assigned to
|
||||
|
||||
.PARAMETER manufacturer_id
|
||||
ID number of the manufacturer for this accessory.
|
||||
|
||||
.PARAMETER model_number
|
||||
Model number for this accessory
|
||||
|
||||
.PARAMETER order_number
|
||||
Order number for this accessory.
|
||||
|
||||
.PARAMETER purchase_cost
|
||||
Cost of item being purchased.
|
||||
|
||||
.PARAMETER purchase_date
|
||||
Date accessory was purchased
|
||||
|
||||
.PARAMETER supplier_id
|
||||
ID number of the supplier for this accessory
|
||||
|
||||
.PARAMETER location_id
|
||||
ID number of the location the accessory is assigned to
|
||||
|
||||
.PARAMETER image
|
||||
Image file name and path for item
|
||||
|
||||
.PARAMETER image_delete
|
||||
Remove current image
|
||||
|
||||
.PARAMETER RequestType
|
||||
Http request type to send Snipe IT system. Defaults to Patch you could use Put if needed.
|
||||
|
||||
.PARAMETER url
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. URL of Snipeit system.
|
||||
|
||||
.PARAMETER apiKey
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. Users API Key for Snipeit.
|
||||
.EXAMPLE
|
||||
Set-SnipeitAccessory -id 1 -qty 3
|
||||
|
||||
#>
|
||||
function Set-SnipeitAccessory() {
|
||||
[CmdletBinding(
|
||||
SupportsShouldProcess = $true,
|
||||
ConfirmImpact = "Low"
|
||||
)]
|
||||
|
||||
Param(
|
||||
[parameter(mandatory = $true,ValueFromPipelineByPropertyName)]
|
||||
[int[]]$id,
|
||||
|
||||
[ValidateLength(3, 255)]
|
||||
[string]$name,
|
||||
|
||||
[int]$qty,
|
||||
|
||||
[ValidateRange(1, [int]::MaxValue)]
|
||||
[int]$category_id,
|
||||
|
||||
[Nullable[System.Int32]]$company_id,
|
||||
|
||||
[Nullable[System.Int32]]$manufacturer_id,
|
||||
|
||||
[string]$model_number,
|
||||
|
||||
[string]$order_number,
|
||||
|
||||
[float]$purchase_cost,
|
||||
|
||||
[datetime]$purchase_date,
|
||||
|
||||
[Nullable[System.Int32]]$min_amt,
|
||||
|
||||
[Nullable[System.Int32]]$supplier_id,
|
||||
|
||||
[Nullable[System.Int32]]$location_id,
|
||||
|
||||
[ValidateScript({Test-Path $_})]
|
||||
[string]$image,
|
||||
|
||||
[switch]$image_delete=$false,
|
||||
|
||||
[ValidateSet("Put","Patch")]
|
||||
[string]$RequestType = "Patch",
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$apiKey
|
||||
)
|
||||
|
||||
begin {
|
||||
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
|
||||
|
||||
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
|
||||
|
||||
if ($Values['purchase_date']) {
|
||||
$Values['purchase_date'] = $Values['purchase_date'].ToString("yyyy-MM-dd")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
process {
|
||||
foreach($accessory_id in $id) {
|
||||
$Parameters = @{
|
||||
Api = "/api/v1/accessories/$accessory_id"
|
||||
Method = $RequestType
|
||||
Body = $Values
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyApiKey -apiKey $apikey
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url) {
|
||||
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyUrl -url $url
|
||||
}
|
||||
|
||||
if ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
}
|
||||
|
||||
$result
|
||||
}
|
||||
}
|
||||
|
||||
end {
|
||||
# reset legacy sessions
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url -or $PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Reset-SnipeitPSLegacyApi
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
82
SnipeitPS/Public/Set-SnipeitAccessoryOwner.ps1
Normal file
82
SnipeitPS/Public/Set-SnipeitAccessoryOwner.ps1
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Checkout accessory
|
||||
.DESCRIPTION
|
||||
Checkout accessory to user
|
||||
|
||||
.PARAMETER id
|
||||
Unique ID For accessory or array of IDs to checkout
|
||||
|
||||
.PARAMETER assigned_id
|
||||
Id of target user
|
||||
|
||||
.PARAMETER note
|
||||
Notes about checkout
|
||||
|
||||
.PARAMETER url
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. URL of Snipeit system.
|
||||
|
||||
.PARAMETER apiKey
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. User's API Key for Snipeit.
|
||||
|
||||
.EXAMPLE
|
||||
Set-SnipeitAccessoryOwner -id 1 -assigned_id 1 -note "testing check out to user"
|
||||
#>
|
||||
function Set-SnipeitAccessoryOwner() {
|
||||
[CmdletBinding(
|
||||
SupportsShouldProcess = $true,
|
||||
ConfirmImpact = "Medium"
|
||||
)]
|
||||
|
||||
Param(
|
||||
[parameter(mandatory = $true,ValueFromPipelineByPropertyName)]
|
||||
[int[]]$id,
|
||||
|
||||
[parameter(mandatory = $true)]
|
||||
[int]$assigned_to,
|
||||
|
||||
[string] $note,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$apiKey
|
||||
)
|
||||
begin{
|
||||
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
|
||||
}
|
||||
|
||||
process {
|
||||
foreach($accessory_id in $id) {
|
||||
$Parameters = @{
|
||||
Api = "/api/v1/accessories/$accessory_id/checkout"
|
||||
Method = 'POST'
|
||||
Body = $Values
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyApiKey -apiKey $apikey
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url) {
|
||||
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyUrl -url $url
|
||||
}
|
||||
|
||||
if ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
}
|
||||
|
||||
return $result
|
||||
}
|
||||
}
|
||||
|
||||
end {
|
||||
# reset legacy sessions
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url -or $PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Reset-SnipeitPSLegacyApi
|
||||
}
|
||||
}
|
||||
}
|
||||
203
SnipeitPS/Public/Set-SnipeitAsset.ps1
Normal file
203
SnipeitPS/Public/Set-SnipeitAsset.ps1
Normal file
|
|
@ -0,0 +1,203 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Update a specific Asset in the Snipe-it asset system
|
||||
|
||||
.DESCRIPTION
|
||||
Long description
|
||||
|
||||
.PARAMETER id
|
||||
ID of the Asset or array of IDs
|
||||
|
||||
.PARAMETER asset_tag
|
||||
New tag for asset.
|
||||
|
||||
.PARAMETER Name
|
||||
Asset name
|
||||
|
||||
.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 last_checkout
|
||||
Date the asset was last checked out
|
||||
|
||||
.PARAMETER assigned_to
|
||||
The id of the user the asset is currently checked out to
|
||||
|
||||
.PARAMETER company_id
|
||||
The id of an associated company id
|
||||
|
||||
.PARAMETER serial
|
||||
Serial number of the asset
|
||||
|
||||
.PARAMETER order_number
|
||||
Order number for the asset
|
||||
|
||||
.PARAMETER warranty_months
|
||||
Number of months for the asset warranty
|
||||
|
||||
.PARAMETER purchase_cost
|
||||
Purchase cost of the asset, without a currency symbol
|
||||
|
||||
.PARAMETER purchase_date
|
||||
Date of asset purchase
|
||||
|
||||
.PARAMETER supplier_id
|
||||
Supplier id of the Asset
|
||||
|
||||
.PARAMETER requestable
|
||||
Whether or not the asset can be requested by users with the permission to request assets
|
||||
|
||||
.PARAMETER archived
|
||||
Whether or not the asset is archived. Archived assets cannot be checked out and do not show up in the deployable asset screens
|
||||
|
||||
.PARAMETER rtd_location_id
|
||||
The id that corresponds to the location where the asset is usually located when not checked out
|
||||
|
||||
.PARAMETER notes
|
||||
Notes about asset
|
||||
|
||||
.PARAMETER image
|
||||
Image file name and path for item
|
||||
|
||||
.PARAMETER image_delete
|
||||
Remove current image
|
||||
|
||||
.PARAMETER RequestType
|
||||
Http request type to send Snipe IT system. Defaults to Patch you could use Put if needed.
|
||||
|
||||
.PARAMETER url
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. URL of Snipeit system.
|
||||
|
||||
.PARAMETER apiKey
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. Users API Key for Snipeit.
|
||||
|
||||
.PARAMETER customfields
|
||||
Hastable of custom fields and extra fields that need passing through to Snipeit
|
||||
|
||||
.EXAMPLE
|
||||
Set-SnipeitAsset -id 1 -status_id 1 -model_id 1 -name "Machine1"
|
||||
|
||||
.EXAMPLE
|
||||
Set-SnipeitAsset -id 1 -name "Machine1" -customfields = @{ "_snipeit_os_5" = "Windows 10 Pro" ; "_snipeit_os_version" = "1909" }
|
||||
|
||||
.EXAMPLE
|
||||
Get-SnipeitAsset -serial 12345678 | Set-SnipeitAsset -notes 'Just updated'
|
||||
#>
|
||||
|
||||
function Set-SnipeitAsset() {
|
||||
[CmdletBinding(
|
||||
SupportsShouldProcess = $true,
|
||||
ConfirmImpact = "Medium"
|
||||
)]
|
||||
|
||||
Param(
|
||||
[parameter(mandatory = $true,ValueFromPipelineByPropertyName)]
|
||||
[int[]]$id,
|
||||
|
||||
[parameter(Mandatory=$false)]
|
||||
[string]
|
||||
$asset_tag,
|
||||
|
||||
[string]$name,
|
||||
|
||||
[ValidateRange(1, [int]::MaxValue)]
|
||||
[int]$status_id,
|
||||
|
||||
[ValidateRange(1, [int]::MaxValue)]
|
||||
[int]$model_id,
|
||||
|
||||
[DateTime]$last_checkout,
|
||||
|
||||
[Nullable[System.Int32]]$assigned_to,
|
||||
|
||||
[Nullable[System.Int32]]$company_id,
|
||||
|
||||
[string]$serial,
|
||||
|
||||
[string]$order_number,
|
||||
|
||||
[Nullable[System.Int32]]$warranty_months,
|
||||
|
||||
[double]$purchase_cost,
|
||||
|
||||
[datetime]$purchase_date,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[int]$supplier_id,
|
||||
|
||||
[bool]$requestable,
|
||||
|
||||
[bool]$archived,
|
||||
|
||||
[Nullable[System.Int32]]$rtd_location_id,
|
||||
|
||||
[string]$notes,
|
||||
|
||||
[ValidateSet("Put","Patch")]
|
||||
[string]$RequestType = "Patch",
|
||||
|
||||
[ValidateScript({Test-Path $_})]
|
||||
[string]$image,
|
||||
|
||||
[switch]$image_delete=$false,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$apiKey,
|
||||
|
||||
[Alias('CustomValues')]
|
||||
[hashtable] $customfields
|
||||
)
|
||||
begin{
|
||||
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
|
||||
|
||||
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
|
||||
|
||||
if ($Values['purchase_date']) {
|
||||
$Values['purchase_date'] = $Values['purchase_date'].ToString("yyyy-MM-dd")
|
||||
}
|
||||
|
||||
if ($customfields) {
|
||||
$Values += $customfields
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
process {
|
||||
foreach($asset_id in $id) {
|
||||
$Parameters = @{
|
||||
Api = "/api/v1/hardware/$asset_id"
|
||||
Method = $RequestType
|
||||
Body = $Values
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyApiKey -apiKey $apikey
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url) {
|
||||
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyUrl -url $url
|
||||
}
|
||||
|
||||
if ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
}
|
||||
|
||||
$result
|
||||
}
|
||||
}
|
||||
|
||||
end {
|
||||
# reset legacy sessions
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url -or $PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Reset-SnipeitPSLegacyApi
|
||||
}
|
||||
}
|
||||
}
|
||||
126
SnipeitPS/Public/Set-SnipeitAssetOwner.ps1
Normal file
126
SnipeitPS/Public/Set-SnipeitAssetOwner.ps1
Normal file
|
|
@ -0,0 +1,126 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Checkout asset
|
||||
.DESCRIPTION
|
||||
Checkout asset to user/localtion/asset
|
||||
|
||||
.PARAMETER ID
|
||||
Unique IDs For assets to checkout
|
||||
|
||||
.PARAMETER assigned_id
|
||||
Id of target user , location or asset
|
||||
|
||||
.PARAMETER checkout_to_type
|
||||
Checkout asset to one of following types user, location, asset
|
||||
|
||||
.PARAMETER note
|
||||
Notes about checkout
|
||||
|
||||
.PARAMETER name
|
||||
Optional new asset name. This is useful for changing the asset's name on new checkout,
|
||||
for example, an asset that was named "Anna's Macbook Pro" could be renamed on the fly
|
||||
when it's checked out to Elizabeth, to "Beth's Macbook Pro"
|
||||
|
||||
.PARAMETER expected_checkin
|
||||
Optional date the asset is expected to be checked in
|
||||
|
||||
.PARAMETER checkout_at
|
||||
Optional date to override the checkout time of now
|
||||
|
||||
.PARAMETER url
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. URL of Snipeit system.
|
||||
|
||||
.PARAMETER apiKey
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. User's API Key for Snipeit.
|
||||
|
||||
.EXAMPLE
|
||||
Set-SnipeitAssetOwner -id 1 -assigned_id 1 -checkout_to_type user -note "testing check out to user"
|
||||
#>
|
||||
function Set-SnipeitAssetOwner() {
|
||||
[CmdletBinding(
|
||||
SupportsShouldProcess = $true,
|
||||
ConfirmImpact = "Medium"
|
||||
)]
|
||||
|
||||
Param(
|
||||
[parameter(mandatory = $true,ValueFromPipelineByPropertyName)]
|
||||
[int[]]$id,
|
||||
|
||||
[parameter(mandatory = $true)]
|
||||
[int]$assigned_id,
|
||||
|
||||
[ValidateSet("location","asset","user")]
|
||||
[string] $checkout_to_type = "user",
|
||||
|
||||
[string] $name,
|
||||
|
||||
[string] $note,
|
||||
|
||||
[datetime] $expected_checkin,
|
||||
|
||||
[datetime]$checkout_at,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$apiKey
|
||||
)
|
||||
|
||||
begin{
|
||||
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
|
||||
|
||||
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
|
||||
|
||||
if ($Values['expected_checkin']) {
|
||||
$Values['expected_checkin'] = $Values['expected_checkin'].ToString("yyyy-MM-dd")
|
||||
}
|
||||
|
||||
if ($Values['checkout_at']) {
|
||||
$Values['checkout_at'] = $Values['checkout_at'].ToString("yyyy-MM-dd")
|
||||
}
|
||||
|
||||
switch ($checkout_to_type) {
|
||||
'location' { $Values += @{ "assigned_location" = $assigned_id } }
|
||||
'user' { $Values += @{ "assigned_user" = $assigned_id } }
|
||||
'asset' { $Values += @{ "assigned_asset" = $assigned_id } }
|
||||
}
|
||||
|
||||
#This can be removed now
|
||||
if ($Values.ContainsKey('assigned_id')) {$Values.Remove('assigned_id')}
|
||||
|
||||
}
|
||||
|
||||
process{
|
||||
foreach($asset_id in $id) {
|
||||
$Parameters = @{
|
||||
Api = "/api/v1/hardware/$asset_id/checkout"
|
||||
Method = 'POST'
|
||||
Body = $Values
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyApiKey -apiKey $apikey
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url) {
|
||||
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyUrl -url $url
|
||||
}
|
||||
|
||||
if ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
}
|
||||
|
||||
return $result
|
||||
}
|
||||
}
|
||||
|
||||
end {
|
||||
# reset legacy sessions
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url -or $PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Reset-SnipeitPSLegacyApi
|
||||
}
|
||||
}
|
||||
}
|
||||
119
SnipeitPS/Public/Set-SnipeitCategory.ps1
Normal file
119
SnipeitPS/Public/Set-SnipeitCategory.ps1
Normal file
|
|
@ -0,0 +1,119 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Create a new Snipe-IT Category
|
||||
|
||||
.PARAMETER name
|
||||
Name of new category to be created
|
||||
|
||||
.PARAMETER type
|
||||
Type of new category to be created (asset, accessory, consumable, component, license)
|
||||
|
||||
.PARAMETER use_default_eula
|
||||
If switch is present, use the primary default EULA
|
||||
|
||||
.PARAMETER eula_text
|
||||
This allows you to customize your EULAs for specific types of assets
|
||||
|
||||
.PARAMETER require_acceptance
|
||||
If switch is present, require users to confirm acceptance of assets in this category
|
||||
|
||||
.PARAMETER checkin_email
|
||||
Should the user be emailed the EULA and/or an acceptance confirmation email when this item is checked in?
|
||||
|
||||
.PARAMETER image
|
||||
Image file name and path for item
|
||||
|
||||
.PARAMETER image_delete
|
||||
Remove current image
|
||||
|
||||
.PARAMETER RequestType
|
||||
Http request type to send Snipe IT system. Defaults to Patch you could use Put if needed.
|
||||
|
||||
.PARAMETER url
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. URL of Snipeit system.
|
||||
|
||||
.PARAMETER apiKey
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. Users API Key API Key for Snipeit.
|
||||
|
||||
.EXAMPLE
|
||||
Set-SnipeitCategory -id 4 -name "Laptops"
|
||||
#>
|
||||
|
||||
function Set-SnipeitCategory() {
|
||||
[CmdletBinding(
|
||||
SupportsShouldProcess = $true,
|
||||
ConfirmImpact = "Low"
|
||||
)]
|
||||
|
||||
Param(
|
||||
[parameter(mandatory = $true)]
|
||||
[int[]]$id,
|
||||
|
||||
[string]$name,
|
||||
|
||||
[ValidateSet("asset", "accessory", "consumable", "component", "license")]
|
||||
[string]$category_type,
|
||||
|
||||
[string]$eula_text,
|
||||
|
||||
[bool]$use_default_eula,
|
||||
|
||||
[bool]$require_acceptance,
|
||||
|
||||
[bool]$checkin_email,
|
||||
|
||||
[ValidateScript({Test-Path $_})]
|
||||
[string]$image,
|
||||
|
||||
[switch]$image_delete=$false,
|
||||
|
||||
[ValidateSet("Put","Patch")]
|
||||
[string]$RequestType = "Patch",
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$apiKey
|
||||
|
||||
)
|
||||
|
||||
begin {
|
||||
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
|
||||
|
||||
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
|
||||
}
|
||||
|
||||
process {
|
||||
foreach($category_id in $id) {
|
||||
$Parameters = @{
|
||||
Api = "/api/v1/categories/$category_id"
|
||||
Method = $RequestType
|
||||
Body = $values
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyApiKey -apiKey $apikey
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url) {
|
||||
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyUrl -url $url
|
||||
}
|
||||
|
||||
if ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
}
|
||||
|
||||
$result
|
||||
}
|
||||
}
|
||||
|
||||
end {
|
||||
# reset legacy sessions
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url -or $PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Reset-SnipeitPSLegacyApi
|
||||
}
|
||||
}
|
||||
}
|
||||
98
SnipeitPS/Public/Set-SnipeitCompany.ps1
Normal file
98
SnipeitPS/Public/Set-SnipeitCompany.ps1
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Updates company name
|
||||
|
||||
.DESCRIPTION
|
||||
Updates companyt name on Snipe-It system
|
||||
|
||||
.PARAMETER id
|
||||
ID number of company
|
||||
|
||||
.PARAMETER name
|
||||
Company name
|
||||
|
||||
.PARAMETER image
|
||||
Image file name and path for item
|
||||
|
||||
.PARAMETER image_delete
|
||||
Remove current image
|
||||
|
||||
.PARAMETER RequestType
|
||||
Http request type to send Snipe IT system. Defaults to Patch you could use Put if needed.
|
||||
|
||||
.PARAMETER url
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. URL of Snipeit system.
|
||||
|
||||
.PARAMETER apiKey
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. Users API Key API Key for Snipeit.
|
||||
|
||||
.EXAMPLE
|
||||
An example
|
||||
|
||||
.NOTES
|
||||
General notes
|
||||
#>
|
||||
function Set-SnipeitCompany() {
|
||||
[CmdletBinding(
|
||||
SupportsShouldProcess = $true,
|
||||
ConfirmImpact = "Medium"
|
||||
)]
|
||||
|
||||
Param(
|
||||
[parameter(mandatory = $true,ValueFromPipelineByPropertyName)]
|
||||
[int[]]$id,
|
||||
|
||||
[parameter(mandatory = $true)]
|
||||
[string]$name,
|
||||
|
||||
[ValidateScript({Test-Path $_})]
|
||||
[string]$image,
|
||||
|
||||
[switch]$image_delete=$false,
|
||||
|
||||
[ValidateSet("Put","Patch")]
|
||||
[string]$RequestType = "Patch",
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$apiKey
|
||||
)
|
||||
|
||||
begin{
|
||||
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
|
||||
}
|
||||
|
||||
process{
|
||||
foreach($company_id in $id) {
|
||||
$Parameters = @{
|
||||
Api = "/api/v1/companies/$company_id"
|
||||
Method = $RequestType
|
||||
Body = $Values
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyApiKey -apiKey $apikey
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url) {
|
||||
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyUrl -url $url
|
||||
}
|
||||
|
||||
if ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
}
|
||||
|
||||
$result
|
||||
}
|
||||
}
|
||||
end {
|
||||
# reset legacy sessions
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url -or $PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Reset-SnipeitPSLegacyApi
|
||||
}
|
||||
}
|
||||
}
|
||||
139
SnipeitPS/Public/Set-SnipeitComponent.ps1
Normal file
139
SnipeitPS/Public/Set-SnipeitComponent.ps1
Normal file
|
|
@ -0,0 +1,139 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Updates component
|
||||
|
||||
.DESCRIPTION
|
||||
Updates component on Snipe-It system
|
||||
|
||||
.PARAMETER id
|
||||
ID number of name
|
||||
|
||||
.PARAMETER name
|
||||
Component name
|
||||
|
||||
.PARAMETER category_id
|
||||
ID number of category
|
||||
|
||||
.PARAMETER qty
|
||||
Quantity of the components you have
|
||||
|
||||
.PARAMETER min_amt
|
||||
Minimum Quantity of the components before alert is triggered
|
||||
|
||||
.PARAMETER location_id
|
||||
ID number of the location the accessory is assigned to
|
||||
|
||||
.PARAMETER order_number
|
||||
Order number for the accessory
|
||||
|
||||
.PARAMETER purchase_date
|
||||
Date accessory was purchased
|
||||
|
||||
.PARAMETER purchase_cost
|
||||
Cost of item being purchased.
|
||||
|
||||
.PARAMETER image
|
||||
Image file name and path for item
|
||||
|
||||
.PARAMETER image_delete
|
||||
Remove current image
|
||||
|
||||
.PARAMETER RequestType
|
||||
Http request type to send Snipe IT system. Defaults to Patch you could use Put if needed.
|
||||
|
||||
.PARAMETER url
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. URL of Snipeit system.
|
||||
|
||||
.PARAMETER apiKey
|
||||
Deprecated parameter, please use Connect-SnipeitPS instead. Users API Key API Key for Snipeit.
|
||||
|
||||
.EXAMPLE
|
||||
Set-SnipeitComponent -id 42 -qty 12
|
||||
Sets count of component with ID 42 to 12
|
||||
|
||||
#>
|
||||
function Set-SnipeitComponent() {
|
||||
[CmdletBinding(
|
||||
SupportsShouldProcess = $true,
|
||||
ConfirmImpact = "Medium"
|
||||
)]
|
||||
|
||||
Param(
|
||||
[parameter(mandatory = $true,ValueFromPipelineByPropertyName)]
|
||||
[int[]]$id,
|
||||
|
||||
[parameter(mandatory = $true)]
|
||||
[int]$qty,
|
||||
|
||||
[Nullable[System.Int32]]$min_amt,
|
||||
|
||||
[string]$name,
|
||||
|
||||
[Nullable[System.Int32]]$company_id,
|
||||
|
||||
[Nullable[System.Int32]]$location_id,
|
||||
|
||||
|
||||
[string]$order_number,
|
||||
|
||||
[datetime]$purchase_date,
|
||||
|
||||
[float]$purchase_cost,
|
||||
|
||||
[ValidateScript({Test-Path $_})]
|
||||
[string]$image,
|
||||
|
||||
[switch]$image_delete=$false,
|
||||
|
||||
[ValidateSet("Put","Patch")]
|
||||
[string]$RequestType = "Patch",
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$apiKey
|
||||
)
|
||||
begin {
|
||||
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
|
||||
|
||||
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
|
||||
|
||||
if ($Values['purchase_date']) {
|
||||
$Values['purchase_date'] = $Values['purchase_date'].ToString("yyyy-MM-dd")
|
||||
}
|
||||
}
|
||||
|
||||
process {
|
||||
foreach($component_id in $id) {
|
||||
$Parameters = @{
|
||||
Api = "/api/v1/components/$component_id"
|
||||
Method = $RequestType
|
||||
Body = $Values
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyApiKey -apiKey $apikey
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url) {
|
||||
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
|
||||
Set-SnipeitPSLegacyUrl -url $url
|
||||
}
|
||||
|
||||
if ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
}
|
||||
|
||||
$result
|
||||
}
|
||||
}
|
||||
|
||||
end {
|
||||
# reset legacy sessions
|
||||
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url -or $PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
||||
Reset-SnipeitPSLegacyApi
|
||||
}
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue