2020 PSCredential where username shoul be snipe it url and password should be
2121 snipe it apikey.
2222
23+ . PARAMETER throttleLimit
24+ Throttle request rate to nro of requests per throttlePeriod. Defaults to 0 that means no requests are not throttled.
25+
26+ . PARAMETER throttlePeriod
27+ Throttle period time span in milliseconds defaults to 60 milliseconds.
28+
29+ . PARAMETER throttleThreshold
30+ Threshold percentage of used request on period after request are throttled.
31+
32+ . PARAMETER throttleMode
33+ RequestThrottling type. "Burst" allows all requests to be used in ThrottlePeriod without delays and then waits
34+ until there's new requests avalable. With "Contant" mode there always delay between requests. Delay is calculated
35+ by dividing throttlePeriod with throttleLimit. "Adaptive" mode allows throttleThreshold percentage of request to be
36+ used with out delay, after threshold limit is reached next requests are delayded by dividing available requests
37+ over throttlePeriod.
38+
2339 . EXAMPLE
2440 Connect-SnipeitPS -Url $url -apiKey $myapikey
2541 Connect to Snipe it api.
@@ -61,7 +77,28 @@ function Connect-SnipeitPS {
6177 [SecureString ]$secureApiKey ,
6278
6379 [Parameter (ParameterSetName = ' Connect with credential' , Mandatory = $true )]
64- [PSCredential ]$siteCred
80+ [PSCredential ]$siteCred ,
81+
82+ [Parameter (ParameterSetName = ' Connect with url and apikey' , Mandatory = $false )]
83+ [Parameter (ParameterSetName = ' Connect with url and secure apikey' , Mandatory = $false )]
84+ [Parameter (ParameterSetName = ' Connect with credential' , Mandatory = $false )]
85+ [int ]$throttleLimit ,
86+
87+ [Parameter (ParameterSetName = ' Connect with url and apikey' , Mandatory = $false )]
88+ [Parameter (ParameterSetName = ' Connect with url and secure apikey' , Mandatory = $false )]
89+ [Parameter (ParameterSetName = ' Connect with credential' , Mandatory = $false )]
90+ [int ]$throttlePeriod ,
91+
92+ [Parameter (ParameterSetName = ' Connect with url and apikey' , Mandatory = $false )]
93+ [Parameter (ParameterSetName = ' Connect with url and secure apikey' , Mandatory = $false )]
94+ [Parameter (ParameterSetName = ' Connect with credential' , Mandatory = $false )]
95+ [int ]$throttleThreshold ,
96+
97+ [Parameter (ParameterSetName = ' Connect with url and apikey' , Mandatory = $false )]
98+ [Parameter (ParameterSetName = ' Connect with url and secure apikey' , Mandatory = $false )]
99+ [Parameter (ParameterSetName = ' Connect with credential' , Mandatory = $false )]
100+ [ValidateSet (" Burst" , " Constant" , " Adaptive" )]
101+ [string ]$throttleMode
65102 )
66103
67104
@@ -86,6 +123,21 @@ function Connect-SnipeitPS {
86123 $SnipeitPSSession.apiKey = $siteCred.GetNetworkCredential ().SecurePassword
87124 }
88125 }
126+ if ($null -eq $throttleLimit ) { $throttleLimit = 0 }
127+ $SnipeitPSSession.throttleLimit = $throttleLimit
128+
129+ if ($throttleThreshold -lt 1 ) { $throttleThreshold = 90 }
130+ $SnipeitPSSession.throttleThreshold = $throttleThreshold
131+
132+ if (' ' -eq $throttleMode ) { $throttleMode = " Burst" }
133+ $SnipeitPSSession.throttleMode = $throttleMode
134+
135+ if ($SnipeitPSSession.throttleLimit -gt 0 ) {
136+ if ($null -eq $throttlePeriod ) { $throttlePeriod = 60000 }
137+ $SnipeitPSSession.throttlePeriod = $throttlePeriod
138+
139+ $SnipeitPSSession.throttledRequests = [System.Collections.ArrayList ]::new()
140+ }
89141
90142 Write-Debug " Site-url $ ( $SnipeitPSSession.url ) "
91143 Write-Debug " Site apikey: $ ( $SnipeitPSSession.apiKey ) "
0 commit comments