
RRAS – Always On VPN – Stats Remotely
I have done few Microsoft Always On VPN deployments from start to finish and every time I am being asked for any Reporting tool for RRAS or Always-on VPN. And every time I had to say that there is no real remote or central facility where BAU can get data.
Sadly, BAU engineers need to login to each RRAS Server to get reports. Yes, there are some tools which provide stats, but those tools rely on feeding data or providing log files to them.
Basically the script will provide configuration details of the RRAS server as well as connection statistics. Management always needs some numbers to report on. Some of the VPN deployments are simple where only a couple of RRAS servers are active, but when you are dealing with multiple RRAS servers then it is very important that you can get results remotely.
Following Commands are configured in the script
Get-RemoteAccess – Displays the configuration of DirectAccess (DA) and VPN (both Remote Access VPN and site-to-site VPN).
Get-RemoteAccessAccounting – Displays the accounting configuration for Remote Access, such as the different types of accounting that are enabled and the respective configuration.
Get-RemoteAccessConnectionStatistics – Displays the statistics of real-time, currently active DirectAccess (DA) and VPN connections and the statistics of DA and VPN historical connections for a specified time duration.
Get-RemoteAccessConnectionStatisticsSummary – Displays the summary statistics of real-time, currently active DirectAccess (DA) and VPN connections and the summary statistics of DA and VPN historical connections for a specified time duration.
Get-RemoteAccessHealth – Obtains the current health of a RemoteAccess (RA) deployment.
Get-RemoteAccessRadius – Displays the list of RADIUS servers including RADIUS for VPN authentication, RADIUS for DirectAccess (DA) and VPN Accounting, and RADIUS for one-time password (OTP) authentication for DA.
Get-RemoteAccessUserActivity – Displays the resources accessed over the active DirectAccess (DA) and VPN connections and the resources accessed over historical DA and VPN connections.
So here is my Powershell scripting using Window Forms to provide you with a GUI, which can connect to as many RRAS Servers you like to fetch and provide data centrally.
I have written this script in Powershell and it utilises Window Forms to form a GUI, which makes it easy to select and click etc.

There are two Pre-requisties for this script to work.
Requires – PSRemoting must be enabled on RRAS Server
To Configure – Enable-PSRemoting -Force
Requires – RRAS Servers should be on Trusted List on WSMAN
To Check – “Get-Item WSMan:\localhost\client\trustedhosts
To Configure – Set-Item WSMan:\localhost\Client\TrustedHosts -Value “ServerName01, ServerName02, ServerName03, ServerName04” -Force
Usage: Before you start using and gather information from RRAS Server, you will be prompted to enter details of RRAS Servers and login details.
Password is stored as a secure string in a text file, which is encrypted and decrypted as required by the script. Password is encrypted using the current machine and user, so you cannot just copy and paste to another machine.
Configuration: First Time, you will be prompted to provide some details of the server, you would like to connect.

Once you have provided the details, you can click on “Back to Main Form” to execute commands remotely. Alternatively, when you open the script subsequent times and based on configuration file found, you will automatically go to the execution form.
Screenshots:



