|
| 1 | +<# |
| 2 | +Copyright 2017 Ryan Butler |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +#> |
| 16 | + |
| 17 | +function Get-NSlicenseExpiration { |
| 18 | +<# |
| 19 | +.SYNOPSIS |
| 20 | + Grabs Netscaler license expiration information via REST |
| 21 | +.DESCRIPTION |
| 22 | + Grabs Netscaler license expiration information via REST. |
| 23 | +.PARAMETER NSSession |
| 24 | + An existing custom NetScaler Web Request Session object returned by Connect-NSAppliance |
| 25 | +.EXAMPLE |
| 26 | + Get-NSlicenseExpiration -Session $Session |
| 27 | +.NOTES |
| 28 | + Author: Ryan Butler - @ryan_c_butler |
| 29 | + Date Created: 09-07-2017 |
| 30 | +#> |
| 31 | +[CmdletBinding()] |
| 32 | +param ( |
| 33 | +[Parameter(Mandatory=$true)] [PSObject]$Session |
| 34 | +) |
| 35 | + |
| 36 | +begin{ |
| 37 | + _AssertSessionActive |
| 38 | + #Grabs current time from Netscaler |
| 39 | + $currentnstime = Get-NSCurrentTime -Session $Session |
| 40 | + $results = @() |
| 41 | +} |
| 42 | + |
| 43 | +process { |
| 44 | + |
| 45 | + try { |
| 46 | + $lics = Get-NSSystemFile -Session $Session -filelocation "/nsconfig/license"|Where-Object {$_.filename -like "*.lic"} |
| 47 | + } |
| 48 | + Catch{ |
| 49 | + throw "Error reading license(s)" |
| 50 | + } |
| 51 | + |
| 52 | + foreach ($lic in $lics) |
| 53 | + { |
| 54 | + Write-verbose "Reading $($lic.filename)" |
| 55 | + |
| 56 | + #Converts returned value from BASE64 to UTF8 |
| 57 | + $lic = Get-NSSystemFile -Session $Session -filelocation "/nsconfig/license" -filename $lic.filename |
| 58 | + $info = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($lic.filecontent)) |
| 59 | + |
| 60 | + #Grabs needed line that has licensing information |
| 61 | + $lines = $info.Split("`n")|where-object{$_ -like "*INCREMENT*"} |
| 62 | + |
| 63 | + #Parses needed date values from string |
| 64 | + $licdates = @() |
| 65 | + foreach ($line in $lines) |
| 66 | + { |
| 67 | + $licdate = $line.Split() |
| 68 | + |
| 69 | + if ($licdate[4] -like "permanent") |
| 70 | + { |
| 71 | + $expire = "PERMANENT" |
| 72 | + } |
| 73 | + else |
| 74 | + { |
| 75 | + $expire = [datetime]$licdate[4] |
| 76 | + } |
| 77 | + |
| 78 | + #adds date to object |
| 79 | + $temp = New-Object PSObject -Property @{ |
| 80 | + expdate = $expire |
| 81 | + feature = $licdate[1] |
| 82 | + } |
| 83 | + $licdates += $temp |
| 84 | + } |
| 85 | + |
| 86 | + foreach ($date in $licdates) |
| 87 | + { |
| 88 | + if ($date.expdate -like "PERMANENT") |
| 89 | + { |
| 90 | + $expires = "PERMANENT" |
| 91 | + $span = "9999" |
| 92 | + } |
| 93 | + else |
| 94 | + { |
| 95 | + $expires = ($date.expdate).ToShortDateString() |
| 96 | + $span = (New-TimeSpan -Start $currentnstime -end ($date.expdate)).days |
| 97 | + } |
| 98 | + |
| 99 | + $temp = New-Object PSObject -Property @{ |
| 100 | + Expires = $expires |
| 101 | + Feature = $date.feature |
| 102 | + DaysLeft = $span |
| 103 | + LicenseFile = $lic.filename |
| 104 | + } |
| 105 | + $results += $temp |
| 106 | + } |
| 107 | + |
| 108 | + } |
| 109 | +} |
| 110 | + |
| 111 | +end{ |
| 112 | + return $results |
| 113 | + } |
| 114 | +} |
| 115 | + |
0 commit comments