@@ -275,6 +275,18 @@ function Global:New-SGWAccount {
275275 [parameter (
276276 Mandatory = $False ,
277277 Position = 2 ,
278+ HelpMessage = " Use account identity source (supported since StorageGRID 10.4)." )][Boolean ]$UseAccountIdentitySource = $true ,
279+ [parameter (
280+ Mandatory = $False ,
281+ Position = 3 ,
282+ HelpMessage = " Quota for tenant in bytes." )][Int ]$Quota ,
283+ [parameter (
284+ Mandatory = $False ,
285+ Position = 4 ,
286+ HelpMessage = " Tenant root password." )][String ]$Password ,
287+ [parameter (
288+ Mandatory = $False ,
289+ Position = 4 ,
278290 HelpMessage = " StorageGRID Webscale Management Server object. If not specified, global CurrentSGWServer object will be used." )][PSCustomObject ]$Server
279291 )
280292
@@ -285,33 +297,60 @@ function Global:New-SGWAccount {
285297 if (! $Server ) {
286298 Write-Error " No StorageGRID Webscale Management Server management server found. Please run Connect-SGWServer to continue."
287299 }
300+ if ($Server.APIVersion -ge 2 -and ! $Password ) {
301+ Write-Error " Password required"
302+ }
288303
289304 $Capabilities = ' "' + ($Capabilities -split ' ,' -join ' ","' ) + ' "'
290305 }
291306
292307 Process {
293- $Name = @ ($Name )
294- foreach ($Name in $Name ) {
295- $Uri = $Server.BaseURI + " /grid/accounts"
296- $Method = " POST"
308+ $Uri = $Server.BaseURI + " /grid/accounts"
309+ $Method = " POST"
297310
311+ if ($Server.APIVersion -lt 2 ) {
298312 $Body = @"
299313{
300314 "name": "$Name ",
301315 "capabilities": [ $Capabilities ]
302316}
303317"@
304-
305- try {
306- $Result = Invoke-RestMethod - WebSession $Server.Session - Method $Method - Uri $Uri - Headers $Server.Headers - Body $Body - ContentType " application/json"
307- }
308- catch {
309- $ResponseBody = ParseExceptionBody $_.Exception.Response
310- Write-Error " $Method to $Uri failed with Exception $ ( $_.Exception.Message ) `n $responseBody "
318+ else {
319+ if ($Quota ) {
320+ $Body = @"
321+ {
322+ "name": "$Name ",
323+ "capabilities": [ $Capabilities ]
324+ "policy": {
325+ "useAccountIdentitySource": $UseAccountIdentitySource ,
326+ "quotaObjectBytes": $Quota
327+ },
328+ "password": "$Password "
329+ }
330+ "@
331+ else {
332+ $Body = @"
333+ {
334+ "name": "$Name ",
335+ "capabilities": [ $Capabilities ]
336+ "policy": {
337+ "useAccountIdentitySource": $UseAccountIdentitySource
338+ },
339+ "password": "$Password "
340+ }
341+ "@
311342 }
312-
313- Write-Output $Result.data
314343 }
344+
345+ try {
346+ $Result = Invoke-RestMethod - WebSession $Server.Session - Method $Method - Uri $Uri - Headers $Server.Headers - Body $Body - ContentType " application/json"
347+ }
348+ catch {
349+ $ResponseBody = ParseExceptionBody $_.Exception.Response
350+ Write-Error " $Method to $Uri failed with Exception $ ( $_.Exception.Message ) `n $responseBody "
351+ }
352+
353+ Write-Output $Result.data
315354 }
316355}
317356
0 commit comments