Script:
#############################################################################################
#
# Script: Get-AlwaysOnVPN-Stats-GUI.ps1
#
# Author: Harmik Singh Batth
# Website: www.harmikbatth.com
#
# Date: 01/05/2020
#
# About: This script is designed to pull data from different RRAS Servers and present one view.
#
# Usage: To use this script, execute the script and configure VPN Servers initially.
# Next time, you should be able to connect and present data from all configured RRAS Servers.
#
# Requirements:
# Requires - PSRemoting must be enabled on RRAS Server
# To Configure - Enable-PSRemoting -Force
# Requires - RRAS Servers should be on Trusted List on WSMAN
# To Check - "Get-Item WSMan:\localhost\client\trustedhosts
# To Configure - Set-Item WSMan:\localhost\Client\TrustedHosts -Value "ServerName01, ServerName02, ServerName03, ServerName04" -Force
#
# Versions:
# 01/05/2020 - 1.0 - Initial release creation by Harmik Singh Batth
# 13/05/2020 - 1.1 - Added Export Button, which will allow Export of Data to CSV files
#
#############################################################################################
Begin {
cls
#region Calculated Variables
# Different OS versions use different sizes of windows, these corrections allow the form to be correctly sized in any OS.
# Switch -wildcard doesn't work in Powershell 2 so OS version has extra sections removed.
$OSVer = ((Get-WmiObject Win32_OperatingSystem).Version).split(".")[0..1] -join "."
Switch ($OSVer)
{
6.3 {$FormHorizPadding = 21; $FormVertPadding = 43} #Windows 8.1 & Windows Server 2012 R2
6.2 {$FormHorizPadding = 21; $FormVertPadding = 43} #Windows 8 & Windows Server 2012
6.1 {$FormHorizPadding = 10; $FormVertPadding = 29} #Windows 7 & Windows Server 2008 R2
6.0 {$FormHorizPadding = 10; $FormVertPadding = 29} #Windows Vista & Windows Server 2008
5.2 {$FormHorizPadding = 21; $FormVertPadding = 43} #Windows Server 2003
5.1 {$FormHorizPadding = 21; $FormVertPadding = 43} #Windows XP
}
#Check for Configuration Files
$UserLocalAppData = $env:LOCALAPPDATA
$ConfigurationFolder = "$UserLocalAppData\RRASReporting"
$ConfigurationFile = "$ConfigurationFolder\RRAS-Configuration.txt"
$ExportFolder = "$UserLocalAppData\RRASReporting"
$ExportFile = "$ExportFolder\Export.csv"
$Global:ConfigurationUploaded = ""
$Script:TabIndex = 0
#endregion Calculated Variables
# Assemblies
try {
Add-Type -AssemblyName "System.Drawing" -ErrorAction Stop
Add-Type -AssemblyName "System.Windows.Forms" -ErrorAction Stop
}
catch [System.UnauthorizedAccessException] {
Write-Warning -Message "Access denied when attempting to load required assemblies" ;
}
catch [System.Exception] {
Write-Warning -Message "Unable to load required assemblies. Error message: $($_.Exception.Message) Line: $($_.InvocationInfo.ScriptLineNumber)" ;
}
}
Process
{
#region Functions
# Functions
function Load-Form {
$Form.Controls.AddRange(@(
$ComboBoxTypes,
$CheckBoxCurrentData,
$DateTimeStart,
$DateTimeEnd,
$TextBoxUserName,
$LabelDateStart,
$LabelDateEnd,
#$LabelUserName,
$ButtonExecute,
$ButtonExport,
$ButtonConfiguration,
$RadioButtonSelectRRASServer,
$OutputBox,
$DGVResults,
$GBLog,
$GBResults,
$GBRRASServersSelect,
$GBUser,
$GBOptions,
$GBActions,
$GBSettings,
$ButtonConfigExecute,
$ButtonConfigRRASAdd,
$ButtonConfigRRASRemove,
$ButtonConfigBackToMainForm,
$GBConfigActions,
$DGVConfigResults,
$OutputConfigBox,
$LabelRRASServer,
$LabelRRASUsername,
$LabelRRASPassword,
$TextBoxRRASServer,
$TextBoxRRASUsername,
$TextBoxRRASPassword,
$GBConfigLog,
$GBConfigResults,
$GBConfigRRAS,
$StatusBar
))
Try
{
$Form.Add_Shown({$Form.Activate()})
$Form.Add_Shown(
{
if ($Global:ConfigurationUploaded -eq "Success")
{
Write-OutputBox "Configuration File found: $ConfigurationFile, Loading main form" -Type INFO
LoadExecutionForm
}
Else
{
Write-OutputBox "No Configuration File found: $ConfigurationFile, User will be prompted to Create one" -Type WARNING
LoadConfigurationForm
}
}
)
$Form.Add_Closing({CleanUpScript})
$Form.ShowDialog() | Out-Null
}
Catch
{
Write-OutputBox "Script encountered issues " -Type ERROR
}
}
function LoadExecutionForm
{
$RadioButtonSelectRRASServer.Visible=$true
$GBRRASServersSelect.Visible=$true
$ComboBoxTypes.Visible=$true
$CheckBoxCurrentData.Visible=$true
$DateTimeStart.Visible=$true
$DateTimeEnd.Visible=$true
$LabelDateStart.Visible=$true
$LabelDateEnd.Visible=$true
#$LabelUserName.Visible=$true
$GBOptions.Visible=$true
$TextBoxUserName.Visible=$true
$GBUser.Visible=$true
$ButtonExecute.Visible=$true
$ButtonExport.Visible=$true
$GBActions.Visible=$true
$ButtonConfiguration.Visible=$true
$GBSettings.Visible=$true
$DGVResults.Visible=$true
$GBResults.Visible=$true
$OutputBox.Visible=$true
$GBLog.Visible=$true
$LabelRRASServer.Visible=$false
$LabelRRASUsername.Visible=$false
$LabelRRASPassword.Visible=$false
$TextBoxRRASServer.Visible=$false
$TextBoxRRASUsername.Visible=$false
$TextBoxRRASPassword.Visible=$false
$GBConfigRRAS.Visible=$false
$ButtonConfigRRASAdd.Visible=$false
$ButtonConfigRRASRemove.Visible=$false
$ButtonConfigExecute.Visible=$false
$ButtonConfigBackToMainForm.Visible=$false
$GBConfigActions.Visible=$false
$DGVConfigResults.Visible=$false
$GBConfigResults.Visible=$false
$OutputConfigBox.Visible=$false
$GBConfigLog.Visible=$false
if ($Global:ConfigurationUploaded -eq "Success")
{
Load-Connect
}
}
function LoadConfigurationForm
{
$RadioButtonSelectRRASServer.Visible=$false
$GBRRASServersSelect.Visible=$false
$ComboBoxTypes.Visible=$false
$CheckBoxCurrentData.Visible=$false
$DateTimeStart.Visible=$false
$DateTimeEnd.Visible=$false
$LabelDateStart.Visible=$false
$LabelDateEnd.Visible=$false
#$LabelUserName.Visible=$false
$GBOptions.Visible=$false
$TextBoxUserName.Visible=$false
$GBUser.Visible=$false
$ButtonExecute.Visible=$false
$ButtonExport.Visible=$false
$GBActions.Visible=$false
$ButtonConfiguration.Visible=$false
$GBSettings.Visible=$false
$DGVResults.Visible=$false
$GBResults.Visible=$false
$OutputBox.Visible=$false
$GBLog.Visible=$false
$LabelRRASServer.Visible=$true
$LabelRRASUsername.Visible=$true
$LabelRRASPassword.Visible=$true
$TextBoxRRASServer.Visible=$true
$TextBoxRRASUsername.Visible=$true
$TextBoxRRASPassword.Visible=$true
$GBConfigRRAS.Visible=$true
$ButtonConfigRRASAdd.Visible=$true
$ButtonConfigRRASRemove.Visible=$true
$ButtonConfigExecute.Visible=$true
$ButtonConfigBackToMainForm.Visible=$true
$GBConfigActions.Visible=$true
$DGVConfigResults.Visible=$true
$GBConfigResults.Visible=$true
$OutputConfigBox.Visible=$true
$GBConfigLog.Visible=$true
#$TextBoxRRASServer.Focus()
Load-ConnectConfig
}
function CheckConfigurationFile
{
if (test-path -path $ConfigurationFile)
{
Write-OutputBox "Configuration File: $ConfigurationFile found, and will be used to connect to servers" -Type INFO
#Checking Contents of the file, if empty then
if ((Get-Content -Path $ConfigurationFile) -eq $null)
{
Write-OutputBox "No data found in Configuration File: $ConfigurationFile, user will be prompted to re-configure" -Type INFO
$Global:ConfigurationUploaded = ""
}
Else
{
$Global:ConfigurationUploaded = "Success"
}
}
Else
{
Write-OutputBox "No Configuration File: $ConfigurationFile found, user will be prompted to create one." -Type INFO
$Global:ConfigurationUploaded = ""
}
}
function CleanUpScript
{
#Clean Up Variables and PS-Sessions
Try
{
#Dispose PSSessions
Get-PSSession | ? ComputerName -match "vpn" | Remove-PSSession
}
Catch
{
Write-OutputBox "Script encountered issues while removing PS-Sessions" -Type ERROR
}
}
function Invoke-CleanControls {
param(
[parameter(Mandatory=$true)]
[ValidateSet("All","Log")]
$Option
)
if ($Option -eq "All") {
$DGVResults.Rows.Clear()
#Clean Output Box if required
#$OutputBox.ResetText()
}
if ($Option -eq "Log") {
#Clean Output Box if required
#$OutputBox.ResetText()
}
}
function Invoke-CleanConfigControls {
param(
[parameter(Mandatory=$true)]
[ValidateSet("All","Log")]
$Option
)
if ($Option -eq "All") {
$DGVConfigResults.Rows.Clear()
#Clean Output Box if required
#$OutputConfigBox.ResetText()
}
if ($Option -eq "Log") {
#Clean Output Box if required
#$OutputConfigBox.ResetText()
}
}
function ModifyTextBox
{
if ($TextBoxUserName.Text -eq "Enter UserName or DeviceName")
{
$TextBoxUserName.Text = ""
}
Elseif (($TextBoxUserName.Text -eq $null) -or ($TextBoxUserName.Text -eq "") -or ($TextBoxUserName.Text -eq " "))
{
$TextBoxUserName.Text = "Enter UserName or DeviceName"
}
}
function Activate-DateControls
{
if (($ComboBoxTypes.SelectedIndex -eq 2) -or ($ComboBoxTypes.SelectedIndex -eq 3) -or ($ComboBoxTypes.SelectedIndex -eq 6))
{
$CheckBoxCurrentData.Enabled = $true
$DateTimeStart.Enabled = $true
$DateTimeEnd.Enabled = $true
if (($ComboBoxTypes.SelectedIndex -eq 2) -or ($ComboBoxTypes.SelectedIndex -eq 6))
{
$TextBoxUserName.Enabled=$true
}
Else
{
$TextBoxUserName.Enabled=$false
}
}
Else
{
$CheckBoxCurrentData.Enabled = $false
$DateTimeStart.Enabled = $false
$DateTimeEnd.Enabled = $false
$TextBoxUserName.Enabled=$false
}
}
function Activate-CheckBoxControls
{
if ($CheckBoxCurrentData.Checked -eq $false)
{
$DateTimeStart.Enabled = $true
$DateTimeEnd.Enabled = $true
}
Else
{
$DateTimeStart.Enabled = $false
$DateTimeEnd.Enabled = $false
}
}
function Activate-Controls {
#[System.Windows.Forms.Application]::UseWaitCursor = $false
$ButtonExecute.Enabled=$true
$ButtonExport.Enabled=$true
$ButtonConfiguration.Enabled=$true
$ComboBoxTypes.Enabled=$true
Activate-DateControls
Activate-CheckBoxControls
ModifyTextBox
#$RadioButtonSelectRRASServer.Focus()
}
function DeActivate-Controls {
#[System.Windows.Forms.Application]::UseWaitCursor = $true
$ButtonExecute.Enabled=$false
$ButtonExport.Enabled=$false
$ButtonConfiguration.Enabled=$false
$ComboBoxTypes.Enabled=$false
Activate-DateControls
Activate-CheckBoxControls
ModifyTextBox
}
function Write-OutputBox {
param(
[parameter(Mandatory=$true)]
[string]$OutputBoxMessage,
[parameter(Mandatory=$true)]
[ValidateSet("WARNING","ERROR","INFO")]
[string]$Type
)
Begin {
$DateTime = (Get-Date).ToLongTimeString()
}
Process {
if ($OutputBox.Text.Length -eq 0) {
$OutputBox.Text = "$($DateTime) - $($Type): $($OutputBoxMessage)"
[System.Windows.Forms.Application]::DoEvents()
$OutputBox.SelectionStart = $OutputBox.Text.Length
$OutputBox.ScrollToCaret()
}
else {
$OutputBox.AppendText("`n$($DateTime) - $($Type): $($OutputBoxMessage)")
[System.Windows.Forms.Application]::DoEvents()
$OutputBox.SelectionStart = $OutputBox.Text.Length
$OutputBox.ScrollToCaret()
}
}
}
function Write-OutputConfigBox {
param(
[parameter(Mandatory=$true)]
[string]$OutputBoxMessage,
[parameter(Mandatory=$true)]
[ValidateSet("WARNING","ERROR","INFO")]
[string]$Type
)
Begin {
$DateTime = (Get-Date).ToLongTimeString()
}
Process {
if ($OutputConfigBox.Text.Length -eq 0) {
$OutputConfigBox.Text = "$($DateTime) - $($Type): $($OutputBoxMessage)"
[System.Windows.Forms.Application]::DoEvents()
$OutputConfigBox.SelectionStart = $OutputConfigBox.Text.Length
$OutputConfigBox.ScrollToCaret()
}
else {
$OutputConfigBox.AppendText("`n$($DateTime) - $($Type): $($OutputBoxMessage)")
[System.Windows.Forms.Application]::DoEvents()
$OutputConfigBox.SelectionStart = $OutputConfigBox.Text.Length
$OutputConfigBox.ScrollToCaret()
}
}
}
function Connect-RRASServers
{
if (test-path -path $ConfigurationFile)
{
# Get RRAS Servers from the Configuration File
ForEach ($RRASserver in (Get-content -path $ConfigurationFile))
{
$RRASServerDetails = $RRASServer.Split(",")
$RRASserverName = $RRASServerDetails[0]
$RRASLogin = $RRASServerDetails[1]
$RRASPassword = (Get-Content -Path "$UserLocalAppData\RRASreporting\$RRASserverName.txt" | ConvertTo-SecureString)
$LoginUser = "$RRASserverName\$RRASLogin"
$RRASCred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $LoginUser,$RRASPassword
# Connect to RRAS Server
# Check for Variable if already exists, if it does, Then just do the PS-Sessions only.
if (Get-Variable | ? Name -eq $RRASServerName)
{
if (Get-PSSession | ? ComputerName -eq $RRASserverName)
{
Write-OutputBox -OutputBoxMessage "PS-Session for this Host already exists, existing session will be utilised" -Type INFO
}
Else
{
Write-OutputBox -OutputBoxMessage "Initiating connection to RRAS Server: $RRASserverName" -Type INFO
try
{
$RRASserverName = New-PSSession -ComputerName $RRASserverName -Credential $RRASCred
}
catch
{
Write-OutputBox -OutputBoxMessage "Unable to connect to RRAS Server: $RRASserverName" -Type ERROR; break
}
Write-OutputBox -OutputBoxMessage "Successfully connected to RRAS Server: $RRASserverName" -Type INFO
}
}
Else
{
Write-OutputBox -OutputBoxMessage "Initiating connection to RRAS Server: $RRASserverName" -Type INFO
New-Variable -Name $RRASserverName -Scope Global -Value (New-PSSession -ComputerName $RRASserverName -Credential $RRASCred)
}
}
}
Else
{
Write-OutputBox -OutputBoxMessage "No Configuration File found, user will be prompted to create one." -Type WARNING
}
}
function Load-Connect
{
Write-OutputBox -OutputBoxMessage "Connecting to required RRAS Servers" -Type INFO
if ($Global:ConfigurationUploaded -eq "Success")
{
#Deactivate controls while inititaing forms
DeActivate-Controls
#Connect and Create PS-Sessions to RRAS Servers
Connect-RRASServers
#Activate controls as all forms are loaded now
Activate-Controls
}
}
function Load-ConnectConfig
{
Write-OutputConfigBox -OutputBoxMessage "Fetching Details of RRAS Servers" -Type INFO
#Clear Datagrid rows
$DGVConfigResults.Rows.Clear()
#Connect and Create PS-Sessions to RRAS Servers
LoadConfiguration
Write-OutputConfigBox -OutputBoxMessage "Successfully obtained information about RRAS Servers" -Type INFO
}
function Update-StatusBar {
param(
[parameter(Mandatory=$true)]
[ValidateSet("Ready","Updating","Validating","Enumerating")]
[string]$Activity,
[parameter(Mandatory=$true)]
[string]$Text
)
$StatusBarPanelActivity.Text = $Activity
$StatusBarPanelProcessing.Text = $Text
[System.Windows.Forms.Application]::DoEvents()
}
function Get-RRASGeneralInformation {
Process
{
ForEach ($RRASserver in (Get-content -path $configurationfile))
{
$RRASserverDetails = $RRASserver.Split(",")
$RRASserverName = $RRASserverDetails[0]
if (Get-PSSession | ? ComputerName -eq $RRASserverName)
{
Update-StatusBar -Activity Enumerating -Text " "
Update-StatusBar -Activity Validating -Text "Validating connection to $RRASserver"
$script = {Get-RemoteAccess}
$Session = (Get-PSSession | ? Computername -eq "$RRASserverName")
$var = Invoke-Command -Session $Session -ScriptBlock $script
$VpnStatus = $var.VpnStatus
$RoutingStatus = $var.RoutingStatus
$InternetInterface = $var.InternetInterface
$InternalInterface = $var.InternalInterface
$IPAssignmentMethod = $var | Select -ExpandProperty IPAssignmentMethod
$IPAddressRangeList = $var | Select -ExpandProperty IPAddressRangeList
$AuthenticationType = $var.AuthenticationType
$RadiusServerList =""
foreach ($RadiusServer in ($var | Select -ExpandProperty RadiusServerList))
{
$RadiusServerList += "$RadiusServer,"
}
$DGVResults.Rows.Add($RRASserverName,$VpnStatus, $RoutingStatus, $InternetInterface, $InternalInterface, $IPAssignmentMethod, $IPAddressRangeList, $AuthenticationType, $RadiusServerList)
Write-OutputBox -OutputBoxMessage "Successfully collected data from $RRASserver" -Type INFO
[System.Windows.Forms.Application]::DoEvents()
}
else
{
Write-OutputBox -OutputBoxMessage "No data was found" -Type INFO
}
Update-StatusBar -Activity Ready -Text " "
Write-OutputBox -OutputBoxMessage "Completed collecting RRAS General Information data" -Type INFO
}
}
}
function Get-RemoteAccessAccounting
{
Process
{
ForEach ($RRASserver in (Get-content -path $configurationfile))
{
$RRASserverDetails = $RRASserver.Split(",")
$RRASserverName = $RRASserverDetails[0]
if (Get-PSSession | ? ComputerName -eq $RRASserverName)
{
Update-StatusBar -Activity Enumerating -Text " "
Update-StatusBar -Activity Validating -Text "Validating connection to $RRASserver"
$script = {Get-RemoteAccessAccounting}
$var = Invoke-Command -Session (Get-PSSession | ? Computername -eq "$RRASserverName") -ScriptBlock $script
$RadiusAccountingStatus = $var.RadiusAccountingStatus
$RadiusServerList =""
foreach ($RadiusServer in ($var | Select -ExpandProperty RemoteRadiusServerList))
{
$RadiusServerList += "$RadiusServer,"
}
$RemoteRadiusServerList = $RadiusServerList
$InboxAccountingStatus = $var.InboxAccountingStatus
$InboxStoreLimit = $var.InboxStoreLimit
$InboxStoreUsedBytes = [math]::round($var.InboxStoreUsedBytes/1GB, 2)
$InboxStoreUsedBytesInPercentage = ($var.InboxStoreUsedBytesInPercentage/100).ToString("P")
$InboxStoreFreeBytes = [math]::round($var.InboxStoreFreeBytes/1GB, 2)
$InboxStoreFreeBytesInPercentage = ($var.InboxStoreFreeBytesInPercentage/100).ToString("P")
$InboxStoreFirstRecordDate = $var.InboxStoreFirstRecordDate
$InboxStoreLastRecordDate = $var.InboxStoreLastRecordDate
$DGVResults.Rows.Add($RRASserverName, $InboxAccountingStatus, $InboxStoreLimit, $InboxStoreUsedBytes, $InboxStoreUsedBytesInPercentage, $InboxStoreFreeBytes, $InboxStoreFreeBytesInPercentage, $InboxStoreFirstRecordDate, $InboxStoreLastRecordDate)
Write-OutputBox -OutputBoxMessage "Successfully collected data from $RRASserver" -Type INFO
[System.Windows.Forms.Application]::DoEvents()
}
else
{
Write-OutputBox -OutputBoxMessage "No data was found" -Type INFO
}
Update-StatusBar -Activity Ready -Text " "
Write-OutputBox -OutputBoxMessage "Completed collecting RRAS Remote Access Accounting data" -Type INFO
}
}
}
function Get-RemoteAccessConnectionStatistics {
Process
{
ForEach ($RRASserver in (Get-content -path $configurationfile))
{
$RRASserverDetails = $RRASserver.Split(",")
$RRASserverName = $RRASserverDetails[0]
if (Get-PSSession | ? ComputerName -eq $RRASserverName)
{
Update-StatusBar -Activity Enumerating -Text " "
Update-StatusBar -Activity Validating -Text "Validating connection to $RRASserver"
$StartDate = Get-Date -Date $DateTimeStart.value -Format "MM-dd-yyyy hh:mm:ss tt"
$EndDate = Get-Date -Date $DateTimeEnd.value -Format "MM-dd-yyyy hh:mm:ss tt"
if (($TextBoxUserName.Text -eq "Enter UserName or DeviceName") -or ($TextBoxUserName.Text -eq "") -or ($TextBoxUserName.Text -eq " ") -or ($TextBoxUserName.Text -eq $null))
{
$SelectedUser = $null
}
Else
{
$SelectedUser = $TextBoxUserName.Text
if ($SelectedUser -match "internal.dotars.gov.au")
{
#do Nothing
}
Else
{
if ($SelectedUser -match "xt")
{
$SelectedUser = "$SelectedUser.internal.dotars.gov.au"
}
Else
{
$SelectedUser = "$SelectedUser@internal.dotars.gov.au"
}
}
}
if ($CheckBoxCurrentData.checked -eq $false)
{
if ($SelectedUser -ne $null)
{
$script = {param($StartdateTime,$EndDateTime,$Username) Get-RemoteAccessConnectionStatistics -StartDateTime $StartdateTime -EndDateTime $EndDateTime | ? UserName -match $Username}
Write-OutputBox -OutputBoxMessage "Exeucting $script" -Type INFO
$var = Invoke-Command -Session (Get-PSSession | ? Computername -eq "$RRASserverName") -ScriptBlock $script -ArgumentList $Startdate, $EndDate, $SelectedUser
}
Else
{
$script = {param($StartdateTime,$EndDateTime) Get-RemoteAccessConnectionStatistics -StartDateTime $StartdateTime -EndDateTime $EndDateTime}
Write-OutputBox -OutputBoxMessage "Exeucting $script" -Type INFO
$var = Invoke-Command -Session (Get-PSSession | ? Computername -eq "$RRASserverName") -ScriptBlock $script -ArgumentList $Startdate, $EndDate
}
}
Else
{
if ($SelectedUser -ne $null)
{
$script = {param($Username) Get-RemoteAccessConnectionStatistics | ? UserName -match $Username}
Write-OutputBox -OutputBoxMessage "Exeucting $script" -Type INFO
$var = Invoke-Command -Session (Get-PSSession | ? Computername -eq "$RRASserverName") -ScriptBlock $script -ArgumentList $SelectedUser
}
Else
{
$script = {Get-RemoteAccessConnectionStatistics}
Write-OutputBox -OutputBoxMessage "Exeucting $script" -Type INFO
$var = Invoke-Command -Session (Get-PSSession | ? Computername -eq "$RRASserverName") -ScriptBlock $script
}
}
#Write-OutputBox -OutputBoxMessage "Executing: $script" -Type INFO
#Write-OutputBox -OutputBoxMessage "Fetching Data for RemoteAccessConnectionStatistics Start Date: $DateTimeStart.value and End Date: $DateTimeEnd.value " -Type INFO
Foreach ($Row in $var)
{
$Username = $Row | Select -ExpandProperty UserName
$ClientIPAddress = $Row.ClientIPAddress.IPAddressToString
$ClientExternalAddress = $Row.ClientExternalAddress
$AuthMethod = $Row.AuthMethod
$TunnelType = $Row.TunnelType
$UserActivityState = $Row.UserActivityState
$ConnectionStartTime = $Row.ConnectionStartTime.DateTime
$DateTimeNow = Get-Date
$Time= New-TimeSpan -Start $Row.ConnectionStartTime.DateTime -End $DateTimeNow
$Time = ($Row.ConnectionStartTime).AddSeconds($Row.ConnectionDuration)
$secs = $Row.ConnectionDuration
$ts = [timespan]::fromseconds($secs)
$ConnectionDuration = "{0:00}:{1:00}:{2:00}:{3:00}" -f $time.days,$time.Hours,$time.Minutes,$time.seconds
$ConnectionDuration = "$($ts.hours):$($ts.minutes):$($ts.seconds)"
$TotalBytesIn = [math]::round($Row.TotalBytesIn/1GB, 2)
$TotalBytesOut = [math]::round($Row.TotalBytesOut/1GB, 2)
$DGVResults.Rows.Add($RRASserverName,$Username,$ClientIPAddress,$ClientExternalAddress,$AuthMethod,$TunnelType,$ConnectionStartTime,$ConnectionDuration,$UserActivityState)
}
Write-OutputBox -OutputBoxMessage "Successfully collected data from $RRASserver" -Type INFO
[System.Windows.Forms.Application]::DoEvents()
}
else
{
Write-OutputBox -OutputBoxMessage "No data was found" -Type INFO
}
Update-StatusBar -Activity Ready -Text " "
Write-OutputBox -OutputBoxMessage "Completed collecting RRAS Connection Statistics data" -Type INFO
}
}
}
function Get-RRASConnectionStatisticsSummary {
Process
{
ForEach ($RRASserver in (Get-content -path $configurationfile))
{
$RRASserverDetails = $RRASserver.Split(",")
$RRASserverName = $RRASserverDetails[0]
if (Get-PSSession | ? ComputerName -eq $RRASserverName)
{
Update-StatusBar -Activity Enumerating -Text " "
Update-StatusBar -Activity Validating -Text "Validating connection to $RRASserver"
$StartDate = Get-Date -Date $DateTimeStart.value -Format "MM-dd-yyyy hh:mm:ss tt"
$EndDate = Get-Date -Date $DateTimeEnd.value -Format "MM-dd-yyyy hh:mm:ss tt"
if ($CheckBoxCurrentData.checked -eq $false)
{
$script = {param($StartdateTime,$EndDateTime) Get-RemoteAccessConnectionStatisticsSummary -StartDateTime "$StartdateTime" -EndDateTime "$EndDateTime"}
$var = Invoke-Command -Session (Get-PSSession | ? Computername -eq "$RRASserverName") -ScriptBlock $script -ArgumentList $Startdate, $EndDate
$TotalSessions = $var.TotalSessions
#$TotalDASessions = $var.TotalDASessions
$TotalVpnSessions = $var.TotalVpnSessions
$MaxConcurrentSessions = $var.MaxConcurrentSessions
#$TotalUniqueDAClients = $var.TotalUniqueDAClients
$AverageSessionsPerDay = $var.AverageSessionsPerDay
$TotalUniqueUsers = $var.TotalUniqueUsers
$DGVResults.Rows.Add($RRASserverName, $TotalSessions, $TotalVpnSessions, $MaxConcurrentSessions, $AverageSessionsPerDay, $TotalUniqueUsers)
}
Else
{
$script = {Get-RemoteAccessConnectionStatisticsSummary}
$var = Invoke-Command -Session (Get-PSSession | ? Computername -eq "$RRASserverName") -ScriptBlock $script
$TotalVpnConnections = $var.TotalVpnConnections
$TotalUniqueUsers = $var.TotalUniqueUsers
$MaxConcurrentConnections = $var.MaxConcurrentConnections
$TotalCumulativeConnections = $var.TotalCumulativeConnections
$TotalBytesIn = [math]::round($var.TotalBytesIn/1GB, 2)
$TotalBytesOut = [math]::round($var.TotalBytesOut/1GB, 2)
$DGVResults.Rows.Add($RRASserverName, $TotalVpnConnections, $TotalUniqueUsers, $MaxConcurrentConnections, $TotalCumulativeConnections, $TotalBytesIn, $TotalBytesOut)
}
Write-OutputBox -OutputBoxMessage "Successfully collected data from $RRASserver" -Type INFO
[System.Windows.Forms.Application]::DoEvents()
}
else
{
Write-OutputBox -OutputBoxMessage "No data was found" -Type INFO
}
Update-StatusBar -Activity Ready -Text " "
Write-OutputBox -OutputBoxMessage "Completed collecting RRAS Connection Statistics Summary data" -Type INFO
}
}
}
function Get-RemoteAccessHealth
{
Process
{
ForEach ($RRASserver in (Get-content -path $configurationfile))
{
$RRASserverDetails = $RRASserver.Split(",")
$RRASserverName = $RRASserverDetails[0]
if (Get-PSSession | ? ComputerName -eq $RRASserverName)
{
Update-StatusBar -Activity Enumerating -Text " "
Update-StatusBar -Activity Validating -Text "Validating connection to $RRASserver"
$script = {Get-RemoteAccessHealth}
$var = Invoke-Command -Session (Get-PSSession | ? Computername -eq "$RRASserverName") -ScriptBlock $script
Foreach ($Row in $var)
{
if (($Row.Component -eq "Server") -or ($Row.Component -eq "Vpn Addressing") -or ($Row.Component -eq "Vpn Connectivity") -or ($Row.Component -eq "Services"))
{
$Component = $Row | Select -ExpandProperty Component
$HealthState = $Row | Select -ExpandProperty HealthState
$TimeStamp = $Row | Select -ExpandProperty TimeStamp
$DGVResults.Rows.Add($RRASserverName, $Component, $HealthState, $TimeStamp)
}
}
Write-OutputBox -OutputBoxMessage "Successfully collected data from $RRASserver" -Type INFO
[System.Windows.Forms.Application]::DoEvents()
}
else
{
Write-OutputBox -OutputBoxMessage "No data was found" -Type INFO
}
Update-StatusBar -Activity Ready -Text " "
Write-OutputBox -OutputBoxMessage "Completed collecting RRAS Remote Access Health data" -Type INFO
}
}
}
function Get-RemoteAccessRadius
{
Process
{
ForEach ($RRASserver in (Get-content -path $configurationfile))
{
$RRASserverDetails = $RRASserver.Split(",")
$RRASserverName = $RRASserverDetails[0]
if (Get-PSSession | ? ComputerName -eq $RRASserverName)
{
Update-StatusBar -Activity Enumerating -Text " "
Update-StatusBar -Activity Validating -Text "Validating connection to $RRASserver"
$script = {Get-RemoteAccessRadius}
$var = Invoke-Command -Session (Get-PSSession | ? Computername -eq "$RRASserverName") -ScriptBlock $script
Foreach ($Row in $var)
{
$ServerName = $Row | Select -ExpandProperty ServerName
$Purpose = $Row | Select -ExpandProperty Purpose
$Score = $Row | Select -ExpandProperty Score
$Timeout = $Row | Select -ExpandProperty Timeout
$Port = $Row | Select -ExpandProperty Port
$AccountingOnOffMsg = $Row | Select -ExpandProperty AccountingOnOffMsg
$MsgAuthenticator = $Row | Select -ExpandProperty MsgAuthenticator
$DGVResults.Rows.Add($RRASserverName, $ServerName, $Purpose, $Score, $Timeout, $Port, $AccountingOnOffMsg, $MsgAuthenticator)
}
Write-OutputBox -OutputBoxMessage "Successfully collected data from $RRASserver" -Type INFO
[System.Windows.Forms.Application]::DoEvents()
}
else
{
Write-OutputBox -OutputBoxMessage "No data was found" -Type INFO
}
Update-StatusBar -Activity Ready -Text " "
Write-OutputBox -OutputBoxMessage "Completed collecting RRAS Remote Access Health data" -Type INFO
}
}
}
function Get-RemoteAccessUserActivity
{
Process
{
if (($TextBoxUserName.Text -eq "Enter UserName or DeviceName") -or ($TextBoxUserName.Text -eq "") -or ($TextBoxUserName.Text -eq " ") -or ($TextBoxUserName.Text -eq $null))
{
Update-StatusBar -Activity Enumerating -Text " "
Update-StatusBar -Activity Validating -Text "Validating Username for Fetching User Activity Details"
Write-OutputBox -OutputBoxMessage "Username Field cannot be left empty, Please Enter UserName or DeviceName" -Type WARNING
}
Else
{
ForEach ($RRASserver in (Get-content -path $configurationfile))
{
$RRASserverDetails = $RRASserver.Split(",")
$RRASserverName = $RRASserverDetails[0]
if (Get-PSSession | ? ComputerName -eq $RRASserverName)
{
Update-StatusBar -Activity Enumerating -Text " "
Update-StatusBar -Activity Validating -Text "Validating connection to $RRASserver"
$StartDate = Get-Date -Date $DateTimeStart.value -Format "MM-dd-yyyy hh:mm:ss tt"
$EndDate = Get-Date -Date $DateTimeEnd.value -Format "MM-dd-yyyy hh:mm:ss tt"
$SelectedUser = $TextBoxUserName.Text
if ($SelectedUser -match "internal.dotars.gov.au")
{
#do Nothing
}
Else
{
if ($SelectedUser -match "xt")
{
$SelectedUser = "$SelectedUser.internal.dotars.gov.au"
}
Else
{
$SelectedUser = "$SelectedUser@internal.dotars.gov.au"
}
}
if ($CheckBoxCurrentData.Checked -eq $false)
{
$script = {param($StartdateTime,$EndDateTime,$Username) Get-RemoteAccessUserActivity -StartDateTime $StartdateTime -EndDateTime $EndDateTime -UserName $Username }
Write-OutputBox -OutputBoxMessage "Executing script: $Script with paramaters: $Startdate, $EndDate, $SelectedUser " -Type INFO
$var = Invoke-Command -Session (Get-PSSession | ? Computername -eq "$RRASserverName") -ScriptBlock $script -ArgumentList $Startdate, $EndDate, $SelectedUser
}
Else
{
$script = {param($Username) Get-RemoteAccessUserActivity -UserName $Username}
Write-OutputBox -OutputBoxMessage "Executing script: $Script with parameters: $SelectedUser " -Type INFO
$var = Invoke-Command -Session (Get-PSSession | ? Computername -eq "$RRASserverName") -ScriptBlock $script -ArgumentList $SelectedUser
}
Foreach ($Row in $var)
{
$ServerIpAddress = $Row | Select -ExpandProperty ServerIpAddress
$ProtocolID = $Row | Select -ExpandProperty ProtocolID
$ServerPort = $Row | Select -ExpandProperty ServerPort
$DGVResults.Rows.Add($RRASserverName, $SelectedUser, $ServerIpAddress, $ProtocolID, $ServerPort)
}
Write-OutputBox -OutputBoxMessage "Successfully collected data from $RRASserver" -Type INFO
[System.Windows.Forms.Application]::DoEvents()
}
else
{
Write-OutputBox -OutputBoxMessage "No data was found" -Type INFO
}
Update-StatusBar -Activity Ready -Text " "
Write-OutputBox -OutputBoxMessage "Completed collecting RRAS Remote Access Health data" -Type INFO
}
}
}
}
function RefreshDataGRidView
{
$DGVResults.Rows.Clear()
if ($ComboBoxTypes.SelectedItem -eq "General Information") {
$DGVResults.Columns.Clear()
$DGVResults.Columns.Insert(0,(New-Object -TypeName System.Windows.Forms.DataGridViewTextBoxColumn))
$DGVResults.Columns[0].Name = "RRAS Server"
$DGVResults.Columns[0].AutoSizeMode = "Fill"
$DGVResults.Columns[0].ReadOnly = $true
$DGVResults.Columns.Insert(1,(New-Object -TypeName System.Windows.Forms.DataGridViewTextBoxColumn))
$DGVResults.Columns[1].Name = "VpnStatus"
$DGVResults.Columns[1].Width = "200"
$DGVResults.Columns[1].ReadOnly = $true
$DGVResults.Columns.Insert(2,(New-Object -TypeName System.Windows.Forms.DataGridViewTextBoxColumn))
$DGVResults.Columns[2].Name = "Routing Status"
$DGVResults.Columns[2].AutoSizeMode = "Fill"
$DGVResults.Columns[2].ReadOnly = $true
$DGVResults.Columns.Insert(3,(New-Object -TypeName System.Windows.Forms.DataGridViewTextBoxColumn))
$DGVResults.Columns[3].Name = "Internet Interface"
$DGVResults.Columns[3].AutoSizeMode = "Fill"
$DGVResults.Columns[3].ReadOnly = $true
$DGVResults.Columns.Insert(4,(New-Object -TypeName System.Windows.Forms.DataGridViewTextBoxColumn))
$DGVResults.Columns[4].Name = "Internal Interface"
$DGVResults.Columns[4].AutoSizeMode = "Fill"
$DGVResults.Columns[4].ReadOnly = $true
$DGVResults.Columns.Insert(5,(New-Object -TypeName System.Windows.Forms.DataGridViewTextBoxColumn))
$DGVResults.Columns[5].Name = "IP Assignment Method"
$DGVResults.Columns[5].AutoSizeMode = "Fill"
$DGVResults.Columns[5].ReadOnly = $true
$DGVResults.Columns.Insert(6,(New-Object -TypeName System.Windows.Forms.DataGridViewTextBoxColumn))
$DGVResults.Columns[6].Name = "IP Address Range List"
$DGVResults.Columns[6].AutoSizeMode = "Fill"
$DGVResults.Columns[6].ReadOnly = $true
$DGVResults.Columns.Insert(7,(New-Object -TypeName System.Windows.Forms.DataGridViewTextBoxColumn))
$DGVResults.Columns[7].Name = "Authentication Type"
$DGVResults.Columns[7].AutoSizeMode = "Fill"
$DGVResults.Columns[7].ReadOnly = $true
$DGVResults.Columns.Insert(8,(New-Object -TypeName System.Windows.Forms.DataGridViewTextBoxColumn))
$DGVResults.Columns[8].Name = "Radius Server List"
$DGVResults.Columns[8].AutoSizeMode = "Fill"
$DGVResults.Columns[8].ReadOnly = $true
}
Elseif ($ComboBoxTypes.SelectedItem -eq "Accounting")
{
$DGVResults.Columns.Clear()
$DGVResults.Columns.Insert(0,(New-Object -TypeName System.Windows.Forms.DataGridViewTextBoxColumn))
$DGVResults.Columns[0].Name = "RRAS Server"
$DGVResults.Columns[0].AutoSizeMode = "Fill"
$DGVResults.Columns[0].ReadOnly = $true
$DGVResults.Columns.Insert(1,(New-Object -TypeName System.Windows.Forms.DataGridViewTextBoxColumn))
$DGVResults.Columns[1].Name = "Inbox Status"
$DGVResults.Columns[1].AutoSizeMode = "Fill"
$DGVResults.Columns[1].ReadOnly = $true
$DGVResults.Columns.Insert(2,(New-Object -TypeName System.Windows.Forms.DataGridViewTextBoxColumn))
$DGVResults.Columns[2].Name = "Inbox Limit"
$DGVResults.Columns[2].AutoSizeMode = "Fill"
$DGVResults.Columns[2].ReadOnly = $true
$DGVResults.Columns.Insert(3,(New-Object -TypeName System.Windows.Forms.DataGridViewTextBoxColumn))
$DGVResults.Columns[3].Name = "Inbox UsedBytes (GB)"
$DGVResults.Columns[3].AutoSizeMode = "Fill"
$DGVResults.Columns[3].ReadOnly = $true
$DGVResults.Columns.Insert(4,(New-Object -TypeName System.Windows.Forms.DataGridViewTextBoxColumn))
$DGVResults.Columns[4].Name = "UsedBytes (%)"
$DGVResults.Columns[4].AutoSizeMode = "Fill"
$DGVResults.Columns[4].ReadOnly = $true
$DGVResults.Columns.Insert(5,(New-Object -TypeName System.Windows.Forms.DataGridViewTextBoxColumn))
$DGVResults.Columns[5].Name = "FreeBytes (GB)"
$DGVResults.Columns[5].AutoSizeMode = "Fill"
$DGVResults.Columns[5].ReadOnly = $true
$DGVResults.Columns.Insert(6,(New-Object -TypeName System.Windows.Forms.DataGridViewTextBoxColumn))
$DGVResults.Columns[6].Name = "FreeBytes (%)"
$DGVResults.Columns[6].AutoSizeMode = "Fill"
$DGVResults.Columns[6].ReadOnly = $true
$DGVResults.Columns.Insert(7,(New-Object -TypeName System.Windows.Forms.DataGridViewTextBoxColumn))
$DGVResults.Columns[7].Name = "FirstRecordDate"
$DGVResults.Columns[7].AutoSizeMode = "Fill"
$DGVResults.Columns[7].ReadOnly = $true
$DGVResults.Columns.Insert(8,(New-Object -TypeName System.Windows.Forms.DataGridViewTextBoxColumn))
$DGVResults.Columns[8].Name = "LastRecordDate"
$DGVResults.Columns[8].AutoSizeMode = "Fill"
$DGVResults.Columns[8].ReadOnly = $true
}
Elseif ($ComboBoxTypes.SelectedItem -eq "Connection Statistics")
{
$DGVResults.Columns.Clear()
$DGVResults.Columns.Insert(0,(New-Object -TypeName System.Windows.Forms.DataGridViewTextBoxColumn))
$DGVResults.Columns[0].Name = "RRAS Server"
$DGVResults.Columns[0].AutoSizeMode = "Fill"
$DGVResults.Columns[0].ReadOnly = $true
$DGVResults.Columns.Insert(1,(New-Object -TypeName System.Windows.Forms.DataGridViewTextBoxColumn))
$DGVResults.Columns[1].Name = "Username"
$DGVResults.Columns[1].AutoSizeMode = "Fill"
$DGVResults.Columns[1].ReadOnly = $true
$DGVResults.Columns.Insert(2,(New-Object -TypeName System.Windows.Forms.DataGridViewTextBoxColumn))
$DGVResults.Columns[2].Name = "Client IPAddress"
$DGVResults.Columns[2].AutoSizeMode = "Fill"
$DGVResults.Columns[2].ReadOnly = $true
$DGVResults.Columns.Insert(3,(New-Object -TypeName System.Windows.Forms.DataGridViewTextBoxColumn))
$DGVResults.Columns[3].Name = "Client ExternalAddress"
$DGVResults.Columns[3].AutoSizeMode = "Fill"
$DGVResults.Columns[3].ReadOnly = $true
$DGVResults.Columns.Insert(4,(New-Object -TypeName System.Windows.Forms.DataGridViewTextBoxColumn))
$DGVResults.Columns[4].Name = "AuthMethod"
$DGVResults.Columns[4].AutoSizeMode = "Fill"
$DGVResults.Columns[4].ReadOnly = $true
$DGVResults.Columns.Insert(5,(New-Object -TypeName System.Windows.Forms.DataGridViewTextBoxColumn))
$DGVResults.Columns[5].Name = "Tunnel Type"
$DGVResults.Columns[5].AutoSizeMode = "Fill"
$DGVResults.Columns[5].ReadOnly = $true
$DGVResults.Columns.Insert(6,(New-Object -TypeName System.Windows.Forms.DataGridViewTextBoxColumn))
$DGVResults.Columns[6].Name = "Connection StartTime"
$DGVResults.Columns[6].AutoSizeMode = "Fill"
$DGVResults.Columns[6].ReadOnly = $true
$DGVResults.Columns.Insert(7,(New-Object -TypeName System.Windows.Forms.DataGridViewTextBoxColumn))
$DGVResults.Columns[7].Name = "Connection Duration"
$DGVResults.Columns[7].AutoSizeMode = "Fill"
$DGVResults.Columns[7].ReadOnly = $true
$DGVResults.Columns.Insert(8,(New-Object -TypeName System.Windows.Forms.DataGridViewTextBoxColumn))
$DGVResults.Columns[8].Name = "User ActivityState"
$DGVResults.Columns[8].AutoSizeMode = "Fill"
$DGVResults.Columns[8].ReadOnly = $true
#TotalBytesIn
#TotalBytesOut
}
Elseif ($ComboBoxTypes.SelectedItem -eq "Connection Statistics Summary")
{
if ($CheckBoxCurrentData.Checked -eq $true)
{
$DGVResults.Columns.Clear()
$DGVResults.Columns.Insert(0,(New-Object -TypeName System.Windows.Forms.DataGridViewTextBoxColumn))
$DGVResults.Columns[0].Name = "RRAS Server"
$DGVResults.Columns[0].AutoSizeMode = "Fill"
$DGVResults.Columns[0].ReadOnly = $true
$DGVResults.Columns.Insert(1,(New-Object -TypeName System.Windows.Forms.DataGridViewTextBoxColumn))
$DGVResults.Columns[1].Name = "Total VPN Connections"
$DGVResults.Columns[1].AutoSizeMode = "Fill"
$DGVResults.Columns[1].ReadOnly = $true
$DGVResults.Columns.Insert(2,(New-Object -TypeName System.Windows.Forms.DataGridViewTextBoxColumn))
$DGVResults.Columns[2].Name = "Total Unique Users"
$DGVResults.Columns[2].AutoSizeMode = "Fill"
$DGVResults.Columns[2].ReadOnly = $true
$DGVResults.Columns.Insert(3,(New-Object -TypeName System.Windows.Forms.DataGridViewTextBoxColumn))
$DGVResults.Columns[3].Name = "Max Concurrent Connections"
$DGVResults.Columns[3].AutoSizeMode = "Fill"
$DGVResults.Columns[3].ReadOnly = $true
$DGVResults.Columns.Insert(4,(New-Object -TypeName System.Windows.Forms.DataGridViewTextBoxColumn))
$DGVResults.Columns[4].Name = "Total Cumulative Connections"
$DGVResults.Columns[4].AutoSizeMode = "Fill"
$DGVResults.Columns[4].ReadOnly = $true
$DGVResults.Columns.Insert(5,(New-Object -TypeName System.Windows.Forms.DataGridViewTextBoxColumn))
$DGVResults.Columns[5].Name = "Total BytesIn (GB)"
$DGVResults.Columns[5].AutoSizeMode = "Fill"
$DGVResults.Columns[5].ReadOnly = $true
$DGVResults.Columns.Insert(6,(New-Object -TypeName System.Windows.Forms.DataGridViewTextBoxColumn))
$DGVResults.Columns[6].Name = "Total BytesOut (GB)"
$DGVResults.Columns[6].AutoSizeMode = "Fill"
$DGVResults.Columns[6].ReadOnly = $true
}
Else
{
$DGVResults.Columns.Clear()
$DGVResults.Columns.Insert(0,(New-Object -TypeName System.Windows.Forms.DataGridViewTextBoxColumn))
$DGVResults.Columns[0].Name = "RRAS Server"
$DGVResults.Columns[0].AutoSizeMode = "Fill"
$DGVResults.Columns[0].ReadOnly = $true
$DGVResults.Columns.Insert(1,(New-Object -TypeName System.Windows.Forms.DataGridViewTextBoxColumn))
$DGVResults.Columns[1].Name = "Total Sessions"
$DGVResults.Columns[1].AutoSizeMode = "Fill"
$DGVResults.Columns[1].ReadOnly = $true
$DGVResults.Columns.Insert(2,(New-Object -TypeName System.Windows.Forms.DataGridViewTextBoxColumn))
$DGVResults.Columns[2].Name = "Total Vpn Sessions"
$DGVResults.Columns[2].AutoSizeMode = "Fill"
$DGVResults.Columns[2].ReadOnly = $true
$DGVResults.Columns.Insert(3,(New-Object -TypeName System.Windows.Forms.DataGridViewTextBoxColumn))
$DGVResults.Columns[3].Name = "Max Concurrent Sessions"
$DGVResults.Columns[3].AutoSizeMode = "Fill"
$DGVResults.Columns[3].ReadOnly = $true
$DGVResults.Columns.Insert(4,(New-Object -TypeName System.Windows.Forms.DataGridViewTextBoxColumn))
$DGVResults.Columns[4].Name = "Average SessionsPerDay"
$DGVResults.Columns[4].AutoSizeMode = "Fill"
$DGVResults.Columns[4].ReadOnly = $true
$DGVResults.Columns.Insert(5,(New-Object -TypeName System.Windows.Forms.DataGridViewTextBoxColumn))
$DGVResults.Columns[5].Name = "Total UniqueUsers"
$DGVResults.Columns[5].AutoSizeMode = "Fill"
$DGVResults.Columns[5].ReadOnly = $true
}
}
Elseif ($ComboBoxTypes.SelectedItem -eq "Health")
{
$DGVResults.Columns.Clear()
$DGVResults.Columns.Insert(0,(New-Object -TypeName System.Windows.Forms.DataGridViewTextBoxColumn))
$DGVResults.Columns[0].Name = "RRAS Server"
$DGVResults.Columns[0].AutoSizeMode = "Fill"
$DGVResults.Columns[0].ReadOnly = $true
$DGVResults.Columns.Insert(1,(New-Object -TypeName System.Windows.Forms.DataGridViewTextBoxColumn))
$DGVResults.Columns[1].Name = "Component"
$DGVResults.Columns[1].AutoSizeMode = "Fill"
$DGVResults.Columns[1].ReadOnly = $true
$DGVResults.Columns.Insert(2,(New-Object -TypeName System.Windows.Forms.DataGridViewTextBoxColumn))
$DGVResults.Columns[2].Name = "Health State"
$DGVResults.Columns[2].AutoSizeMode = "Fill"
$DGVResults.Columns[2].ReadOnly = $true
$DGVResults.Columns.Insert(3,(New-Object -TypeName System.Windows.Forms.DataGridViewTextBoxColumn))
$DGVResults.Columns[3].Name = "Timestamp"
$DGVResults.Columns[3].AutoSizeMode = "Fill"
$DGVResults.Columns[3].ReadOnly = $true
}
Elseif ($ComboBoxTypes.SelectedItem -eq "RemoteAccessRadius")
{
$DGVResults.Columns.Clear()
$DGVResults.Columns.Insert(0,(New-Object -TypeName System.Windows.Forms.DataGridViewTextBoxColumn))
$DGVResults.Columns[0].Name = "RRAS Server"
$DGVResults.Columns[0].AutoSizeMode = "Fill"
$DGVResults.Columns[0].ReadOnly = $true
$DGVResults.Columns.Insert(1,(New-Object -TypeName System.Windows.Forms.DataGridViewTextBoxColumn))
$DGVResults.Columns[1].Name = "ServerName"
$DGVResults.Columns[1].AutoSizeMode = "Fill"
$DGVResults.Columns[1].ReadOnly = $true
$DGVResults.Columns.Insert(2,(New-Object -TypeName System.Windows.Forms.DataGridViewTextBoxColumn))
$DGVResults.Columns[2].Name = "Purpose"
$DGVResults.Columns[2].AutoSizeMode = "Fill"
$DGVResults.Columns[2].ReadOnly = $true
$DGVResults.Columns.Insert(3,(New-Object -TypeName System.Windows.Forms.DataGridViewTextBoxColumn))
$DGVResults.Columns[3].Name = "Score"
$DGVResults.Columns[3].AutoSizeMode = "Fill"
$DGVResults.Columns[3].ReadOnly = $true
$DGVResults.Columns.Insert(4,(New-Object -TypeName System.Windows.Forms.DataGridViewTextBoxColumn))
$DGVResults.Columns[4].Name = "Timeout"
$DGVResults.Columns[4].AutoSizeMode = "Fill"
$DGVResults.Columns[4].ReadOnly = $true
$DGVResults.Columns.Insert(5,(New-Object -TypeName System.Windows.Forms.DataGridViewTextBoxColumn))
$DGVResults.Columns[5].Name = "Port"
$DGVResults.Columns[5].AutoSizeMode = "Fill"
$DGVResults.Columns[5].ReadOnly = $true
$DGVResults.Columns.Insert(6,(New-Object -TypeName System.Windows.Forms.DataGridViewTextBoxColumn))
$DGVResults.Columns[6].Name = "AccountingOnOffMsg"
$DGVResults.Columns[6].AutoSizeMode = "Fill"
$DGVResults.Columns[6].ReadOnly = $true
$DGVResults.Columns.Insert(7,(New-Object -TypeName System.Windows.Forms.DataGridViewTextBoxColumn))
$DGVResults.Columns[7].Name = "MsgAuthenticator"
$DGVResults.Columns[7].AutoSizeMode = "Fill"
$DGVResults.Columns[7].ReadOnly = $true
}
Elseif ($ComboBoxTypes.SelectedItem -eq "User Activity")
{
$DGVResults.Columns.Clear()
$DGVResults.Columns.Insert(0,(New-Object -TypeName System.Windows.Forms.DataGridViewTextBoxColumn))
$DGVResults.Columns[0].Name = "RRAS Server"
$DGVResults.Columns[0].AutoSizeMode = "Fill"
$DGVResults.Columns[0].ReadOnly = $true
$DGVResults.Columns.Insert(1,(New-Object -TypeName System.Windows.Forms.DataGridViewTextBoxColumn))
$DGVResults.Columns[1].Name = "UserName"
$DGVResults.Columns[1].AutoSizeMode = "Fill"
$DGVResults.Columns[1].ReadOnly = $true
$DGVResults.Columns.Insert(2,(New-Object -TypeName System.Windows.Forms.DataGridViewTextBoxColumn))
$DGVResults.Columns[2].Name = "ServerIpAddress"
$DGVResults.Columns[2].AutoSizeMode = "Fill"
$DGVResults.Columns[2].ReadOnly = $true
$DGVResults.Columns.Insert(3,(New-Object -TypeName System.Windows.Forms.DataGridViewTextBoxColumn))
$DGVResults.Columns[3].Name = "ProtocolID"
$DGVResults.Columns[3].AutoSizeMode = "Fill"
$DGVResults.Columns[3].ReadOnly = $true
$DGVResults.Columns.Insert(4,(New-Object -TypeName System.Windows.Forms.DataGridViewTextBoxColumn))
$DGVResults.Columns[4].Name = "ServerPort"
$DGVResults.Columns[4].AutoSizeMode = "Fill"
$DGVResults.Columns[4].ReadOnly = $true
}
}
function SaveConfiguration($DGVConfigResultsData)
{
#Check File and Create if required
if (Test-path -Path $ConfigurationFile)
{
Write-OutputConfigBox -OutputBoxMessage "Configuration File found, Initiating clean up procedure" -Type INFO
Remove-Item -Path $ConfigurationFile -Force
New-Item -path $ConfigurationFile -ItemType File
}
Else
{
Write-OutputConfigBox -OutputBoxMessage "Configuration File not found, creating file as required: $ConfigurationFile" -Type INFO
New-Item -path $ConfigurationFile -ItemType File
}
# Save Information to Configuration File
$Row = 0
For ($Row =0; $row -lt $DGVConfigResultsData.Rowcount -1 ; $Row++)
{
$RRASHostname = ""
$RRASUsername = ""
$RRASHostname = $DGVConfigResultsData.Rows[$row].Cells[0].Value
$RRASUsername = $DGVConfigResultsData.Rows[$row].Cells[1].Value
#$RRASPassword = (Decrypt-String -Encrypted ($DGVConfigResults[2,$DGVConfigResults.CurrentCell.RowIndex].Value))
$RRASPassword = (Decrypt-String -Encrypted ($DGVConfigResultsData.Rows[$row].Cells[2].Value))
#Save RRAS hostname and Username in the Configuraiton File
Add-Content -Path $ConfigurationFile -Value "$RRASHostname,$RRASUsername"
# Encrytping password
$RRASPassword | ConvertTo-SecureString -AsPlainText -Force | ConvertFrom-SecureString | Out-File "$UserLocalAppData\RRASreporting\$RRASHostname.txt"
Write-OutputConfigBox -OutputBoxMessage "Data saved in Configuration File: $ConfigurationFile" -Type INFO
$Global:ConfigurationUploaded = "Success"
}
}
function LoadConfiguration
{
Process
{
#Check File and Create if required
if (Test-path -Path $ConfigurationFile)
{
Write-OutputConfigBox -OutputBoxMessage "Configuration File found, Loading information" -Type INFO
# Load information
ForEach ($RRASserver in (Get-content -path $configurationfile))
{
$RRASServerDetails = $RRASserver.Split(",")
$RRASServerName = $RRASServerDetails[0]
$RRASUserName = $RRASserverDetails[1]
$RRASDecryptedPassword = ConvertFrom-SecureToPlain (Get-Content -Path "$UserLocalAppData\RRASreporting\$RRASServerName.txt" | ConvertTo-SecureString)
Update-StatusBar -Activity Validating -Text "Fetching login details from $UserLocalAppData\RRASreporting\$RRASServerName.txt"
Write-OutputConfigBox -OutputBoxMessage "Fetching login details from $UserLocalAppData\RRASreporting\$RRASServerName.txt" -Type INFO
Update-StatusBar -Activity Enumerating -Text " "
Update-StatusBar -Activity Validating -Text "Adding Server to the RRAS Server List"
$EncryptedPassword = (Encrypt-String -String ($RRASDecryptedPassword))
$DGVConfigResults.Rows.Add($RRASServerName, $RRASUserName, $EncryptedPassword)
Update-StatusBar -Activity Ready -Text " "
Write-OutputConfigBox -OutputBoxMessage "Successfully added data to Grid view" -Type INFO
}
}
}
}
function Export-DGV2CSV ([Windows.Forms.DataGridView] $grid, [String] $File)
<#
.SYNOPSIS
Export basic datagrid to CSV file
.PARAMETER grid
Datagrid object
.PARAMETER file
Path to CSV file
#>
{
if ($grid.RowCount -eq 0) { return } # nothing to do
$row = New-Object Windows.Forms.DataGridViewRow
$sw = new-object System.IO.StreamWriter($File)
Try
{
#Write header line
$sw.WriteLine( ($grid.Columns | % { $_.HeaderText } ) -join ',' )
Update-StatusBar -Activity Validating -Text "Fetching data from Datagrid to Export"
Write-OutputBox -OutputBoxMessage "Fetching data from Datagrid to Export" -Type INFO
#Export contents inlcuding Headers
$grid.Rows | % {
$sw.WriteLine(
($_.Cells | % { $_.Value }) -join ','
)
}
$sw.Close()
Write-OutputBox -OutputBoxMessage "Data Exported to $ExportFile successfully" -Type INFO
Update-StatusBar -Activity Ready -Text " "
}
Catch
{
Write-OutputBox -OutputBoxMessage "Issues while exporting datagridview: $_.Exception.Message" -Type ERROR
}
}
function Encrypt-String($String, $Passphrase="EncryptIt", $salt="SaltCrypto", $init="PassKeeper", [switch]$arrayOutput)
{
# Info: More information and good documentation on these functions can be found in the link above
$r = New-Object System.Security.Cryptography.RijndaelManaged
$pass = [Text.Encoding]::UTF8.GetBytes($Passphrase)
$salt = [Text.Encoding]::UTF8.GetBytes($salt)
$r.Key = (New-Object Security.Cryptography.PasswordDeriveBytes $pass, $salt, "SHA1", 5).GetBytes(32)
$r.IV = (New-Object Security.Cryptography.SHA1Managed).ComputeHash( [Text.Encoding]::UTF8.GetBytes($init) )[0..15]
$c = $r.CreateEncryptor()
$ms = New-Object IO.MemoryStream
$cs = New-Object Security.Cryptography.CryptoStream $ms,$c,"Write"
$sw = New-Object IO.StreamWriter $cs
$sw.Write($String)
$sw.Close()
$cs.Close()
$ms.Close()
$r.Clear()
[byte[]]$result = $ms.ToArray()
return [Convert]::ToBase64String($result)
}
function Decrypt-String($Encrypted, $Passphrase="EncryptIt", $salt="SaltCrypto", $init="PassKeeper")
{
if($Encrypted -is [string])
{
$Encrypted = [Convert]::FromBase64String($Encrypted)
}
$r = New-Object System.Security.Cryptography.RijndaelManaged
$pass = [Text.Encoding]::UTF8.GetBytes($Passphrase)
$salt = [Text.Encoding]::UTF8.GetBytes($salt)
$r.Key = (New-Object Security.Cryptography.PasswordDeriveBytes $pass, $salt, "SHA1", 5).GetBytes(32) #256/8
$r.IV = (New-Object Security.Cryptography.SHA1Managed).ComputeHash( [Text.Encoding]::UTF8.GetBytes($init) )[0..15]
$d = $r.CreateDecryptor()
$ms = New-Object IO.MemoryStream @(,$Encrypted)
$cs = New-Object Security.Cryptography.CryptoStream $ms,$d,"Read"
$sr = New-Object IO.StreamReader $cs
$text = $sr.ReadToEnd()
$sr.Close()
$cs.Close()
$ms.Close()
$r.Clear()
return $text
}
# A Generic Function for Converting Security.SecureString Objects to Plain Text Strings
Function ConvertFrom-SecureToPlain
{
param( [Parameter(Mandatory=$true)][System.Security.SecureString] $SecurePassword)
# Create a "password pointer"
$PasswordPointer = [Runtime.InteropServices.Marshal]::SecureStringToBSTR($SecurePassword)
# Get the plain text version of the password
$PlainTextPassword = [Runtime.InteropServices.Marshal]::PtrToStringAuto($PasswordPointer)
# Free the pointer
[Runtime.InteropServices.Marshal]::ZeroFreeBSTR($PasswordPointer)
# Return the plain text password
$PlainTextPassword
}
function RemoveRRASServertoGridView
{
Process
{
Update-StatusBar -Activity Enumerating -Text " "
Update-StatusBar -Activity Validating -Text "Adding Server to the RRAS Server List"
$DGVConfigResults.Rows.Remove($DGVConfigResults.Rows[$DGVConfigResults.CurrentCell.RowIndex])
Update-StatusBar -Activity Ready -Text " "
Write-OutputBox -OutputBoxMessage "Successfully added data to Grid view" -Type INFO
}
}
function AddRRASServertoGridView
{
Process
{
Update-StatusBar -Activity Enumerating -Text " "
Update-StatusBar -Activity Validating -Text "Adding Server to the RRAS Server List"
# Encrytping password
$EncryptedString = (Encrypt-String -String ($TextBoxRRASPassword.Text))
$DGVConfigResults.Rows.Add($TextBoxRRASServer.Text, $TextBoxRRASUsername.Text, $EncryptedString)
Update-StatusBar -Activity Ready -Text " "
Write-OutputConfigBox -OutputBoxMessage "Successfully added data to Grid view" -Type INFO
}
}
#endregion Functions
#region Windows Form Settings
#region Form Details
# Forms
$Form = New-Object System.Windows.Forms.Form
#$Form.Size = New-Object System.Drawing.Size(900,700)
$Form.Size = New-Object System.Drawing.Size(1200,700)
$Form.MinimumSize = New-Object System.Drawing.Size(1200,700)
$Form.MaximumSize = New-Object System.Drawing.Size([System.Int32]::MaxValue,[System.Int32]::MaxValue)
$Form.SizeGripStyle = "Show"
$Form.Icon = [System.Drawing.Icon]::ExtractAssociatedIcon($PSHome + "\powershell.exe")
$Form.Text = "Harmik Batth - RRAS Server Stats v1.0"
$Form.ControlBox = $true
$Form.MinimizeBox=$true
$Form.MaximizeBox=$true
$Form.TopMost = $false
#endregion Form Details
#region Execution Form page
# Buttons
$ButtonExecute = New-Object System.Windows.Forms.Button
$ButtonExecute.Location = New-Object System.Drawing.Size(790,27)
$ButtonExecute.Size = New-Object System.Drawing.Size(90,25)
$ButtonExecute.Text = "Execute"
$ButtonExecute.TabIndex = "5"
$ButtonExecute.Anchor = "Top, Left"
$ButtonExecute.Enabled = $true
$ButtonExecute.Add_Click({
switch ($ComboBoxTypes.SelectedItem)
{
"General Information"
{
Invoke-CleanControls -Option All
if ($RadioButtonSelectRRASServer.Checked -eq $true)
{
DeActivate-Controls
RefreshDataGridView
Get-RRASGeneralInformation
Activate-Controls
}
}
"Accounting"
{
Invoke-CleanControls -Option All
if ($RadioButtonSelectRRASServer.Checked -eq $true)
{
DeActivate-Controls
RefreshDataGridView
Get-RemoteAccessAccounting
Activate-Controls
}
}
"Connection Statistics"
{
Invoke-CleanControls -Option All
if ($RadioButtonSelectRRASServer.Checked -eq $true)
{
DeActivate-Controls
RefreshDataGridView
Get-RemoteAccessConnectionStatistics
Activate-Controls
}
}
"Connection Statistics Summary"
{
Invoke-CleanControls -Option All
if ($RadioButtonSelectRRASServer.Checked -eq $true)
{
DeActivate-Controls
RefreshDataGridView
Get-RRASConnectionStatisticsSummary
Activate-Controls
}
}
"Health"
{
Invoke-CleanControls -Option All
if ($RadioButtonSelectRRASServer.Checked -eq $true)
{
DeActivate-Controls
RefreshDataGridView
Get-RemoteAccessHealth
Activate-Controls
}
}
"RemoteAccessRadius"
{
Invoke-CleanControls -Option All
if ($RadioButtonSelectRRASServer.Checked -eq $true)
{
DeActivate-Controls
RefreshDataGridView
Get-RemoteAccessRadius
Activate-Controls
}
}
"User Activity"
{
Invoke-CleanControls -Option All
if ($RadioButtonSelectRRASServer.Checked -eq $true)
{
DeActivate-Controls
RefreshDataGridView
Get-RemoteAccessUserActivity
Activate-Controls
}
}
}
})
$ButtonConfiguration = New-Object System.Windows.Forms.Button
$ButtonConfiguration.Location = New-Object System.Drawing.Size(910,27)
$ButtonConfiguration.Size = New-Object System.Drawing.Size(90,25)
$ButtonConfiguration.Text = "Configuration"
$ButtonConfiguration.TabIndex = "6"
$ButtonConfiguration.Anchor = "Top, Left"
$ButtonConfiguration.Enabled = $true
$ButtonConfiguration.Add_Click({
LoadConfigurationForm
})
$ButtonExport = New-Object System.Windows.Forms.Button
$ButtonExport.Location = New-Object System.Drawing.Size(790,57)
$ButtonExport.Size = New-Object System.Drawing.Size(90,25)
$ButtonExport.Text = "Export"
$ButtonExport.TabIndex = "7"
$ButtonExport.Anchor = "Top, Left"
$ButtonExport.Enabled = $true
$ButtonExport.Add_Click({
$strDate = Get-Date -Format "dd-MM-yyyy"
switch ($ComboBoxTypes.SelectedItem)
{
"General Information"
{
$ExportFile = $ExportFile = "$ExportFolder\RRAS-General-Information-$strDate.csv"
}
"Accounting"
{
$ExportFile = $ExportFile = "$ExportFolder\RRAS-Accounting-$strDate.csv"
}
"Connection Statistics"
{
$ExportFile = $ExportFile = "$ExportFolder\RRAS-Connection-Statistics-$strDate.csv"
}
"Connection Statistics Summary"
{
if ($CheckBoxCurrentData.Checked -$true)
{
$ExportFile = $ExportFile = "$ExportFolder\RRAS-Connection-Statistics-Summary-Current-$strDate.csv"
}
Else
{
$ExportFile = $ExportFile = "$ExportFolder\RRAS-Connection-Statistics-Summary-Custom-$strDate.csv"
}
}
"Health"
{
$ExportFile = $ExportFile = "$ExportFolder\RRAS-Health-$strDate.csv"
}
"RemoteAccessRadius"
{
$ExportFile = $ExportFile = "$ExportFolder\RRAS-Radius-$strDate.csv"
}
"User Activity"
{
$ExportFile = $ExportFile = "$ExportFolder\RRAS-User-Activity-$strDate.csv"
}
}
Export-DGV2CSV $DGVResults $ExportFile
})
# GroupBoxes
$GBRRASServersSelect = New-Object -TypeName System.Windows.Forms.GroupBox
$GBRRASServersSelect.Location = New-Object -TypeName System.Drawing.Size(10,10)
$GBRRASServersSelect.Size = New-Object -TypeName System.Drawing.Size(120,50)
$GBRRASServersSelect.Anchor = "Top, Left"
$GBRRASServersSelect.Text = "RRAS Servers List"
$GBOptions = New-Object -TypeName System.Windows.Forms.GroupBox
$GBOptions.Location = New-Object -TypeName System.Drawing.Size(140,10)
$GBOptions.Size = New-Object -TypeName System.Drawing.Size(630,80)
$GBOptions.Anchor = "Top, Left"
$GBOptions.Text = "Options"
$GBUser = New-Object -TypeName System.Windows.Forms.GroupBox
$GBUser.Location = New-Object -TypeName System.Drawing.Size(540,30)
$GBUser.Size = New-Object -TypeName System.Drawing.Size(220,50)
$GBUser.Anchor = "Top, Left"
$GBUser.Text = "Enter Username to Report on"
$GBActions = New-Object -TypeName System.Windows.Forms.GroupBox
$GBActions.Location = New-Object -TypeName System.Drawing.Size(780,10)
$GBActions.Size = New-Object -TypeName System.Drawing.Size(110,90)
$GBActions.Anchor = "Top, Left"
$GBActions.Text = "Actions"
$GBSettings = New-Object -TypeName System.Windows.Forms.GroupBox
$GBSettings.Location = New-Object -TypeName System.Drawing.Size(900,10)
$GBSettings.Size = New-Object -TypeName System.Drawing.Size(110,50)
$GBSettings.Anchor = "Top, Left"
$GBSettings.Text = "Settings"
$GBResults = New-Object -TypeName System.Windows.Forms.GroupBox
$GBResults.Location = New-Object -TypeName System.Drawing.Size(10,100)
$GBResults.Size = New-Object -TypeName System.Drawing.Size(1160,350)
$GBResults.Anchor = "Top, Bottom, Left, Right"
$GBResults.Text = "Source information"
$GBLog = New-Object -TypeName System.Windows.Forms.GroupBox
$GBLog.Location = New-Object -TypeName System.Drawing.Size(10,455)
$GBLog.Size = New-Object -TypeName System.Drawing.Size(1160,175)
$GBLog.Anchor = "Bottom, Left, Right"
$GBLog.Text = "Logging"
# ComboBoxes
$ComboBoxTypes = New-Object System.Windows.Forms.ComboBox
$ComboBoxTypes.Location = New-Object System.Drawing.Size(150,30)
$ComboBoxTypes.Size = New-Object System.Drawing.Size(160,30)
$ComboBoxTypes.Items.AddRange(@("General Information","Accounting","Connection Statistics","Connection Statistics Summary","Health","RemoteAccessRadius","User Activity"))
$ComboBoxTypes.SelectedItem = "General Information"
$ComboBoxTypes.TabIndex = "1"
$ComboBoxTypes.Anchor = "Top, Left"
$ComboBoxTypes.DropDownStyle = [System.Windows.Forms.ComboBoxStyle]::DropDownList
$ComboBoxTypes.Add_SelectedIndexChanged({
Activate-DateControls
})
#Checkboxes
$CheckBoxCurrentData = New-Object System.Windows.Forms.CheckBox
$CheckBoxCurrentData.Location = New-Object System.Drawing.Size(150,55)
$CheckBoxCurrentData.Size = New-Object System.Drawing.Size(160,30)
$CheckBoxCurrentData.Anchor = "Top, Left"
$CheckBoxCurrentData.Text = "Show Current Data"
$CheckBoxCurrentData.Enabled = $false
$CheckBoxCurrentData.Checked = $true
$CheckBoxCurrentData.Add_CheckedChanged({
Activate-CheckBoxControls
})
# Date Time Boxes
$DateTimeStart= New-Object System.Windows.Forms.DateTimePicker
$DateTimeStart.Location = New-Object System.Drawing.Size(380,30)
$DateTimeStart.Size = New-Object System.Drawing.Size(150,20)
$DateTimeStart.Format = [System.Windows.Forms.DateTimePickerFormat]::Custom
$DateTimeStart.CustomFormat = "dd-MM-yyyy hh:mm:ss tt"
$DateTimeStart.Value = ([DateTime]::Today).AddDays(-1)
$DateTimeStart.MaxDate = Get-Date
$DateTimeStart.Anchor = "Top, Left"
$DateTimeStart.Enabled = $false
$DateTimeStart.TabIndex = "2"
$DateTimeEnd= New-Object System.Windows.Forms.DateTimePicker
$DateTimeEnd.Location = New-Object System.Drawing.Size(380,60)
$DateTimeEnd.Size = New-Object System.Drawing.Size(150,20)
$DateTimeEnd.Format = [System.Windows.Forms.DateTimePickerFormat]::Custom
$DateTimeEnd.CustomFormat = "dd-MM-yyyy hh:mm:ss tt"
$DateTimeEnd.Value = [DateTime]::Today
$DateTimeEnd.MaxDate = Get-Date
$DateTimeEnd.Anchor = "Top, Left"
$DateTimeEnd.Enabled = $false
$DateTimeEnd.TabIndex = "3"
# Lables
$LabelDateStart = New-Object System.Windows.Forms.Label
$LabelDateStart.Location = New-Object System.Drawing.Size(320,33)
$LabelDateStart.Size = New-Object System.Drawing.Size(60,20)
$LabelDateStart.Anchor = "Top, Left"
$LabelDateStart.Text = "Start Date"
$LabelDateEnd = New-Object System.Windows.Forms.Label
$LabelDateEnd.Location = New-Object System.Drawing.Size(320,63)
$LabelDateEnd.Size = New-Object System.Drawing.Size(60,20)
$LabelDateEnd.Anchor = "Top, Left"
$LabelDateEnd.Text = "End Date"
$LabelUserName = New-Object System.Windows.Forms.Label
$LabelUserName.Location = New-Object System.Drawing.Size(550,33)
$LabelUserName.Size = New-Object System.Drawing.Size(100,20)
$LabelUserName.Anchor = "Top, Left"
$LabelUserName.Text = "Enter Username"
# Radio Buttons
$RadioButtonSelectRRASServer = New-Object System.Windows.Forms.RadioButton
$RadioButtonSelectRRASServer.Location = New-Object System.Drawing.Size(20,30)
$RadioButtonSelectRRASServer.Size = New-Object System.Drawing.Size(70,15)
$RadioButtonSelectRRASServer.TabIndex = "0"
$RadioButtonSelectRRASServer.Anchor = "Top, Left"
$RadioButtonSelectRRASServer.Text = "All RRAS Servers"
$RadioButtonSelectRRASServer.Checked = $true
# RichTextBox
$OutputBox = New-Object System.Windows.Forms.RichTextBox
$OutputBox.Location = New-Object System.Drawing.Size(20,475)
$OutputBox.Size = New-Object System.Drawing.Size(1138,145)
$OutputBox.Anchor = "Bottom, Left, Right"
$OutputBox.TabIndex = "9"
$OutputBox.Font = "Courier New"
$OutputBox.BackColor = "white"
$OutputBox.ReadOnly = $true
$OutputBox.MultiLine = $true
$TextBoxUserName = New-Object System.Windows.Forms.RichTextBox
$TextBoxUserName.Location = New-Object System.Drawing.Size(550,50)
$TextBoxUserName.Size = New-Object System.Drawing.Size(200,20)
$TextBoxUserName.Anchor = "Top, Left"
$TextBoxUserName.TabIndex = "4"
$TextBoxUserName.Font = "Courier New"
$TextBoxUserName.BackColor = "white"
$TextBoxUserName.ReadOnly = $false
$TextBoxUserName.MultiLine = $false
$TextBoxUserName.Enabled = $false
$TextBoxUserName.Text = "Enter UserName or DeviceName"
$TextBoxUserName.add_GotFocus({
ModifyTextbox
})
$TextBoxUserName.add_LostFocus({
ModifyTextbox
})
# StatusBar
$StatusBarPanelActivity = New-Object Windows.Forms.StatusBarPanel
$StatusBarPanelActivity.Text = "Ready"
$StatusBarPanelActivity.Width = "100"
$StatusBarPanelProcessing = New-Object Windows.Forms.StatusBarPanel
$StatusBarPanelProcessing.Text = ""
$StatusBarPanelProcessing.Width = "770"
$StatusBarPanelAuthor = New-Object Windows.Forms.StatusBarPanel
$StatusBarPanelAuthor.Text = "Author: Harmik Singh Batth"
$StatusBarPanelAuthor.Width = "150"
$StatusBarPanelAuthorWesbite = New-Object Windows.Forms.StatusBarPanel
$StatusBarPanelAuthorWesbite.Text = "Website: www.harmikbatth.com"
$StatusBarPanelAuthorWesbite.AutoSize = "Spring"
#$StatusBarPanelProcessing.Style = [System.Drawing.Color]::Red - need to fix color
$StatusBar = New-Object Windows.Forms.StatusBar
$StatusBar.Size = New-Object System.Drawing.Size(500,20)
$StatusBar.ShowPanels = $true
$StatusBar.SizingGrip = $false
$StatusBar.AutoSize = "Full"
$StatusBar.Panels.AddRange(@(
$StatusBarPanelActivity,
$StatusBarPanelProcessing,
$StatusBarPanelAuthor,
$StatusBarPanelAuthorWesbite
))
#Tooltip Progress bar
$TooltipProgressBar = New-Object Windows.Forms.ToolStripProgressBar
# DataGridViews
$DGVResults = New-Object System.Windows.Forms.DataGridView
$DGVResults.Location = New-Object System.Drawing.Size(20,120)
$DGVResults.Size = New-Object System.Drawing.Size(1138,320)
$DGVResults.Anchor = "Top, Bottom, Left, Right"
$DGVResults.TabIndex = "8"
$DGVResults.ColumnHeadersVisible = $true
$DGVResults.Columns.Insert(0,(New-Object -TypeName System.Windows.Forms.DataGridViewTextBoxColumn))
$DGVResults.Columns[0].Name = "RRAS Server"
$DGVResults.Columns[0].AutoSizeMode = "Fill"
$DGVResults.Columns[0].ReadOnly = $true
$DGVResults.Columns.Insert(1,(New-Object -TypeName System.Windows.Forms.DataGridViewTextBoxColumn))
$DGVResults.Columns[1].Name = "VpnStatus"
$DGVResults.Columns[1].Width = "200"
$DGVResults.Columns[1].ReadOnly = $true
$DGVResults.Columns.Insert(2,(New-Object -TypeName System.Windows.Forms.DataGridViewTextBoxColumn))
$DGVResults.Columns[2].Name = "RoutingStatus"
$DGVResults.Columns[2].AutoSizeMode = "Fill"
$DGVResults.Columns[2].ReadOnly = $true
$DGVResults.Columns.Insert(3,(New-Object -TypeName System.Windows.Forms.DataGridViewTextBoxColumn))
$DGVResults.Columns[3].Name = "Internet Interface"
$DGVResults.Columns[3].AutoSizeMode = "Fill"
$DGVResults.Columns[3].ReadOnly = $true
$DGVResults.Columns.Insert(4,(New-Object -TypeName System.Windows.Forms.DataGridViewTextBoxColumn))
$DGVResults.Columns[4].Name = "Internal Interface"
$DGVResults.Columns[4].AutoSizeMode = "Fill"
$DGVResults.Columns[4].ReadOnly = $true
$DGVResults.Columns.Insert(5,(New-Object -TypeName System.Windows.Forms.DataGridViewTextBoxColumn))
$DGVResults.Columns[5].Name = "IPAssignmentMethod"
$DGVResults.Columns[5].AutoSizeMode = "Fill"
$DGVResults.Columns[5].ReadOnly = $true
$DGVResults.Columns.Insert(6,(New-Object -TypeName System.Windows.Forms.DataGridViewTextBoxColumn))
$DGVResults.Columns[6].Name = "IPAddressRangeList"
$DGVResults.Columns[6].AutoSizeMode = "Fill"
$DGVResults.Columns[6].ReadOnly = $true
$DGVResults.Columns.Insert(7,(New-Object -TypeName System.Windows.Forms.DataGridViewTextBoxColumn))
$DGVResults.Columns[7].Name = "AuthenticationType"
$DGVResults.Columns[7].AutoSizeMode = "Fill"
$DGVResults.Columns[7].ReadOnly = $true
$DGVResults.Columns.Insert(8,(New-Object -TypeName System.Windows.Forms.DataGridViewTextBoxColumn))
$DGVResults.Columns[8].Name = "RadiusServerList"
$DGVResults.Columns[8].AutoSizeMode = "Fill"
$DGVResults.Columns[8].ReadOnly = $true
$DGVResults.AllowUserToAddRows = $false
$DGVResults.AllowUserToDeleteRows = $false
$DGVResults.ReadOnly = $false
$DGVResults.MultiSelect = $true
$DGVResults.ColumnHeadersHeightSizeMode = "DisableResizing"
$DGVResults.RowHeadersWidthSizeMode = "DisableResizing"
$DGVResults.RowHeadersVisible = $false
$DGVResults.SelectionMode = "FullRowSelect"
#endregion Execution Form page
#region Configuration Form page
#------------------Configuration Form--------------------------#
# GroupBoxes
$GBConfigActions = New-Object -TypeName System.Windows.Forms.GroupBox
$GBConfigActions.Location = New-Object -TypeName System.Drawing.Size(400,10)
$GBConfigActions.Size = New-Object -TypeName System.Drawing.Size(270,120)
$GBConfigActions.Anchor = "Top, Left"
$GBConfigActions.Text = "Actions"
$GBConfigResults = New-Object -TypeName System.Windows.Forms.GroupBox
$GBConfigResults.Location = New-Object -TypeName System.Drawing.Size(10,170)
$GBConfigResults.Size = New-Object -TypeName System.Drawing.Size(860,280)
$GBConfigResults.Anchor = "Top, Bottom, Left, Right"
$GBConfigResults.Text = "Configure RRAS Server Details"
$GBConfigLog = New-Object -TypeName System.Windows.Forms.GroupBox
$GBConfigLog.Location = New-Object -TypeName System.Drawing.Size(10,455)
$GBConfigLog.Size = New-Object -TypeName System.Drawing.Size(860,175)
$GBConfigLog.Anchor = "Bottom, Left, Right"
$GBConfigLog.Text = "Logging"
$GBConfigRRAS = New-Object -TypeName System.Windows.Forms.GroupBox
$GBConfigRRAS.Location = New-Object -TypeName System.Drawing.Size(10,10)
$GBConfigRRAS.Size = New-Object -TypeName System.Drawing.Size(380,120)
$GBConfigRRAS.Anchor = "Top, Left"
$GBConfigRRAS.Text = "Provide RRAS Server Details"
# DataGridViews
$DGVConfigResults = New-Object System.Windows.Forms.DataGridView
$DGVConfigResults.Location = New-Object System.Drawing.Size(20,190)
$DGVConfigResults.Size = New-Object System.Drawing.Size(838,250)
$DGVConfigResults.Anchor = "Top, Bottom, Left, Right"
$DGVConfigResults.ColumnHeadersVisible = $true
$DGVConfigResults.Columns.Insert(0,(New-Object -TypeName System.Windows.Forms.DataGridViewTextBoxColumn))
$DGVConfigResults.Columns[0].Name = "RRAS Server Name"
$DGVConfigResults.Columns[0].Width = "200"
$DGVConfigResults.Columns[0].ReadOnly = $false
$DGVConfigResults.Columns.Insert(1,(New-Object -TypeName System.Windows.Forms.DataGridViewTextBoxColumn))
$DGVConfigResults.Columns[1].Name = "Username"
$DGVConfigResults.Columns[1].AutoSizeMode = "Fill"
$DGVConfigResults.Columns[1].ReadOnly = $false
$DGVConfigResults.Columns.Insert(2,(New-Object -TypeName System.Windows.Forms.DataGridViewTextBoxColumn))
$DGVConfigResults.Columns[2].Name = "Password"
$DGVConfigResults.Columns[2].AutoSizeMode = "Fill"
$DGVConfigResults.Columns[2].ReadOnly = $false
$DGVConfigResults.AllowUserToAddRows = $true
$DGVConfigResults.AllowUserToDeleteRows = $true
$DGVConfigResults.ReadOnly = $true
$DGVConfigResults.MultiSelect = $true
$DGVConfigResults.ColumnHeadersHeightSizeMode = "DisableResizing"
$DGVConfigResults.RowHeadersWidthSizeMode = "DisableResizing"
$DGVConfigResults.RowHeadersVisible = $true
$DGVConfigResults.SelectionMode = "FullRowSelect"
#$DGVConfigResults.TabIndex = 0
# Buttons
$ButtonConfigExecute = New-Object System.Windows.Forms.Button
$ButtonConfigExecute.Location = New-Object System.Drawing.Size(540,30)
$ButtonConfigExecute.Size = New-Object System.Drawing.Size(120,30)
$ButtonConfigExecute.Text = "Save Configuration"
$ButtonConfigExecute.TabIndex = "1"
$ButtonConfigExecute.Anchor = "Top, Left"
$ButtonConfigExecute.Enabled = $true
$ButtonConfigExecute.Add_Click({
if ($DGVConfigResults.RowCount -ge 1)
{
SaveConfiguration $DGVConfigResults
}
})
$ButtonConfigRRASAdd = New-Object System.Windows.Forms.Button
$ButtonConfigRRASAdd.Location = New-Object System.Drawing.Size(410,30)
$ButtonConfigRRASAdd.Size = New-Object System.Drawing.Size(120,30)
$ButtonConfigRRASAdd.Text = "Add Server"
$ButtonConfigRRASAdd.TabIndex = "1"
$ButtonConfigRRASAdd.Anchor = "Top, Left"
$ButtonConfigRRASAdd.Enabled = $true
$ButtonConfigRRASAdd.Add_Click({
$preReqs = ""
if (($TextBoxRRASServer.Text -eq $null) -or ($TextBoxRRASServer.Text -eq ""))
{
Write-OutputConfigBox -OutputBoxMessage "Server name cannot be empty" -Type WARNING
Update-StatusBar -Activity Validating -Text "Server name cannot be empty"
$preReqs = "Not Met"
}
if (($TextBoxRRASUsername.Text -eq $null) -or ($TextBoxRRASUsername.Text -eq ""))
{
Write-OutputConfigBox -OutputBoxMessage "UserName cannot be empty" -Type WARNING
Update-StatusBar -Activity Validating -Text "UserName cannot be empty"
$preReqs = "Not Met"
}
if (($TextBoxRRASPassword.Text -eq $null) -or ($TextBoxRRASPassword.Text -eq ""))
{
Write-OutputConfigBox -OutputBoxMessage "Password cannot be empty" -Type WARNING
Update-StatusBar -Activity Validating -Text "Password cannot be empty"
$preReqs = "Not Met"
}
if ($preReqs -ne "Not Met")
{
Write-OutputConfigBox -OutputBoxMessage "Adding RRAS Server Details to Grid view" -Type INFO
Update-StatusBar -Activity Ready -Text " "
AddRRASServertoGridView
}
})
$ButtonConfigRRASRemove = New-Object System.Windows.Forms.Button
$ButtonConfigRRASRemove.Location = New-Object System.Drawing.Size(410,70)
$ButtonConfigRRASRemove.Size = New-Object System.Drawing.Size(120,30)
$ButtonConfigRRASRemove.Text = "Remove Server"
$ButtonConfigRRASRemove.TabIndex = "1"
$ButtonConfigRRASRemove.Anchor = "Top, Left"
$ButtonConfigRRASRemove.Enabled = $true
$ButtonConfigRRASRemove.Add_Click({
RemoveRRASServertoGridView
})
$ButtonConfigBackToMainForm = New-Object System.Windows.Forms.Button
$ButtonConfigBackToMainForm.Location = New-Object System.Drawing.Size(540,70)
$ButtonConfigBackToMainForm.Size = New-Object System.Drawing.Size(120,30)
$ButtonConfigBackToMainForm.Text = "Back To Main Form"
$ButtonConfigBackToMainForm.TabIndex = "1"
$ButtonConfigBackToMainForm.Anchor = "Top, Left"
$ButtonConfigBackToMainForm.Enabled = $true
$ButtonConfigBackToMainForm.Add_Click({
CheckConfigurationFile
LoadExecutionForm
})
# Lables
$LabelRRASServer = New-Object System.Windows.Forms.Label
#$LabelRRASServer.Font = New-Object System.Drawing.Font("Arial", "10",[System.Drawing.FontStyle]::Regular)
$LabelRRASServer.Location = New-Object System.Drawing.Size(15,35)
$LabelRRASServer.Size = New-Object System.Drawing.Size(160,30)
$LabelRRASServer.Anchor = "Top, Left"
$LabelRRASServer.Text = "Enter RRAS Server Name"
$LabelRRASUsername = New-Object System.Windows.Forms.Label
#$LabelRRASUsername.Font = New-Object System.Drawing.Font("Arial", "10",[System.Drawing.FontStyle]::Regular)
$LabelRRASUsername.Location = New-Object System.Drawing.Size(15,65)
$LabelRRASUsername.Size = New-Object System.Drawing.Size(160,30)
$LabelRRASUsername.Anchor = "Top, Left"
$LabelRRASUsername.Text = "Enter RRAS Server UserName"
$LabelRRASPassword = New-Object System.Windows.Forms.Label
#$LabelRRASPassword.Font = New-Object System.Drawing.Font("Arial", "10",[System.Drawing.FontStyle]::Regular)
$LabelRRASPassword.Location = New-Object System.Drawing.Size(15,95)
$LabelRRASPassword.Size = New-Object System.Drawing.Size(160,30)
$LabelRRASPassword.Anchor = "Top, Left"
$LabelRRASPassword.Text = "Enter RRAS Server Password"
# RichTextBox
$OutputConfigBox = New-Object System.Windows.Forms.RichTextBox
$OutputConfigBox.Location = New-Object System.Drawing.Size(20,475)
$OutputConfigBox.Size = New-Object System.Drawing.Size(838,145)
$OutputConfigBox.Anchor = "Bottom, Left, Right"
$OutputConfigBox.Font = "Courier New"
$OutputConfigBox.BackColor = "white"
$OutputConfigBox.ReadOnly = $true
$OutputConfigBox.MultiLine = $true
$TextBoxRRASServer = New-Object System.Windows.Forms.RichTextBox
$TextBoxRRASServer.Location = New-Object System.Drawing.Size(180,30)
$TextBoxRRASServer.Size = New-Object System.Drawing.Size(200,25)
$TextBoxRRASServer.Anchor = "Top, Left"
$TextBoxRRASServer.Font = "Courier New"
$TextBoxRRASServer.BackColor = "white"
$TextBoxRRASServer.ReadOnly = $false
$TextBoxRRASServer.MultiLine = $false
$TextBoxRRASUsername = New-Object System.Windows.Forms.RichTextBox
$TextBoxRRASUsername.Location = New-Object System.Drawing.Size(180,60)
$TextBoxRRASUsername.Size = New-Object System.Drawing.Size(200,25)
$TextBoxRRASUsername.Anchor = "Top, Left"
$TextBoxRRASUsername.Font = "Courier New"
$TextBoxRRASUsername.BackColor = "white"
$TextBoxRRASUsername.ReadOnly = $false
$TextBoxRRASUsername.MultiLine = $false
$TextBoxRRASPassword = New-Object System.Windows.Forms.TextBox
$TextBoxRRASPassword.Location = New-Object System.Drawing.Size(180,90)
$TextBoxRRASPassword.Size = New-Object System.Drawing.Size(200,30)
$TextBoxRRASPassword.Anchor = "Top, Left"
$TextBoxRRASPassword.Font = "Courier New"
$TextBoxRRASPassword.BackColor = "white"
$TextBoxRRASPassword.ReadOnly = $false
$TextBoxRRASPassword.MultiLine = $false
$TextBoxRRASPassword.PasswordChar = '*'
#endregion Configuration Form page
#endregion Windows Form Settings
#region Script Execution
#-----------------------------Execution starts here----------------------#
if (Test-Path -Path $ConfigurationFolder)
{
Write-OutputBox "Configuration Folder already exists, no action required" -Type INFO
}
Else
{
Write-OutputBox "Configuration Folder does not exist, creating Folder" -Type INFO
Try
{
mkdir $ConfigurationFolder
}
Catch
{
Write-OutputBox "Issues while creating Configuration Folder: $_.Exception.Message" -Type INFO
}
}
#CheckConfigurationFile
CheckConfigurationFile
#Load Form
Load-Form
}
#endregion Script Execution
No Comments