-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
252 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<# | ||
Copyright 2017 Ryan Butler | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
#> | ||
function Get-NSCurrentTime { | ||
<# | ||
.SYNOPSIS | ||
Retrieve the current NetScaler Time and returns as date object | ||
.DESCRIPTION | ||
Retrieve the current NetScaler Time and returns as date object | ||
.PARAMETER Session | ||
An existing custom NetScaler Web Request Session object returned by Connect-NSAppliance | ||
.EXAMPLE | ||
Get-NSCurrentTime -Session $Session | ||
.NOTES | ||
Author: Ryan Butler - @ryan_c_butler | ||
Date Created: 09-07-2017 | ||
#> | ||
[CmdletBinding()] | ||
param ( | ||
$Session = $Script:Session | ||
) | ||
|
||
begin { | ||
_AssertSessionActive | ||
} | ||
|
||
process { | ||
$response = _InvokeNSRestApi -Session $Session -Method GET -Type nsconfig | ||
$currentdatestr = $response.nsconfig.systemtime | ||
Write-Verbose "systemtime: $currentdatestr" | ||
$date = Get-Date -Date '1/1/1970' | ||
$nsdate = $date.AddSeconds($currentdatestr) | ||
$nsdate | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
<# | ||
Copyright 2017 Ryan Butler | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
#> | ||
|
||
function Get-NSLicenseExpiration { | ||
<# | ||
.SYNOPSIS | ||
Grabs Netscaler license expiration information via REST | ||
.DESCRIPTION | ||
Grabs Netscaler license expiration information via REST. | ||
.PARAMETER Session | ||
An existing custom NetScaler Web Request Session object returned by Connect-NSAppliance | ||
.EXAMPLE | ||
Get-NSlicenseExpiration -Session $Session | ||
.NOTES | ||
Author: Ryan Butler - @ryan_c_butler | ||
Date Created: 09-07-2017 | ||
#> | ||
[CmdletBinding()] | ||
param ( | ||
$Session = $Script:Session | ||
) | ||
|
||
begin{ | ||
_AssertSessionActive | ||
# Grabs current time from Netscaler | ||
$currentnstime = Get-NSCurrentTime -Session $Session | ||
$results = @() | ||
} | ||
|
||
process { | ||
try { | ||
$lics = Get-NSSystemFile -Session $Session -Filelocation '/nsconfig/license' | Where-Object {$_.filename -like '*.lic'} | ||
} catch{ | ||
throw 'Error reading license(s)' | ||
} | ||
|
||
foreach ($lic in $lics) { | ||
Write-verbose "Reading [$($lic.filename)]" | ||
|
||
# Converts returned value from BASE64 to UTF8 | ||
$lic = Get-NSSystemFile -Session $Session -Filelocation '/nsconfig/license' -Filename $lic.filename | ||
$info = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($lic.filecontent)) | ||
|
||
# Grabs needed line that has licensing information | ||
$lines = $info.Split("`n") | Where-Object {$_ -like '*INCREMENT*'} | ||
|
||
# Parses needed date values from string | ||
$licdates = @() | ||
foreach ($line in $lines) { | ||
$licdate = $line.Split() | ||
|
||
if ($licdate[4] -like 'permanent') { | ||
$expire = 'PERMANENT' | ||
} else { | ||
$expire = [datetime]$licdate[4] | ||
} | ||
|
||
# Adds date to object | ||
$temp = [pscustomobject]@{ | ||
expdate = $expire | ||
feature = $licdate[1] | ||
} | ||
$licdates += $temp | ||
} | ||
|
||
foreach ($date in $licdates) { | ||
if ($date.expdate -like 'PERMANENT') { | ||
$expires = 'PERMANENT' | ||
$span = '9999' | ||
} else { | ||
$expires = ($date.expdate).ToShortDateString() | ||
$span = (New-TimeSpan -Start $currentnstime -End $date.expdate).Days | ||
} | ||
|
||
$temp = [pscustomobject]@{ | ||
Expires = $expires | ||
Feature = $date.feature | ||
DaysLeft = $span | ||
LicenseFile = $lic.filename | ||
} | ||
$results += $temp | ||
} | ||
} | ||
|
||
$results | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<# | ||
Copyright 2017 Ryan Butler | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
#> | ||
|
||
function Update-NSAppliance { | ||
<# | ||
.SYNOPSIS | ||
Updates a Netscaler and uses firmware from a remote location. | ||
.DESCRIPTION | ||
Updates a Netscaler and uses firmware from a remote location. | ||
.PARAMETER Session | ||
An existing custom NetScaler Web Request Session object returned by Connect-NSAppliance | ||
.PARAMETER Url | ||
URL for Netscaler firmware (MANDATORY) | ||
.PARAMETER NoReboot | ||
Don't reboot after upgrade | ||
.PARAMETER NoCallhome | ||
Don't enable CallHome | ||
.EXAMPLE | ||
Update-NSAppliance -Session $Session -url "https://mywebserver/build-11.1-47.14_nc.tgz" | ||
.NOTES | ||
Author: Ryan Butler - @ryan_c_butler | ||
Date Created: 09-07-2017 | ||
Will probably fail with VPX Express due to API timeout | ||
#> | ||
[CmdletBinding()] | ||
param ( | ||
[Parameter(Mandatory = $true)] | ||
[string]$Url, | ||
|
||
$Session = $Script:Session, | ||
|
||
[switch]$NoReboot, | ||
|
||
[switch]$NoCallhome | ||
) | ||
|
||
begin { | ||
_AssertSessionActive | ||
} | ||
|
||
process { | ||
if (-not $nocallhome) { | ||
Write-Verbose -Message 'Enabling callhome' | ||
$ch = $true | ||
} else { | ||
Write-Verbose -Message 'Disabling callhome' | ||
$ch = $false | ||
} | ||
|
||
if (-not $NoReboot) { | ||
Write-Verbose -Message 'Rebooting NS Appliance' | ||
$reboot = $true | ||
} else { | ||
Write-Verbose -Message 'Skipping reboot' | ||
$reboot = $false | ||
} | ||
|
||
# Build upgrade payload | ||
$payload = @{ | ||
'url' = $Url | ||
'y' = $reboot | ||
'l' = $ch | ||
} | ||
|
||
# Attempt upgrade | ||
try { | ||
_InvokeNSRestApi -Session $Session -Method POST -Type install -Payload $payload | ||
} catch{ | ||
throw $_ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters