public/Get-AppVentiXLicence.ps1
<#
.SYNOPSIS Retrieves the details of the AppVentiX license. .DESCRIPTION The Get-AppVentiXLicence function retrieves the details of the AppVentiX license. It can retrieve the license details from a specified license file or from the default configuration share. .PARAMETER ConfigShare Specifies the path to the AppVentiX configuration share. You can omit this parameter if Set-AppVentiXConfigShare has been called. .EXAMPLE Get-AppVentiXLicence -ConfigShare "\\server\share" Retrieves the license details from the specified configuration share. .EXAMPLE Get-AppVentiXLicence -Filename "C:\Path\To\AppVentiX.lic" Retrieves the license details from the specified license file. .NOTES Function : Get-AppVentiXLicence Author : John Billekens Copyright: Copyright (c) AppVentiX Version : 1.0 #> function Get-AppVentiXLicence { [CmdletBinding(DefaultParameterSetName = 'ConfigShare')] param ( [Alias('File', 'License')] [Parameter(Mandatory, ParameterSetName = 'License')] [ValidateScript({ try { if ((Test-Path -Path "$_") -and [String]$_ -like "*AppVentiX.lic") { $true } else { Throw [System.Management.Automation.ItemNotFoundException] "The parameter must be a valid AppVentiX.lic file!" } } catch { Throw [System.Management.Automation.ItemNotFoundException] "The parameter must be a valid AppVentiX.lic file!" } })] [System.IO.FileInfo]$Filename, [Parameter(ParameterSetName = 'ConfigShare')] [String]$ConfigShare = $Script:AppVentix.ConfigShare ) if ($PsCmdlet.ParameterSetName -eq 'ConfigShare') { if (Test-Path -Path $ConfigShare) { [System.IO.FileInfo]$Filename = Join-Path -Path $ConfigShare -ChildPath "AppVentiX.lic" if ([String]::IsNullOrEmpty($ConfigShare)) { Write-Warning "Config share not defined!" return $null } elseif (-Not (Test-Path -Path $Filename)) { Write-Warning "Could not read the license file 'AppVentiX.lic'!" return $null } } elseif ([String]::IsNullOrEmpty($ConfigShare)) { Write-Warning "Config share not defined!" return $null } else { Write-Warning "Could not access the config share `"$ConfigShare`"!" return $null } } try { $licenseDetails = Get-Content -Path $Filename | ConvertFrom-Json -ErrorAction SilentlyContinue | Select-Object -Property LicensedTo, Email, LicensedOn, LicensedUntil, Type, LicensedMachines, OrderNo $licenseDetails.LicensedUntil = [datetime]::Parse($licenseDetails.LicensedUntil) $licenseDetails.LicensedOn = [datetime]::Parse($licenseDetails.LicensedOn) if ($licenseDetails.LicensedTo -like 'Trial') { Write-Warning "AppVentiX is running in trial mode. The trial will expire on $($licenseDetails.LicensedUntil.ToString("M/d/yyyy"))." } } catch { Throw "Could not read the license file 'AppVentiX.lic'!" } return $licenseDetails } |