diff --git a/Modules/Commvault.CommCell/Commvault.CommCell.psd1 b/Modules/Commvault.CommCell/Commvault.CommCell.psd1 index 932a74a..fcef47d 100644 Binary files a/Modules/Commvault.CommCell/Commvault.CommCell.psd1 and b/Modules/Commvault.CommCell/Commvault.CommCell.psd1 differ diff --git a/Modules/Commvault.CommCell/Commvault.CommCell.psm1 b/Modules/Commvault.CommCell/Commvault.CommCell.psm1 index e7db652..cddf1c5 100644 --- a/Modules/Commvault.CommCell/Commvault.CommCell.psm1 +++ b/Modules/Commvault.CommCell/Commvault.CommCell.psm1 @@ -418,6 +418,250 @@ function Get-CVClient { } +function Get-CVClientLicense { +<# +.SYNOPSIS + Method to get licenses for a client. +.DESCRIPTION + Method to get licenses for a client. +.PARAMETER Name + Get licenses on client specified by Name. +.PARAMETER Id + Get licenses on client specified by Id. +.EXAMPLE + Get-CVClientLicences -Name 'carbonwincs1' +.OUTPUTS + [PsCustomObject] containing details of the license and the plaform type +.NOTES + Author: Craig Tolley + Based on API Documentation at https://documentation.commvault.com/commvault/v11/article?p=47685.htm +#> + [CmdletBinding(DefaultParameterSetName = 'ByName')] + [OutputType([PSCustomObject])] + param( + [Alias('Client')] + [Parameter(Mandatory = $True, ParameterSetName = 'ByName', ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True)] + [ValidateNotNullorEmpty()] + [String] $Name, + + [Alias('ClientId')] + [Parameter(Mandatory = $True, ParameterSetName = 'ById', ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True)] + [ValidateNotNullorEmpty()] + [Int32] $Id + ) + + begin { Write-Debug -Message "$($MyInvocation.MyCommand): begin" + + try { + $sessionObj = Get-CVSessionDetail $MyInvocation.MyCommand.Name + $endpointSave = $sessionObj.requestProps.endpoint + } + catch { + throw $_ + } + } + + process { Write-Debug -Message "$($MyInvocation.MyCommand): process" + + try { + $sessionObj.requestProps.endpoint = $endpointSave + + if ($PSCmdlet.ParameterSetName -eq 'ByName') { + $clientObj = (Get-CVClient -Name $Name) + if ($null -ne $clientObj) { + $Id = $clientObj.clientId + } + else { + Write-Information -InformationAction Continue -MessageData "INFO: $($MyInvocation.MyCommand): client not found having name [$Name]" + return + } + } + + $sessionObj.requestProps.endpoint = $sessionObj.requestProps.endpoint -creplace ('{clientId}', $Id) + $headerObj = Get-CVRESTHeader $sessionObj + + $body = '' + $payload = @{ } + $payload.Add('headerObject', $headerObj) + $payload.Add('body', $body) + $validate = 'licensesInfo' + + $response = Submit-CVRESTRequest $payload $validate + + if ($response.IsValid) { + Write-Output $response.Content.licensesInfo + } + + else { + Write-Information -InformationAction Continue -MessageData "INFO: $($MyInvocation.MyCommand): license information not found for client Id [$Id]" + } + + } + catch { + throw $_ + } + } + + end { Write-Debug -Message "$($MyInvocation.MyCommand): end" + } +} + + +function Revoke-CVClientLicense { +<# +.SYNOPSIS + Method to release licenses from a client. +.DESCRIPTION + Method to release licenses from a client. +.PARAMETER Name + Release licenses on client specified by Name. +.PARAMETER Id + Release licenses on client specified by Id. +.PARAMETER LicensesToRelease + Collection of licenses to release. Details of licenses and format can be found from running Get-CVClientLicense +.PARAMETER Force + Switch to Force override of default 'WhatIf' confirmation behavior. +.EXAMPLE + $licenses = Get-CVClientLicences -Name 'carbonwincs1' + Revoke-CvClientLicenses -Name 'carbonwincs1' -LicensesToRelease $licenses +.PARAMETER Force + Switch to Force override of default 'WhatIf' confirmation behavior. +.OUTPUTS + Outputs errorMessage and errorCode. Error code 0 is success. +.NOTES + Author: Craig Tolley + Based on API Documentation at https://documentation.commvault.com/commvault/v11/article?p=92013.htm +#> + [CmdletBinding(DefaultParameterSetName = 'ByName', SupportsShouldProcess = $True, ConfirmImpact = 'High')] + Param ( + [Alias('Client')] + [Parameter(Mandatory = $True, ParameterSetName = 'ByName', ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True)] + [ValidateNotNullorEmpty()] + [String] $Name, + + [Alias('ClientId')] + [Parameter(Mandatory = $True, ParameterSetName = 'ById', ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True)] + [ValidateNotNullorEmpty()] + [Int32] $Id, + + [Parameter(Mandatory = $True, ParameterSetName = 'ByName')] + [Parameter(Mandatory = $True, ParameterSetName = 'ById')] + [System.Object] $LicensesToRelease, + + [switch]$Force + ) + + begin { Write-Debug -Message "$($MyInvocation.MyCommand): begin" + + try { + $sessionObj = Get-CVSessionDetail $MyInvocation.MyCommand.Name + $endpointSave = $sessionObj.requestProps.endpoint + } + catch { + throw $_ + } + } + + process { Write-Debug -Message "$($MyInvocation.MyCommand): process" + + try { + $sessionObj.requestProps.endpoint = $endpointSave + + if ($PSCmdlet.ParameterSetName -eq 'ById' ) { + $sessionObj.requestProps.endpoint = $sessionObj.requestProps.endpoint -creplace ('{clientId}', $Id) + } + else { + $clientObj = Get-CVClient -Name $Name + if ($null -eq $clientObj) { + Write-Information -InformationAction Continue -MessageData "INFO: $($MyInvocation.MyCommand): client not found having name [$Name]" + return + } + $Id = $clientObj.clientId + } + + <# + { + "isClientLevelOperation": true, + "licensesInfo": [{ + "platformType": 1, + "license": { + "appType": 33, + "licenseName": "Server File System - Windows File System" + } + }], + "clientEntity": { + "clientId": "client001" + } + } + #> + + $body = @{} + + $client = @{} + $client.Add('clientId', $Id) + $body.Add('clientEntity', $client) + + $licensesinfos = @() + ForEach ($l in $LicensesToRelease) { + $licenseinfo = @{} + $licenseinfo.Add("platformType",$LicensesToRelease.platformType) + + $license = @{} + $license.Add("appType",$l.license.appType) + $license.Add("licenseName",$l.license.licenseName) + $licenseinfo.Add("license",$license) + + $licensesinfos += $licenseinfo + } + + $body.Add("licensesInfo",$licensesinfos) + $body = ($body | ConvertTo-Json -Depth 10) + + $headerObj = Get-CVRESTHeader $sessionObj + $payload = @{ } + $payload.Add('headerObject', $headerObj) + $payload.Add('body', $body) + $validate = 'errorCode' + $body + if ($PSCmdlet.ParameterSetName -eq 'ById' ) { + if ($Force -or $PSCmdlet.ShouldProcess($Id)) { + $response = Submit-CVRESTRequest $payload $validate + } + else { + $response = Submit-CVRESTRequest $payload $validate -DryRun + } + } + else { + if ($Force -or $PSCmdlet.ShouldProcess($clientObj.clientName)) { + $response = Submit-CVRESTRequest $payload $validate + } + else { + $response = Submit-CVRESTRequest $payload $validate -DryRun + } + } + + if ($response.IsValid) { + Write-Output $response.Content + } + else { + if ($PSCmdlet.ParameterSetName -eq 'ById' ) { + Write-Information -InformationAction Continue -MessageData "INFO: $($MyInvocation.MyCommand): release client license request failed for client id[$Id]" + } + else { + Write-Information -InformationAction Continue -MessageData "INFO: $($MyInvocation.MyCommand): release client license request failed for client name [$($clientObj.clientName)]" + } + } + } + catch { + throw $_ + } + } + + end { Write-Debug -Message "$($MyInvocation.MyCommand): end" + } +} + + function Get-CVClientGroup { <# .SYNOPSIS diff --git a/Modules/Commvault.RESTSession/Commvault.RESTSession.psd1 b/Modules/Commvault.RESTSession/Commvault.RESTSession.psd1 index 7f0730c..5ea1b4d 100644 Binary files a/Modules/Commvault.RESTSession/Commvault.RESTSession.psd1 and b/Modules/Commvault.RESTSession/Commvault.RESTSession.psd1 differ diff --git a/Modules/Commvault.RESTSession/Commvault.RESTSession.psm1 b/Modules/Commvault.RESTSession/Commvault.RESTSession.psm1 index f51aace..b0687ef 100644 --- a/Modules/Commvault.RESTSession/Commvault.RESTSession.psm1 +++ b/Modules/Commvault.RESTSession/Commvault.RESTSession.psm1 @@ -661,6 +661,25 @@ function GetAPIDetail ([String] $Request) { } + 'Get-CVClientLicense' = @{ + + + Description = 'Get client licenses from CommServe' + Endpoint = 'Client/{clientId}/License' + Method = 'Get' + Body = '' + + } + + 'Revoke-CVClientLicense' = @{ + + Description = 'Release a license from a client' + Endpoint = 'Client/License/Release' + Method = 'Post' + Body = '' + + } + 'Add-CVClientGroup' = @{ Description = 'Add new client group on CommServe' diff --git a/README.md b/README.md index f22d45d..26a6b63 100644 --- a/README.md +++ b/README.md @@ -44,9 +44,11 @@ Sample Package Function Table ----------------------------- - Function: Get-CVClient in Module: Commvault.CommCell - Function: Get-CVClientGroup in Module: Commvault.CommCell +- Function: Get-CVClientLicense in Module: Commvault.CommCell - Function: Get-CVVersionInfo in Module: Commvault.CommCell - Function: Get-CVAlert in Module: Commvault.CommCell - Function: Get-CVSubclient in Module: Commvault.CommCell +- Function: Revoke-CVClientLicense in Module: Commvault.CommCell - Function: Set-CVClient in Module: Commvault.CommCell - Function: Set-CVClientGroup in Module: Commvault.CommCell - Function: Backup-CVClientFileSystem in Module: Commvault.FileSystem