Skip to content

Commit 1692342

Browse files
authored
Merge pull request #83 from ryancbutler/master
Function adds for #82
2 parents 381b2e1 + 506190a commit 1692342

File tree

6 files changed

+244
-4
lines changed

6 files changed

+244
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11

2+
## 1.X.0 (Unreleased)
3+
* Features
4+
* PR82 - Added Get-NSCurrentTime, Get-NSlicenseExpiration, and Update-NSAppliance functions (via @ryancbutler)
5+
26
## 1.5.0 (2017-07-25)
37
* Features
48
* PR57 - Added -Graceful parameter to the Disable-NSLBServer (via @daimhin)

NetScaler/NetScaler.psd1

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ FunctionsToExport = @(
111111
'Get-NSCSPolicy',
112112
'Get-NSCSVirtualServer',
113113
'Get-NSCSVirtualServerResponderPolicyBinding',
114+
'Get-NSCurrentTime',
114115
'Get-NSDnsNameServer',
115116
'Get-NSDnsSuffix',
116117
'Get-NSFeature',
@@ -137,6 +138,7 @@ FunctionsToExport = @(
137138
'Get-NSLBVirtualServerTrafficPolicyBinding',
138139
'Get-NSLDAPAuthenticationPolicy',
139140
'Get-NSLDAPAuthenticationServer',
141+
'Get-NSLicenseExpiration',
140142
'Get-NSMode',
141143
'Get-NSNTPServer',
142144
'Get-NSResponderAction',
@@ -209,7 +211,8 @@ FunctionsToExport = @(
209211
'Set-NSResponderAction',
210212
'Set-NSSSLProfile',
211213
'Set-NSTimeZone',
212-
'Set-NSVPNVirtualServerTheme'
214+
'Set-NSVPNVirtualServerTheme',
215+
'Update-NSAppliance'
213216
)
214217

215218
# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
@@ -269,5 +272,5 @@ PrivateData = @{
269272

270273
}
271274

272-
273-
275+
276+
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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+
function Get-NSCurrentTime {
17+
<#
18+
.SYNOPSIS
19+
Retrieve the current NetScaler Time and returns as date object
20+
.DESCRIPTION
21+
Retrieve the current NetScaler Time and returns as date object
22+
.PARAMETER Session
23+
An existing custom NetScaler Web Request Session object returned by Connect-NSAppliance
24+
.EXAMPLE
25+
Get-NSCurrentTime -Session $Session
26+
.NOTES
27+
Author: Ryan Butler - @ryan_c_butler
28+
Date Created: 09-07-2017
29+
#>
30+
[CmdletBinding()]
31+
param (
32+
$Session = $Script:Session
33+
)
34+
35+
begin {
36+
_AssertSessionActive
37+
}
38+
39+
process {
40+
$response = _InvokeNSRestApi -Session $Session -Method GET -Type nsconfig
41+
$currentdatestr = $response.nsconfig.systemtime
42+
Write-Verbose "systemtime: $currentdatestr"
43+
$date = Get-Date -Date '1/1/1970'
44+
$nsdate = $date.AddSeconds($currentdatestr)
45+
$nsdate
46+
}
47+
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
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 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+
)
35+
36+
begin{
37+
_AssertSessionActive
38+
# Grabs current time from Netscaler
39+
$currentnstime = Get-NSCurrentTime -Session $Session
40+
$results = @()
41+
}
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)'
48+
}
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
77+
}
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
86+
}
87+
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
99+
}
100+
}
101+
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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 Update-NSAppliance {
18+
<#
19+
.SYNOPSIS
20+
Updates a Netscaler and uses firmware from a remote location.
21+
.DESCRIPTION
22+
Updates a Netscaler and uses firmware from a remote location.
23+
.PARAMETER Session
24+
An existing custom NetScaler Web Request Session object returned by Connect-NSAppliance
25+
.PARAMETER Url
26+
URL for Netscaler firmware (MANDATORY)
27+
.PARAMETER NoReboot
28+
Don't reboot after upgrade
29+
.PARAMETER NoCallhome
30+
Don't enable CallHome
31+
.EXAMPLE
32+
Update-NSAppliance -Session $Session -url "https://mywebserver/build-11.1-47.14_nc.tgz"
33+
.NOTES
34+
Author: Ryan Butler - @ryan_c_butler
35+
Date Created: 09-07-2017
36+
Will probably fail with VPX Express due to API timeout
37+
#>
38+
[CmdletBinding()]
39+
param (
40+
[Parameter(Mandatory = $true)]
41+
[string]$Url,
42+
43+
$Session = $Script:Session,
44+
45+
[switch]$NoReboot,
46+
47+
[switch]$NoCallhome
48+
)
49+
50+
begin {
51+
_AssertSessionActive
52+
}
53+
54+
process {
55+
if (-not $nocallhome) {
56+
Write-Verbose -Message 'Enabling callhome'
57+
$ch = $true
58+
} else {
59+
Write-Verbose -Message 'Disabling callhome'
60+
$ch = $false
61+
}
62+
63+
if (-not $NoReboot) {
64+
Write-Verbose -Message 'Rebooting NS Appliance'
65+
$reboot = $true
66+
} else {
67+
Write-Verbose -Message 'Skipping reboot'
68+
$reboot = $false
69+
}
70+
71+
# Build upgrade payload
72+
$payload = @{
73+
'url' = $Url
74+
'y' = $reboot
75+
'l' = $ch
76+
}
77+
78+
# Attempt upgrade
79+
try {
80+
_InvokeNSRestApi -Session $Session -Method POST -Type install -Payload $payload
81+
} catch{
82+
throw $_
83+
}
84+
}
85+
}

Tests/Meta/Help.tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Get module commands
44
# Remove all versions of the module from the session. Pester can't handle multiple versions.
55
Get-Module $env:BHProjectName | Remove-Module
6-
Import-Module $env:BHPSModulePath -Verbose:$false -ErrorAction Stop
6+
Import-Module $env:BHModulePath -Verbose:$false -ErrorAction Stop
77
$moduleVersion = (Test-ModuleManifest $env:BHPSModuleManifest | select -ExpandProperty Version).ToString()
88
$ms = [Microsoft.PowerShell.Commands.ModuleSpecification]@{ ModuleName = $env:BHProjectName; RequiredVersion = $moduleVersion }
99
$commands = Get-Command -FullyQualifiedModule $ms -CommandType Cmdlet, Function, Workflow # Not alias

0 commit comments

Comments
 (0)