@@ -14,102 +14,88 @@ See the License for the specific language governing permissions and
1414limitations under the License.
1515#>
1616
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- }
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 Session
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+ $Session = $Script :Session
34+ )
4235
43- process {
44-
45- try {
46- $lics = Get-NSSystemFile - Session $Session - filelocation " /nsconfig/license" | Where-Object {$_.filename -like " *.lic" }
36+ begin {
37+ _AssertSessionActive
38+ # Grabs current time from Netscaler
39+ $currentnstime = Get-NSCurrentTime - Session $Session
40+ $results = @ ()
4741 }
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
42+
43+ process {
44+ try {
45+ $lics = Get-NSSystemFile - Session $Session - Filelocation ' /nsconfig/license' | Where-Object {$_.filename -like ' *.lic' }
46+ } catch {
47+ throw ' Error reading license(s)'
8448 }
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
49+
50+ foreach ($lic in $lics ) {
51+ Write-verbose " Reading [$ ( $lic.filename ) ]"
52+
53+ # Converts returned value from BASE64 to UTF8
54+ $lic = Get-NSSystemFile - Session $Session - Filelocation ' /nsconfig/license' - Filename $lic.filename
55+ $info = [System.Text.Encoding ]::UTF8.GetString([System.Convert ]::FromBase64String($lic.filecontent ))
56+
57+ # Grabs needed line that has licensing information
58+ $lines = $info.Split (" `n " ) | Where-Object {$_ -like ' *INCREMENT*' }
59+
60+ # Parses needed date values from string
61+ $licdates = @ ()
62+ foreach ($line in $lines ) {
63+ $licdate = $line.Split ()
64+
65+ if ($licdate [4 ] -like ' permanent' ) {
66+ $expire = ' PERMANENT'
67+ } else {
68+ $expire = [datetime ]$licdate [4 ]
69+ }
70+
71+ # Adds date to object
72+ $temp = [pscustomobject ]@ {
73+ expdate = $expire
74+ feature = $licdate [1 ]
75+ }
76+ $licdates += $temp
9777 }
98-
99- $temp = New-Object PSObject - Property @ {
100- Expires = $expires
101- Feature = $date.feature
102- DaysLeft = $span
103- LicenseFile = $lic.filename
78+
79+ foreach ($date in $licdates ) {
80+ if ($date.expdate -like ' PERMANENT' ) {
81+ $expires = ' PERMANENT'
82+ $span = ' 9999'
83+ } else {
84+ $expires = ($date.expdate ).ToShortDateString()
85+ $span = (New-TimeSpan - Start $currentnstime - End $date.expdate ).Days
10486 }
105- $results += $temp
106- }
107-
108- }
109- }
11087
111- end {
112- return $results
88+ $temp = [pscustomobject ]@ {
89+ Expires = $expires
90+ Feature = $date.feature
91+ DaysLeft = $span
92+ LicenseFile = $lic.filename
93+ }
94+ $results += $temp
95+ }
96+ }
97+
98+ $results
11399 }
114100}
115101
0 commit comments