Skip to content

Commit

Permalink
Merge pull request #10 from jayrodksmith/dev-edge
Browse files Browse the repository at this point in the history
1.0.5 Release
  • Loading branch information
jayrodksmith authored Mar 14, 2024
2 parents 1f01b2a + 1f9f88a commit 665d30e
Show file tree
Hide file tree
Showing 15 changed files with 1,153 additions and 532 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,24 @@

## [Unreleased]

# [1.0.5] - 14-03-2024

### Added

- Failover support from Chrome to Edge
- Failover support from Edge to Chrome
- Logged in user detection from Edge support

### Changed

### Deprecated

### Removed

### Fixed

- Cleanup of some formatting

# [1.0.4] - 13-03-2024

### Added
Expand Down
2 changes: 1 addition & 1 deletion EasyWarrantyCheck.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = 'EasyWarrantyCheck.psm1'

# Version number of this module.
ModuleVersion = '1.0.4'
ModuleVersion = '1.0.5'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down
1,136 changes: 808 additions & 328 deletions EasyWarrantyCheck_RMM.ps1

Large diffs are not rendered by default.

101 changes: 101 additions & 0 deletions Private/Helpers/Test-BrowserSupport.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
function Test-BrowserSupport {
<#
.SYNOPSIS
Function to check browser support
.DESCRIPTION
This function will check what browser we can use in the main script
.EXAMPLE
Test-BrowserSupport -Browser "Chrome"
Test-BrowserSupport -Browser "Edge"
.PARAMETER Browser
What browser to check if we can run
#>
[CmdletBinding(SupportsShouldProcess)]
param(
[Parameter(Mandatory = $false)]
[String]$Browser = "Chrome"
)
# Check if running in system context
function Test-SystemContext {
$currentUser = [Security.Principal.WindowsIdentity]::GetCurrent()
$currentUserSid = $currentUser.User.Value

# The SID for the SYSTEM account
$systemSid = "S-1-5-18"

if ($currentUserSid -eq $systemSid) {
Write-Verbose "Running in SYSTEM context."
return $true
} else {
Write-Verbose "Not running in SYSTEM context."
return $false
}
}

# Check if Edge and Chrome Installed
$chrome = Test-SoftwareInstalled -SoftwareName "Google Chrome"
$edge = Test-SoftwareInstalled -SoftwareName "Microsoft Edge"
$loggedInUsers = Get-LoggedInUser
$systemcontext = Test-SystemContext

# Check if Edge can be used
if($edge.installed -eq $true) {
if (($loggedInUsers = Get-LoggedInUser) -eq $false) {
Write-Verbose "No user logged in cannot run Edge without user logged in"
$edgesupport = $false
} else{
if($systemcontext -eq $true) {
$edgesupport = $true
} else {
Write-Verbose "Script not running system context cannot run Edge without system context"
$edgesupport = $false
}

}
} else {
$edgesupport = $false
}

if ($Browser -eq "Edge") {
if($edgesupport -eq $true){
Set-Variable DriverMode -Value "Edge" -Scope Global -option ReadOnly -Force
return $true
} else {
if($systemcontext -eq $false) {Write-Host "Script not running system context cannot run Edge without system context"}
if($edge.installed -eq $false) {Write-Host "Microsoft Edge not installed"}
Write-Host "Microsoft Edge not supported, trying Chrome support"
if($chrome.installed -eq $true) {
Write-Host "Defaulting to Chrome support"
Set-Variable DriverMode -Value "Chrome" -Scope Global -option ReadOnly -Force
return $true
} else {
Write-Host "Google Chrome not installed"
return $false
}
}
}

if ($Browser -eq "Chrome"){
if($chrome.installed -eq $true) {
Set-Variable DriverMode -Value "Chrome" -Scope Global -option ReadOnly -Force
return $true
} else {
Write-Host "Google Chrome not installed trying Edge support"
if($edgesupport -eq $true){
Set-Variable DriverMode -Value "Edge" -Scope Global -option ReadOnly -Force
return $true
} else {
if (($loggedInUsers = Get-LoggedInUser) -eq $false) {
Write-Host "No user logged in cannot run Edge without user logged in"
return $false
} else {
Write-Host "Microsoft Edge not installed"
}
}
}
}
}
17 changes: 6 additions & 11 deletions Private/Helpers/Test-SoftwareInstalled.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,19 @@ foreach ($path in $registryPaths) {
$version = $installed.DisplayVersion
Write-Verbose "$SoftwareName version $version is installed."
$result = [PSCustomObject]@{
Software = $SoftwareName
Installed = $true
Version = $version
Software = $SoftwareName
Installed = $true
Version = $version
}
return $result
}
}
# If the software was not found in any location
Write-Host "###########################"
Write-Host "WARNING"
Write-Host "$SoftwareName not detected"
Write-Host "This manufacturer currently requires $SoftwareName installed to check expiry"
Write-Host "###########################"
Write-Verbose "$SoftwareName is not installed."
$result = [PSCustomObject]@{
Software = $SoftwareName
Installed = $false
Version = $null
Software = $SoftwareName
Installed = $false
Version = $null
}
return $result
}
6 changes: 3 additions & 3 deletions Private/RMM/Get-DevicesNinjaRMM.ps1
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
function Get-DevicesNinjaRMM {
[CmdletBinding()]
Param(
[string]$NinjaURL = "https://oc.ninjarmm.com", # Adjust URL
[String]$Secretkey = "test", # Add key here
[String]$AccessKey = "test", # Add key here
[string]$NinjaURL = "https://oc.ninjarmm.com", # Adjust to correct url
[String]$Secretkey = "test", # Add keys here
[String]$AccessKey = "test", # Add keys here
[boolean]$SyncWithSource,
[boolean]$OverwriteWarranty,
[string]$NinjaFieldName
Expand Down
5 changes: 3 additions & 2 deletions Public/Get-Warranty.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ function Get-Warranty {
Set-Variable ForceUpdate -Value $ForceUpdate -Scope Global -option ReadOnly -Force
}
if ($Seleniumdrivermode) {
Set-Variable Seleniumdrivermode -Value $Seleniumdrivermode -Scope Global -option ReadOnly -Force
$browsersupport = Test-BrowserSupport -Browser $Seleniumdrivermode
if ($browsersupport -eq $false) {Set-Variable Browsersupport -Value $false -Scope Global -option ReadOnly -Force}
}
if ($PSCmdlet.ParameterSetName -eq 'Default') {
$machineinfo = Get-MachineInfo
Expand All @@ -113,7 +114,7 @@ function Get-Warranty {
$mfg = $Manufacturer
$global:ServerMode = $true
}

$Notsupported = $false
switch -Wildcard ($mfg) {
"TERRA" {
Expand Down
78 changes: 34 additions & 44 deletions Public/Get-WarrantyAsus.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,47 +23,37 @@ function Get-WarrantyAsus {
[Parameter(Mandatory = $false)]
[String]$DateFormat = 'dd-MM-yyyy'
)
Get-WebDriver -WebDriver $Seleniumdrivermode
Get-SeleniumModule
if ($Seleniumdrivermode -eq "Chrome" ){
$browserinstalled = Test-SoftwareInstalled -SoftwareName "Google Chrome"
}
if ($Seleniumdrivermode -eq "Edge" ){
$browserinstalled = Test-SoftwareInstalled -SoftwareName "Microsoft Edge"
}
if ($browserinstalled.Installed -eq $false){
Write-Host "###########################"
Write-Host "WARNING"
Write-Host "$($browserinstalled.software) not detected"
Write-Host "This manufacturer currently requires $($browserinstalled.software) installed to check expiry"
Write-Host "###########################"

if ($browsersupport -eq $false){
$WarObj = [PSCustomObject]@{
'Serial' = $Serial
'Serial' = $Serial
'Warranty Product name' = $null
'StartDate' = $null
'EndDate' = $null
'Warranty Status' = 'Could not get warranty information'
'Client' = $null
'Product Image' = $null
'Warranty URL' = $null
'StartDate' = $null
'EndDate' = $null
'Warranty Status' = 'Could not get warranty information'
'Client' = $null
'Product Image' = $null
'Warranty URL' = $null
}
Remove-Module Selenium -Verbose:$false
return $warObj
}
# Start a new browser session with headless mode
try{
$driver = Start-SeleniumModule -WebDriver $Seleniumdrivermode -Headless $true
Get-WebDriver -WebDriver $DriverMode
Get-SeleniumModule
$driver = Start-SeleniumModule -WebDriver $DriverMode -Headless $true
}catch{
Write-Verbose $_.Exception.Message
$WarObj = [PSCustomObject]@{
'Serial' = $Serial
'Serial' = $Serial
'Warranty Product name' = $null
'StartDate' = $null
'EndDate' = $null
'Warranty Status' = 'Could not get warranty information'
'Client' = $null
'Product Image' = $null
'Warranty URL' = $null
'StartDate' = $null
'EndDate' = $null
'Warranty Status' = 'Could not get warranty information'
'Client' = $null
'Product Image' = $null
'Warranty URL' = $null
}
Remove-Module Selenium -Verbose:$false
return $warObj
Expand Down Expand Up @@ -117,32 +107,32 @@ function Get-WarrantyAsus {
}

# Close the browser
Stop-SeleniumModule -WebDriver $Seleniumdrivermode
Stop-SeleniumModule -WebDriver $DriverMode
$datestring = $($table.'Warranty Expiry')
$warEndDate = [DateTime]::ParseExact($dateString, "yyyy/MM/dd", [System.Globalization.CultureInfo]::InvariantCulture)
$warEndDate = $warEndDate.ToString($dateformat)

if ($($table.'Warranty Status')) {
$WarObj = [PSCustomObject]@{
'Serial' = $serialnumber
'Serial' = $serialnumber
'Warranty Product name' = $($table.'Model Name')
'StartDate' = $null
'EndDate' = $warEndDate
'Warranty Status' = $warrantystatus
'Client' = $null
'Product Image' = $null
'Warranty URL' = $null
'StartDate' = $null
'EndDate' = $warEndDate
'Warranty Status' = $warrantystatus
'Client' = $null
'Product Image' = $null
'Warranty URL' = $null
}
} else {
$WarObj = [PSCustomObject]@{
'Serial' = $Serial
'Serial' = $Serial
'Warranty Product name' = $null
'StartDate' = $null
'EndDate' = $null
'Warranty Status' = 'Could not get warranty information'
'Client' = $null
'Product Image' = $null
'Warranty URL' = $null
'StartDate' = $null
'EndDate' = $null
'Warranty Status' = 'Could not get warranty information'
'Client' = $null
'Product Image' = $null
'Warranty URL' = $null
}
}
return $WarObj
Expand Down
Loading

0 comments on commit 665d30e

Please sign in to comment.